diff --git a/src/pretix/base/models/event.py b/src/pretix/base/models/event.py index 32c81fef6..116582e65 100644 --- a/src/pretix/base/models/event.py +++ b/src/pretix/base/models/event.py @@ -59,6 +59,7 @@ class Event(LoggedModel): """ settings_namespace = 'event' + CURRENCY_CHOICES = [(c.alpha_3, c.alpha_3 + " - " + c.name) for c in settings.CURRENCIES] organizer = models.ForeignKey(Organizer, related_name="events", on_delete=models.PROTECT) name = I18nCharField( max_length=200, @@ -83,6 +84,7 @@ class Event(LoggedModel): related_name="events", ) currency = models.CharField(max_length=10, verbose_name=_("Default currency"), + choices=CURRENCY_CHOICES, default=settings.DEFAULT_CURRENCY) date_from = models.DateTimeField(verbose_name=_("Event start time")) date_to = models.DateTimeField(null=True, blank=True, diff --git a/src/pretix/settings.py b/src/pretix/settings.py index c8a77f994..a34e98712 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -1,6 +1,7 @@ import configparser import os import sys +from pycountry import currencies import django.conf.locale from django.contrib.messages import constants as messages # NOQA @@ -85,6 +86,7 @@ PRETIX_PLUGINS_DEFAULT = config.get('pretix', 'plugins_default', fallback='pretix.plugins.sendmail,pretix.plugins.statistics') DEFAULT_CURRENCY = config.get('pretix', 'currency', fallback='EUR') +CURRENCIES = list(currencies) ALLOWED_HOSTS = ['*'] diff --git a/src/requirements/production.txt b/src/requirements/production.txt index 53ae8e4c4..b8836d43a 100644 --- a/src/requirements/production.txt +++ b/src/requirements/production.txt @@ -37,3 +37,4 @@ pycparser==2.13 # https://github.com/eliben/pycparser/issues/147 chardet>=2.3,<3 mt-940==3.2 vobject==0.9.* +pycountry diff --git a/src/setup.py b/src/setup.py index a3595b45e..5685c0354 100644 --- a/src/setup.py +++ b/src/setup.py @@ -98,7 +98,8 @@ setup( 'chardet>=2.3,<3', 'mt-940==3.2', 'django-i18nfield', - 'vobject==0.9.*' + 'vobject==0.9.*', + 'pycountry' ], extras_require={ 'dev': [ diff --git a/src/tests/control/test_events.py b/src/tests/control/test_events.py index f2a9704f0..4c41614a2 100644 --- a/src/tests/control/test_events.py +++ b/src/tests/control/test_events.py @@ -386,3 +386,47 @@ class EventsTest(SoupTest): 'basics-presale_end': '2016-11-24 18:00:00', }) assert doc.select(".alert-danger") + + def test_create_event_currency_symbol(self): + doc = self.post_doc('/control/events/add', { + 'event_wizard-current_step': 'foundation', + 'foundation-organizer': self.orga1.pk, + 'foundation-locales': 'en' + }) + + doc = self.post_doc('/control/events/add', { + 'event_wizard-current_step': 'basics', + 'basics-name_0': '33C3', + 'basics-slug': '31c4', + 'basics-date_from': '2016-12-27 10:00:00', + 'basics-date_to': '2016-12-30 19:00:00', + 'basics-location_0': 'Hamburg', + 'basics-currency': '$', + 'basics-locale': 'en', + 'basics-timezone': 'Europe/Berlin', + 'basics-presale_start': '2016-11-01 10:00:00', + 'basics-presale_end': '2016-11-30 18:00:00', + }) + assert doc.select(".alert-danger") + + def test_create_event_non_iso_currency(self): + doc = self.post_doc('/control/events/add', { + 'event_wizard-current_step': 'foundation', + 'foundation-organizer': self.orga1.pk, + 'foundation-locales': 'en' + }) + + doc = self.post_doc('/control/events/add', { + 'event_wizard-current_step': 'basics', + 'basics-name_0': '33C3', + 'basics-slug': '31c5', + 'basics-date_from': '2016-12-27 10:00:00', + 'basics-date_to': '2016-12-30 19:00:00', + 'basics-location_0': 'Hamburg', + 'basics-currency': 'ASD', + 'basics-locale': 'en', + 'basics-timezone': 'Europe/Berlin', + 'basics-presale_start': '2016-11-01 10:00:00', + 'basics-presale_end': '2016-11-30 18:00:00', + }) + assert doc.select(".alert-danger")