Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:unicef/un-partner-portal into fe…
Browse files Browse the repository at this point in the history
…ature/#950-ie-issues
  • Loading branch information
marcindo committed Jan 29, 2018
2 parents 51f08d2 + e4778b9 commit e5301f8
Show file tree
Hide file tree
Showing 26 changed files with 308 additions and 260 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ POSTGRES_SSL_MODE=off
EMAIL_HOST_USER=TBD
EMAIL_HOST_PASSWORD=TBD
GOOGLE_KEY=GOOGLE_KEY_HERE
DJANGO_ALLOWED_HOST=127.0.0.1 # Optional, defaults to localhost
UNPP_FRONTEND_HOST=127.0.0.1:8080 # Optional, defaults to DJANGO_ALLOWED_HOST
12 changes: 12 additions & 0 deletions backend/unpp_api/apps/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from logging.handlers import RotatingFileHandler

from django.conf import settings
from imagekit import ImageSpec
from imagekit.processors import ResizeToFill

Expand Down Expand Up @@ -80,3 +81,14 @@ def confirm(prompt='Confirm', default=False):
return True
if ans.lower() == 'n':
return False


def get_absolute_frontend_url(relative_url):
if not relative_url.startswith('/'):
relative_url = '/' + relative_url

host = settings.FRONTEND_HOST
if host.endswith('/'):
host = host[:-1]

return 'http://' + host + relative_url
39 changes: 21 additions & 18 deletions backend/unpp_api/apps/notification/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from dateutil.relativedelta import relativedelta
from django.db import transaction
from django.core.mail import send_mail
from django.core.mail import EmailMessage
from django.conf import settings
from django.template import loader
from django.contrib.contenttypes.models import ContentType
Expand Down Expand Up @@ -33,7 +33,7 @@ def feed_alert(notification_type, subject, body, users, obj):


