diff --git a/accounts/forms.py b/accounts/forms.py index 7f23eab..748a017 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -12,8 +12,7 @@ UserForm = modelform_factory(User, fields=['first_name', 'last_name', 'email', ' ProfileForm = modelform_factory(Profile, fields=['biography']) ParticipationForm = modelform_factory(Participation, - fields=['need_transport', 'transport', - 'need_hosting', 'homestay', + fields=['need_transport', 'transport', 'accommodation', 'connector', 'sound', 'videotaped', 'video_licence', 'constraints'], widgets={'transport': forms.CheckboxSelectMultiple(), @@ -26,7 +25,7 @@ ProfileOrgaForm = modelform_factory(Profile, fields=['biography']) ParticipationOrgaForm = modelform_factory(Participation, fields=['need_transport', 'transport', 'transport_booked', - 'need_hosting', 'homestay', 'hosting_booked', + 'accommodation', 'accommodation_booked', 'connector', 'sound', 'videotaped', 'video_licence', 'constraints', 'notes', 'orga'], diff --git a/accounts/migrations/0012_auto_20161006_1853.py b/accounts/migrations/0012_auto_20161006_1853.py new file mode 100644 index 0000000..ca8c7ca --- /dev/null +++ b/accounts/migrations/0012_auto_20161006_1853.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.1 on 2016-10-06 18:53 +from __future__ import unicode_literals + +from django.db import migrations, models + + +def migrate_accommodations(apps, schema_editor): + db_alias = schema_editor.connection.alias + Participation = apps.get_model('accounts', 'Participation') + for participation in Participation.objects.using(db_alias).all(): + if participation.need_hosting: + if participation.homestay: + participation.accommodation = 2 + else: + participation.accommodation = 1 + participation.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0011_auto_20161005_1841'), + ] + + operations = [ + migrations.RenameField( + model_name='participation', + old_name='hosting_booked', + new_name='accommodation_booked', + ), + migrations.AddField( + model_name='participation', + name='accommodation', + field=models.IntegerField(null=True, blank=True, choices=[(0, 'No'), (1, 'Hotel'), (2, 'Homestay')], verbose_name='Need accommodation?'), + ), + migrations.RunPython(migrate_accommodations), + migrations.RemoveField( + model_name='participation', + name='need_hosting', + ), + migrations.RemoveField( + model_name='participation', + name='homestay', + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 16414bc..7b5b775 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -46,6 +46,14 @@ class Connector(Option): class Participation(PonyConfModel): LICENCES = IntEnum('Video licence', 'CC-Zero CC-BY CC-BY-SA CC-BY-ND CC-BY-NC CC-BY-NC-SA CC-BY-NC-ND') + ACCOMMODATION_NO = 0 + ACCOMMODATION_HOTEL = 1 + ACCOMMODATION_HOMESTAY = 2 + ACCOMMODATION_CHOICES = ( + (ACCOMMODATION_NO, _('No')), + (ACCOMMODATION_HOTEL, _('Hotel')), + (ACCOMMODATION_HOMESTAY, _('Homestay')), + ) site = models.ForeignKey(Site, on_delete=models.CASCADE) user = models.ForeignKey(User) @@ -57,9 +65,8 @@ class Participation(PonyConfModel): transport = models.ManyToManyField(Transport, verbose_name=_("I'm ok to travel by"), blank=True) transport_booked = models.BooleanField(default=False) - need_hosting = models.BooleanField(verbose_name=_('Need hosting?'), default=False) - homestay = models.BooleanField(verbose_name=_('Ok for homestay?'), default=False) - hosting_booked = models.BooleanField(default=False) + accommodation = models.IntegerField(choices=ACCOMMODATION_CHOICES, verbose_name=_('Need accommodation?'), null=True, blank=True) + accommodation_booked = models.BooleanField(default=False) constraints = models.TextField(blank=True, verbose_name=_("Constraints")) connector = models.ManyToManyField(Connector, verbose_name=_("I can output"), blank=True) diff --git a/proposals/forms.py b/proposals/forms.py index 546e001..3556478 100644 --- a/proposals/forms.py +++ b/proposals/forms.py @@ -5,7 +5,7 @@ from django.utils.translation import ugettext_lazy as _ from django_select2.forms import Select2TagWidget -from accounts.models import User, Transport +from accounts.models import User, Participation, Transport from proposals.models import Conference, Event, Talk, Topic, Track STATUS_CHOICES = [ @@ -72,13 +72,13 @@ class TalkFilterForm(forms.Form): self.fields['track'].choices = [('none', 'Not assigned')] + list(tracks.values_list('slug', 'name')) -def get_transports(): +def get_options(option): try: - transports = list(Transport.objects.values_list('pk', 'name')) + options = list(option.objects.values_list('pk', 'name')) except OperationalError: # happens when db doesn't exist yet - transports = [] - return transports + options = [] + return options class SpeakerFilterForm(forms.Form): @@ -95,19 +95,16 @@ class SpeakerFilterForm(forms.Form): transport = forms.MultipleChoiceField( required=False, widget=forms.CheckboxSelectMultiple, - choices=get_transports(), + choices=get_options(Transport), ) - hosting = forms.MultipleChoiceField( + accommodation= forms.MultipleChoiceField( required=False, widget=forms.CheckboxSelectMultiple, - choices=[ - ('hotel', 'Hotel'), - ('homestay', 'Homestay'), - ], + choices=Participation.ACCOMMODATION_CHOICES, ) sound = forms.NullBooleanField() transport_booked = forms.NullBooleanField() - hosting_booked = forms.NullBooleanField() + accommodation_booked = forms.NullBooleanField() def __init__(self, *args, **kwargs): site = kwargs.pop('site') diff --git a/proposals/templates/proposals/speaker_list.html b/proposals/templates/proposals/speaker_list.html index 3e39d1e..0d954f8 100644 --- a/proposals/templates/proposals/speaker_list.html +++ b/proposals/templates/proposals/speaker_list.html @@ -19,8 +19,8 @@