Skip to content
This repository has been archived by the owner on Sep 19, 2018. It is now read-only.

Commit

Permalink
Merge pull request #428 from michelesr/dev
Browse files Browse the repository at this point in the history
Add support to main contact and secondary ambassadors
  • Loading branch information
mitio committed Sep 29, 2015
2 parents 0877a7e + 196ab0e commit d8b2c18
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding field 'UserProfile.role'
db.add_column(u'api_userprofile', 'role',
self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True),
keep_default=False)

# Adding field 'UserProfile.is_main_contact'
db.add_column(u'api_userprofile', 'is_main_contact',
self.gf('django.db.models.fields.BooleanField')(default=False),
keep_default=False)


def backwards(self, orm):
# Deleting field 'UserProfile.role'
db.delete_column(u'api_userprofile', 'role')

# Deleting field 'UserProfile.is_main_contact'
db.delete_column(u'api_userprofile', 'is_main_contact')


models = {
'api.event': {
'Meta': {'ordering': "['start_date']", 'object_name': 'Event'},
'audience': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'event_audience'", 'symmetrical': 'False', 'to': "orm['api.EventAudience']"}),
'contact_person': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'country': ('django_countries.fields.CountryField', [], {'max_length': '2'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}),
'description': ('django.db.models.fields.TextField', [], {'max_length': '1000'}),
'end_date': ('django.db.models.fields.DateTimeField', [], {}),
'event_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
'geoposition': ('geoposition.fields.GeopositionField', [], {'default': "'0,0'", 'max_length': '42'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'location': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
'organizer': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255'}),
'picture': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'blank': 'True'}),
'pub_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2015, 9, 29, 0, 0)'}),
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'start_date': ('django.db.models.fields.DateTimeField', [], {}),
'status': ('django.db.models.fields.CharField', [], {'default': "'PENDING'", 'max_length': '50'}),
'theme': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'event_theme'", 'symmetrical': 'False', 'to': "orm['api.EventTheme']"}),
'title': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255'}),
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
},
'api.eventaudience': {
'Meta': {'object_name': 'EventAudience'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
},
'api.eventtheme': {
'Meta': {'ordering': "['order', 'name']", 'object_name': 'EventTheme'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'order': ('django.db.models.fields.IntegerField', [], {'default': '0'})
},
'api.socialaccountlist': {
'Meta': {'object_name': 'SocialAccountList'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"})
},
'api.userprofile': {
'Meta': {'object_name': 'UserProfile'},
'bio': ('django.db.models.fields.TextField', [], {'max_length': '1000', 'blank': 'True'}),
'country': ('django_countries.fields.CountryField', [], {'max_length': '2', 'blank': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_main_contact': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'role': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
'twitter': ('django.db.models.fields.CharField', [], {'max_length': '140', 'blank': 'True'}),
'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['auth.User']", 'unique': 'True'}),
'website': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'})
},
u'auth.group': {
'Meta': {'object_name': 'Group'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
u'auth.permission': {
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
u'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
u'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}

complete_apps = ['api']
2 changes: 2 additions & 0 deletions api/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class UserProfile(models.Model):
bio = models.TextField(max_length=1000, blank=True)
website = models.URLField(blank=True)
twitter = models.CharField(max_length=140, blank=True)
role = models.CharField(max_length=255, blank=True, default='')
is_main_contact = models.BooleanField(default=False)

def __unicode__(self):
return 'Username: %s, First Name:%s Last Name: %s, Country: %s, Bio: %s, Website: %s, Twitter: %s' % (
Expand Down
10 changes: 5 additions & 5 deletions web/processors/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ def get_ambassadors_for_countries():
# list countries minus two CUSTOM_COUNTRY_ENTRIES
for code, name in list(countries)[2:]:
readable_name = unicode(name)
# TODO: load main ambassadors
main_ambassadors = []
# TODO: exclude main ambassadors
found_ambassadors = [ambassador for ambassador in ambassadors if ambassador.country == code]
country_ambassadors = [ambassador for ambassador in ambassadors if ambassador.country == code]
# load main ambassadors
main_ambassadors = [ambassador for ambassador in country_ambassadors if ambassador.is_main_contact]
# exclude main ambassadors
found_ambassadors = [ambassador for ambassador in country_ambassadors if not ambassador.is_main_contact]
countries_ambassadors.append(
(code, readable_name, found_ambassadors, main_ambassadors))

countries_ambassadors.sort()
return countries_ambassadors


def get_ambassadors_for_country(country):
ambassadors = User.objects.filter(
groups__name='ambassadors',
Expand Down
36 changes: 18 additions & 18 deletions web/templates/pages/ambassadors.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@ <h1>EU Code Week Ambassadors</h1>
{% if user_country %}Your current country: <a href="http://events.codeweek.eu/ambassadors">{{ user_country.country_name }}</a>{% endif %}
</div>
<div class="tabs clearfix" id="tab-1" data-active="{{ country_pos }}">
<div id="showcountries">
<ul class="clearfix list-style-none">
{% for each_country in all_countries %}
<li><a href="#tabs-{{ each_country.1 }}">
<div class="country-link" data-name="{{ each_country.0 }}">

<img src="/static/flags/{{ each_country.1|lower }}.png" alt="{{ each_country.0 }}" />

<div class="country-name">
{{ each_country.0 }}
</div>
</div>
</a></li>
{% endfor %}

</ul>
</div>
<div class="tab-container">
{% for code,country,ambassadors, mains in countries %}
<div class="tab-content clearfix" id="tabs-{{ code }}">
Expand Down Expand Up @@ -132,12 +115,29 @@ <h3>Ambassadors</h3>

{% endfor %}
{% else %}
<p>No ambassador yet. Why don't you <a href="mailto:europecodes@gmail.com">volunteer</a>?</p>
<p style="text-align: center">No ambassador yet. Why don't you <a href="mailto:europecodes@gmail.com">volunteer</a>?</p>
{% endif %}
</div>

{% endfor %}
</div>
<div id="showcountries">
<ul class="clearfix list-style-none">
{% for each_country in all_countries %}
<li><a href="#tabs-{{ each_country.1 }}">
<div class="country-link" data-name="{{ each_country.0 }}">

<img src="/static/flags/{{ each_country.1|lower }}.png" alt="{{ each_country.0 }}" />

<div class="country-name">
{{ each_country.0 }}
</div>
</div>
</a></li>
{% endfor %}

</ul>
</div>
</div>


Expand Down
102 changes: 58 additions & 44 deletions web/tests/test_events_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,63 +534,77 @@ def test_list_countries():
for country in all_countries[2:]:
assert len(country[1]) == 2


@pytest.mark.django_db
def test_list_active_countries(admin_user, db):
"""
Verifies that only the countries with event which date is gte
2014 are returned from the list_active_countries() function
"""

# this should be returned because is APPROVED and after 2014
event_data = {
'location': u'Ljubljana, Slovenia',
'country': 'SI',
'organizer': u'testko',
"creator": admin_user,
'start_date': datetime.datetime.now(),
'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
'title': u'Test Approved Event',
'status': "APPROVED",
}

test_approved_event = create_or_update_event(event_id=None, **event_data)

# this shouldn't be returned because is PENDING
event_data = {
'location': u'Ljubljana, Slovenia',
'country': 'SI',
'organizer': u'testko',
"creator": admin_user,
'start_date': datetime.datetime.now(),
'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
'title': u'Test Pending Event',
'status': "PENDING",
}

test_pending_event = create_or_update_event(event_id=None, **event_data)

# this shouldn't be returned because is before 2014
event_data = {
'location': u'Rome, Italy',
'country': 'IT',
'organizer': u'testko',
"creator": admin_user,
'start_date': datetime.datetime(2013, 1, 1, 12, 00),
'end_date': datetime.datetime(2013, 1, 1, 12, 00) + datetime.timedelta(days=3, hours=3),
'title': u'Test Approved Event in other country',
'status': "APPROVED",
}
events = [
{
# this country should be returned
# because event is APPROVED and after 2014
'location': u'Ljubljana, Slovenia',
'country': 'SI',
'organizer': u'testko',
"creator": admin_user,
'start_date': datetime.datetime.now(),
'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
'title': u'Test Approved Event',
'status': "APPROVED",
},
{
# this country should be returned
# for the same reasons
'location': u'Paris, France',
'country': 'FR',
'organizer': u'testko',
"creator": admin_user,
'start_date': datetime.datetime.now(),
'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
'title': u'Test Pending Event',
'status': "APPROVED",
},
{
# the same country should be returned only once
'location': u'Ljubljana, Slovenia',
'country': 'SI',
'organizer': u'testko',
"creator": admin_user,
'start_date': datetime.datetime.now(),
'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
'title': u'Test Pending Event',
'status': "APPROVED",
},
{
# this country shouldn't be returned
# because event start_date is < 2014
'location': u'Rome, Italy',
'country': 'IT',
'organizer': u'testko',
"creator": admin_user,
'start_date': datetime.datetime(2013, 1, 1, 12, 00),
'end_date': datetime.datetime(2013, 1, 1, 12, 00) + datetime.timedelta(days=3, hours=3),
'title': u'Test Approved Event in other country',
'status': "APPROVED",
}
]

test_other_country_event = create_or_update_event(
event_id=None, **event_data)
# insert the listed events
for event_data in events:
create_or_update_event(event_id=None, **event_data)

# retrieve the active countries from db
active_countries = list_active_countries()

# there should be only a one active event
assert len(active_countries) == 1
# there should be only two active countries
assert len(active_countries) == 2

# and should be this
# and should be those two
assert ('Slovenia', 'SI') in active_countries
assert ('France', 'FR') in active_countries

# if listing works, results are tuples ('country_name', 'country_code')
# country_code should be a string with 2 characters
Expand Down

0 comments on commit d8b2c18

Please sign in to comment.