def send_notification(
notification_type, obj, users, context=None, send_in_feed=True, check_sent_for_source=True
notification_type, obj, users, context=None, send_in_feed=True, check_sent_for_source=True, use_bcc=False
):
"""
notification_type - check NotificationType class in const.py
Expand All @@ -52,7 +52,16 @@ def send_notification(

targets = [u.email for u in users]
body = render_notification_template_to_str(notification_info.get('template_name'), context)
send_mail(notification_info.get('subject'), body, settings.DEFAULT_FROM_EMAIL, targets)

to, bcc = ([], targets) if use_bcc else (targets, [])

EmailMessage(
subject=notification_info.get('subject'),
body=body,
from_email=settings.DEFAULT_FROM_EMAIL,
to=to,
bcc=bcc
).send()

if send_in_feed:
return feed_alert(notification_type, notification_info.get('subject'), body, users, obj)
Expand All @@ -63,17 +72,11 @@ def render_notification_template_to_str(template_name, context):


def get_notify_partner_users_for_application(application):
users = User.objects.filter(partner_members__partner=application.partner)
return users.distinct()

return User.objects.filter(partner_members__partner=application.partner).distinct()

def get_partner_users_for_app_qs(application_qs):
notify_user_ids = []
for application in application_qs:
users_qs = get_notify_partner_users_for_application(application)
notify_user_ids.extend(list(users_qs.values_list('id', flat=True)))

return User.objects.filter(id__in=notify_user_ids)
def get_partner_users_for_application_queryset(application_qs):
return User.objects.filter(partner_members__partner__applications__in=application_qs).distinct()


# We don't want to send 2x of the same notification
Expand All @@ -97,16 +100,16 @@ def user_received_notification_recently(user, obj, notification_type, time_ago=r

def send_notification_cfei_completed(eoi):
if eoi.completed_reason == COMPLETED_REASON.canceled:
users = get_partner_users_for_app_qs(eoi.applications.all())
send_notification(NotificationType.CFEI_CANCELLED, eoi, users)
users = get_partner_users_for_application_queryset(eoi.applications.all())
send_notification(NotificationType.CFEI_CANCELLED, eoi, users, use_bcc=True)

if eoi.completed_reason == COMPLETED_REASON.partners:
users = get_partner_users_for_app_qs(eoi.applications.losers())
send_notification(NotificationType.CFEI_APPLICATION_LOSS, eoi, users)
users = get_partner_users_for_application_queryset(eoi.applications.losers())
send_notification(NotificationType.CFEI_APPLICATION_LOSS, eoi, users, use_bcc=True)

if eoi.completed_reason == COMPLETED_REASON.no_candidate:
users = get_partner_users_for_app_qs(eoi.applications.all())
send_notification(NotificationType.CFEI_APPLICATION_LOSS, eoi, users)
users = get_partner_users_for_application_queryset(eoi.applications.all())
send_notification(NotificationType.CFEI_APPLICATION_LOSS, eoi, users, use_bcc=True)


def send_agency_updated_application_notification(application):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ The review of applications has now concluded. Unfortunately, your organization

Please continue to visit the UN Partner Portal for other partnership opportunities.

Thank you.
Thank you.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-01-29 13:27
from __future__ import unicode_literals

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('partner', '0055_merge_20180123_1153'),
]

operations = [
migrations.AlterField(
model_name='partner',
name='country_presence',
field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(choices=[('AF', 'Afghanistan'), ('AL', 'Albania'), ('DZ', 'Algeria'), ('AR', 'Argentina'), ('AM', 'Armenia'), ('AZ', 'Azerbaijan'), ('AI', 'Anguilla'), ('AG', 'Antigua and Barbuda'), ('BB', 'Barbados'), ('VG', 'Virgin Islands (UK)'), ('DM', 'Dominica'), ('GD', 'Grenada'), ('MS', 'Montserrat'), ('KN', 'Saint Kitts and Nevis'), ('LC', 'Saint Lucia'), ('VC', 'Saint Vincent and the Grenadines'), ('TC', 'Turks & Caicos'), ('TT', 'Trinidad and Tobago'), ('BT', 'Bhutan'), ('BO', 'Bolivia'), ('BW', 'Botswana'), ('BA', 'Bosnia and Herzegovina'), ('BR', 'Brazil'), ('BG', 'Bulgaria'), ('MM', 'Myanmar'), ('BI', 'Burundi'), ('BY', 'Belarus'), ('KH', 'Cambodia'), ('CM', 'Cameroon'), ('CF', 'Central African Republic'), ('LK', 'Sri Lanka'), ('TD', 'Chad'), ('CL', 'Chile'), ('CN', 'China'), ('CO', 'Colombia'), ('CD', 'Congo, Dem. Rep.'), ('CR', 'Costa Rica'), ('HR', 'Croatia'), ('CU', 'Cuba'), ('BJ', 'Benin'), ('DK', 'Denmark'), ('DO', 'Dominican Republic'), ('EC', 'Ecuador'), ('SV', 'El Salvador'), ('GQ', 'Equatorial Guinea'), ('ET', 'Ethiopia'), ('ER', 'Eritrea'), ('AS', 'American Samoa'), ('CK', 'Cook Islands'), ('FJ', 'Fiji'), ('KI', 'Kiribati'), ('MH', 'Marshall Islands'), ('FM', 'Micronesia'), ('NR', 'Nauru'), ('NU', 'Niue'), ('PW', 'Palau, Republic Of'), ('WS', 'Samoa'), ('SB', 'Solomon Islands'), ('TK', 'Tokelau'), ('TO', 'Tonga'), ('TV', 'Tuvalu'), ('VU', 'Vanuatu'), ('GA', 'Gabon'), ('GM', 'Gambia'), ('GE', 'Georgia'), ('GH', 'Ghana'), ('GT', 'Guatemala'), ('GN', 'Guinea'), ('GY', 'Guyana'), ('SR', 'Suriname'), ('HT', 'Haiti'), ('HN', 'Honduras'), ('IN', 'India'), ('ID', 'Indonesia'), ('IR', 'Iran'), ('IQ', 'Iraq'), ('CI', "Cote D'Ivoire"), ('JM', 'Jamaica'), ('JO', 'Jordan'), ('KZ', 'Kazakhstan'), ('KE', 'Kenya'), ('KG', 'Kyrgyzstan'), ('LA', "Lao, People's Dem. Rep"), ('LB', 'Lebanon'), ('LS', 'Lesotho'), ('LR', 'Liberia'), ('LY', 'Libya'), ('MK', 'Macedonia, TFYR'), ('MG', 'Madagascar'), ('MW', 'Malawi'), ('MY', 'Malaysia'), ('MV', 'Maldives'), ('ML', 'Mali'), ('MR', 'Mauritania'), ('MX', 'Mexico'), ('MN', 'Mongolia'), ('MA', 'Morocco'), ('NP', 'Nepal'), ('NI', 'Nicaragua'), ('NE', 'Niger'), ('NG', 'Nigeria'), ('PK', 'Pakistan'), ('PA', 'Panama'), ('PY', 'Paraguay'), ('CG', 'Congo'), ('PE', 'Peru'), ('PH', 'Philippines'), ('RO', 'Romania'), ('RU', 'Russian Federation'), ('RW', 'Rwanda'), ('BH', 'Bahrain'), ('KW', 'Kuwait'), ('QA', 'Qatar'), ('SA', 'Saudi Arabia'), ('AE', 'United Arab Emirates'), ('SN', 'Senegal'), ('SL', 'Sierra Leone'), ('SO', 'Somalia'), ('ZA', 'South Africa'), ('SD', 'Sudan'), ('SZ', 'Swaziland'), ('SS', 'South Sudan'), ('SY', 'Syrian Arab Republic'), ('TJ', 'Tajikistan'), ('TH', 'Thailand'), ('TG', 'Togo'), ('TN', 'Tunisia'), ('TR', 'Turkey'), ('TM', 'Turkmenistan'), ('UG', 'Uganda'), ('UA', 'Ukraine'), ('EG', 'Egypt'), ('TZ', 'Tanzania, United Republic of'), ('BF', 'Burkina Faso'), ('UY', 'Uruguay'), ('UZ', 'Uzbekistan'), ('VE', 'Venezuela'), ('YE', 'Yemen'), ('ZM', 'Zambia'), ('BD', 'Bangladesh'), ('KP', "Korea, Democratic People's Republic of"), ('VN', 'Viet Nam'), ('MD', 'Moldova'), ('CH', 'Switzerland'), ('BZ', 'Belize'), ('ZW', 'Zimbabwe'), ('OM', 'Oman'), ('PG', 'Papua New Guinea'), ('KM', 'Comoros'), ('DJ', 'Djibouti'), ('AO', 'Angola'), ('CV', 'Cabo Verde'), ('ST', 'Sao Tome and Principe'), ('GW', 'Guinea-Bissau'), ('MZ', 'Mozambique'), ('NA', 'Namibia'), ('PS', 'Palestine'), ('TL', 'Timor-Leste'), ('ME', 'Montenegro'), ('RS', 'Serbia'), ('AW', 'Aruba'), ('AU', 'Australia'), ('AT', 'Austria'), ('BE', 'Belgium'), ('BM', 'Bermuda'), ('BS', 'Bahamas'), ('BN', 'Brunei'), ('CA', 'Canada'), ('KY', 'Cayman Islands'), ('CZ', 'Czech Republic'), ('CY', 'Cyprus'), ('EE', 'Estonia'), ('FI', 'Finland'), ('FR', 'France'), ('DE', 'Germany'), ('GI', 'Gibraltar'), ('GR', 'Greece'), ('GU', 'Guam'), ('HU', 'Hungary'), ('IS', 'Iceland'), ('IE', 'Ireland'), ('IL', 'Israel'), ('IT', 'Italy'), ('JP', 'Japan'), ('LV', 'Latvia'), ('LT', 'Lithuania'), ('LU', 'Luxembourg'), ('MU', 'Mauritius'), ('MT', 'Malta'), ('MC', 'Monaco'), ('NC', 'New Caledonia'), ('NL', 'Netherlands'), ('NO', 'Norway'), ('NZ', 'New Zealand'), ('PL', 'Poland'), ('PT', 'Portugal'), ('PR', 'Puerto Rico'), ('KR', 'Korea, Republic of'), ('SC', 'Seychelles'), ('SG', 'Singapore'), ('SK', 'Slovakia'), ('ES', 'Spain'), ('SI', 'Slovenia'), ('SE', 'Sweden'), ('GB', 'United Kingdom'), ('US', 'United States of America'), ('VI', 'Virgin Islands (USA)'), ('AD', 'Andorra'), ('GF', 'French Guiana'), ('PF', 'French Polynesia (France)'), ('GL', 'Greenland'), ('GP', 'Guadeloupe'), ('LI', 'Liechtenstein'), ('MQ', 'Martinique'), ('AN', 'Netherlands Antilles'), ('MP', 'Northern Mariana Islands'), ('RE', 'Reunion'), ('SH', 'Saint Helena'), ('SM', 'San Marino'), ('CS', 'Serbia & Montenegro'), ('VA', 'Vatican City'), ('WF', 'Wallis & Futuna Islands')], max_length=2), blank=True, default=list, null=True, size=None),
),
]
3 changes: 2 additions & 1 deletion backend/unpp_api/apps/partner/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Partner(TimeStampedModel):
country_presence = ArrayField(
models.CharField(max_length=2, choices=COUNTRIES_ALPHA2_CODE),
default=list,
null=True
null=True,
blank=True,
)
staff_globally = models.CharField(max_length=3, choices=STAFF_GLOBALLY_CHOICES, null=True, blank=True)
# country profile information
Expand Down
11 changes: 9 additions & 2 deletions backend/unpp_api/apps/project/admin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import (
from project.models import (
EOI,
Pin,
Application,
ApplicationFeedback,
Assessment,
)


class ApplicationAdmin(admin.ModelAdmin):
search_fields = ('partner__legal_name', 'eoi__title')
list_display = ('id', 'partner', 'eoi', 'agency', 'did_win', 'did_accept')
list_filter = ('is_unsolicited', 'agency', 'status', 'did_win', 'did_accept', 'did_decline', 'did_withdraw')


admin.site.register(EOI)
admin.site.register(Pin)
admin.site.register(Application)
admin.site.register(Application, ApplicationAdmin)
admin.site.register(ApplicationFeedback)
admin.site.register(Assessment)
Loading

0 comments on commit e5301f8

Please sign in to comment.