Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #825 from glogiotatidis/master
Browse files Browse the repository at this point in the history
[fix bug 1073402] Add X-COUNTRY-CODE to ical feed.
  • Loading branch information
johngian committed Sep 26, 2014
2 parents 68c7127 + 7823b66 commit f4c7322
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions remo/base/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
from funfactory import utils
from jingo import register
from jinja2 import Markup
from product_details import product_details


AES_PADDING = 16
AES_IV_LENGTH = 16
LINE_LIMIT = 75
FOLD_SEP = u'\r\n '

COUNTRIES_NAME_TO_CODE = {}
for code, name in product_details.get_regions('en').items():
name = name.lower()
COUNTRIES_NAME_TO_CODE[name] = code


@register.filter
def markdown(text):
Expand Down Expand Up @@ -264,3 +270,9 @@ def formset_errors_exist(formset):
if form.errors:
return True
return False


@register.filter
def get_country_code(country_name):
"""Return country code from country name."""
return COUNTRIES_NAME_TO_CODE.get(country_name.lower(), '')
1 change: 1 addition & 0 deletions remo/base/templates/multi_event_ical_template.ics
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DTEND;TZID={{ event.timezone }}:{{ event.end|format_datetime_utc }}
SEQUENCE:{{ event.times_edited }}
X-COORDINATES-LAT:{{ event.lat }}
X-COORDINATES-LON:{{ event.lon }}
X-COUNTRY-CODE:{{ event.country|get_country_code }}
END:VEVENT
{% endfor %}
END:VCALENDAR
13 changes: 13 additions & 0 deletions remo/base/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from nose.tools import eq_

from remo.base.helpers import get_country_code
from remo.base.tests import RemoTestCase


class GetCountryNameTests(RemoTestCase):
def test_base(self):
eq_(get_country_code('Greece'), 'gr')
eq_(get_country_code('greece'), 'gr')

def test_country_name_does_not_match(self):
eq_(get_country_code('FOO'), '')

0 comments on commit f4c7322

Please sign in to comment.