hosting is now accommodation

and accommodation is a choice field
This commit is contained in:
Élie Bouttier 2016-10-06 21:24:52 +02:00
parent 8510500480
commit c1d8fef1d2
7 changed files with 78 additions and 43 deletions

View File

@ -12,8 +12,7 @@ UserForm = modelform_factory(User, fields=['first_name', 'last_name', 'email', '
ProfileForm = modelform_factory(Profile, fields=['biography']) ProfileForm = modelform_factory(Profile, fields=['biography'])
ParticipationForm = modelform_factory(Participation, ParticipationForm = modelform_factory(Participation,
fields=['need_transport', 'transport', fields=['need_transport', 'transport', 'accommodation',
'need_hosting', 'homestay',
'connector', 'sound', 'videotaped', 'connector', 'sound', 'videotaped',
'video_licence', 'constraints'], 'video_licence', 'constraints'],
widgets={'transport': forms.CheckboxSelectMultiple(), widgets={'transport': forms.CheckboxSelectMultiple(),
@ -26,7 +25,7 @@ ProfileOrgaForm = modelform_factory(Profile, fields=['biography'])
ParticipationOrgaForm = modelform_factory(Participation, ParticipationOrgaForm = modelform_factory(Participation,
fields=['need_transport', 'transport', 'transport_booked', fields=['need_transport', 'transport', 'transport_booked',
'need_hosting', 'homestay', 'hosting_booked', 'accommodation', 'accommodation_booked',
'connector', 'sound', 'videotaped', 'connector', 'sound', 'videotaped',
'video_licence', 'video_licence',
'constraints', 'notes', 'orga'], 'constraints', 'notes', 'orga'],

View File

@ -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',
),
]

View File

@ -46,6 +46,14 @@ class Connector(Option):
class Participation(PonyConfModel): 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') 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) site = models.ForeignKey(Site, on_delete=models.CASCADE)
user = models.ForeignKey(User) 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 = models.ManyToManyField(Transport, verbose_name=_("I'm ok to travel by"), blank=True)
transport_booked = models.BooleanField(default=False) transport_booked = models.BooleanField(default=False)
need_hosting = models.BooleanField(verbose_name=_('Need hosting?'), default=False) accommodation = models.IntegerField(choices=ACCOMMODATION_CHOICES, verbose_name=_('Need accommodation?'), null=True, blank=True)
homestay = models.BooleanField(verbose_name=_('Ok for homestay?'), default=False) accommodation_booked = models.BooleanField(default=False)
hosting_booked = models.BooleanField(default=False)
constraints = models.TextField(blank=True, verbose_name=_("Constraints")) constraints = models.TextField(blank=True, verbose_name=_("Constraints"))
connector = models.ManyToManyField(Connector, verbose_name=_("I can output"), blank=True) connector = models.ManyToManyField(Connector, verbose_name=_("I can output"), blank=True)

View File

@ -5,7 +5,7 @@ from django.utils.translation import ugettext_lazy as _
from django_select2.forms import Select2TagWidget 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 from proposals.models import Conference, Event, Talk, Topic, Track
STATUS_CHOICES = [ STATUS_CHOICES = [
@ -72,13 +72,13 @@ class TalkFilterForm(forms.Form):
self.fields['track'].choices = [('none', 'Not assigned')] + list(tracks.values_list('slug', 'name')) self.fields['track'].choices = [('none', 'Not assigned')] + list(tracks.values_list('slug', 'name'))
def get_transports(): def get_options(option):
try: try:
transports = list(Transport.objects.values_list('pk', 'name')) options = list(option.objects.values_list('pk', 'name'))
except OperationalError: except OperationalError:
# happens when db doesn't exist yet # happens when db doesn't exist yet
transports = [] options = []
return transports return options
class SpeakerFilterForm(forms.Form): class SpeakerFilterForm(forms.Form):
@ -95,19 +95,16 @@ class SpeakerFilterForm(forms.Form):
transport = forms.MultipleChoiceField( transport = forms.MultipleChoiceField(
required=False, required=False,
widget=forms.CheckboxSelectMultiple, widget=forms.CheckboxSelectMultiple,
choices=get_transports(), choices=get_options(Transport),
) )
hosting = forms.MultipleChoiceField( accommodation= forms.MultipleChoiceField(
required=False, required=False,
widget=forms.CheckboxSelectMultiple, widget=forms.CheckboxSelectMultiple,
choices=[ choices=Participation.ACCOMMODATION_CHOICES,
('hotel', 'Hotel'),
('homestay', 'Homestay'),
],
) )
sound = forms.NullBooleanField() sound = forms.NullBooleanField()
transport_booked = forms.NullBooleanField() transport_booked = forms.NullBooleanField()
hosting_booked = forms.NullBooleanField() accommodation_booked = forms.NullBooleanField()
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
site = kwargs.pop('site') site = kwargs.pop('site')

View File

@ -19,8 +19,8 @@
<div class="col-md-4 col-xs-6"> <div class="col-md-4 col-xs-6">
{% bootstrap_field filter_form.transport layout="horizontal" %} {% bootstrap_field filter_form.transport layout="horizontal" %}
{% bootstrap_field filter_form.transport_booked layout="horizontal" %} {% bootstrap_field filter_form.transport_booked layout="horizontal" %}
{% bootstrap_field filter_form.hosting layout="horizontal" %} {% bootstrap_field filter_form.accommodation layout="horizontal" %}
{% bootstrap_field filter_form.hosting_booked layout="horizontal" %} {% bootstrap_field filter_form.accommodation_booked layout="horizontal" %}
</div> </div>
<div class="col-md-4 col-xs-6"> <div class="col-md-4 col-xs-6">
{% bootstrap_field filter_form.sound layout="horizontal" %} {% bootstrap_field filter_form.sound layout="horizontal" %}
@ -42,7 +42,7 @@
<th class="text-center">{% trans "Fullname" %}</th> <th class="text-center">{% trans "Fullname" %}</th>
<th class="text-center">{% trans "Talk count" %}</th> <th class="text-center">{% trans "Talk count" %}</th>
<th class="text-center">{% blocktrans context "table column title" %}Need transport?{% endblocktrans %}</th> <th class="text-center">{% blocktrans context "table column title" %}Need transport?{% endblocktrans %}</th>
<th class="text-center">{% blocktrans context "table column title" %}Need hosting?{% endblocktrans %}</th> <th class="text-center">{% blocktrans context "table column title" %}Need accommodation?{% endblocktrans %}</th>
<th class="text-center">{% trans "Need sound?" %}</th> <th class="text-center">{% trans "Need sound?" %}</th>
<th class="text-center"></th> <th class="text-center"></th>
</tr> </tr>
@ -69,17 +69,9 @@
{% else %} {% else %}
<td>No</td> <td>No</td>
{% endif %} {% endif %}
{% if speaker.need_hosting %} <td{% if speaker.accommodation != speaker.ACCOMMODATION_NO %} class="{% if speaker.accommodation_booked %}success{% else %}warning{% endif %}"{% endif %}>
<td class="{% if speaker.hosting_booked %}success{% else %}warning{% endif %}"> {{ speaker.get_accommodation_display }}
{% if speaker.homestay %}
Logement chez habitant
{% else %}
Hotel
{% endif %}
</td> </td>
{% else %}
<td></td>
{% endif %}
{% if speaker.sound %} {% if speaker.sound %}
<td class="warning">Yes</td> <td class="warning">Yes</td>
{% else %} {% else %}

View File

@ -32,9 +32,8 @@
<li><b>{% trans "Departure:" %}</b> {{ participation.departure }}</li> <li><b>{% trans "Departure:" %}</b> {{ participation.departure }}</li>
<li><b>{% trans "Ok to travel by:" %}</b> {% for transport in participation.transport.all %}{% if not forloop.first %}, {% endif %}{{ transport }}{% endfor %}</li> <li><b>{% trans "Ok to travel by:" %}</b> {% for transport in participation.transport.all %}{% if not forloop.first %}, {% endif %}{{ transport }}{% endfor %}</li>
<li><b>{% trans "Transport booked:" %}</b> {{ participation.transport_booked|yesno }}</li> <li><b>{% trans "Transport booked:" %}</b> {{ participation.transport_booked|yesno }}</li>
<li><b>{% trans "Need hosting:" %}</b> {{ participation.need_hosting|yesno }}</li> <li><b>{% trans "Need accommodation:" %}</b> {{ participation.get_accommodation_display }}</li>
<li><b>{% trans "Ok for homstay:" %}</b> {{ participation.homestay|yesno }}</li> <li><b>{% trans "Accommodation booked:" %}</b> {{ participation.accommodation_booked|yesno }}</li>
<li><b>{% trans "Hosting booked:" %}</b> {{ participation.hosting_booked|yesno }}</li>
<li><b>{% trans "Video output:" %}</b> {% for conn in participation.connector.all %}{% if not forloop.first %}, {% endif %}{{ conn }}{% endfor %}</li> <li><b>{% trans "Video output:" %}</b> {% for conn in participation.connector.all %}{% if not forloop.first %}, {% endif %}{{ conn }}{% endfor %}</li>
<li><b>{% trans "Need sound:" %}</b> {{ participation.sound|yesno }}</li> <li><b>{% trans "Need sound:" %}</b> {{ participation.sound|yesno }}</li>
<li><b>{% trans "Ok to be recorded on video:" %}</b> {{ participation.videotaped|yesno }}</li> <li><b>{% trans "Ok to be recorded on video:" %}</b> {{ participation.videotaped|yesno }}</li>

View File

@ -309,23 +309,18 @@ def speaker_list(request):
if len(data['transport']): if len(data['transport']):
show_filters = True show_filters = True
speakers = speakers.filter(need_transport=True).filter(reduce(lambda x, y: x | y, [Q(transport__pk=pk) for pk in data['transport']])) speakers = speakers.filter(need_transport=True).filter(reduce(lambda x, y: x | y, [Q(transport__pk=pk) for pk in data['transport']]))
if len(data['hosting']): if len(data['accommodation']):
show_filters = True show_filters = True
queries = [] speakers = speakers.filter(reduce(lambda x, y: x | y, [Q(accommodation__pk=pk) for pk in data['accommodation']]))
if 'hotel' in data['hosting']:
queries += [ Q(need_hosting=True, homestay=False) ]
if 'homestay' in data['hosting']:
queries += [ Q(need_hosting=True, homestay=True) ]
speakers = speakers.filter(reduce(lambda x, y: x | y, queries))
if data['sound'] != None: if data['sound'] != None:
show_filters = True show_filters = True
speakers = speakers.filter(sound=data['sound']) speakers = speakers.filter(sound=data['sound'])
if data['transport_booked'] != None: if data['transport_booked'] != None:
show_filters = True show_filters = True
speakers = speakers.filter(need_transport=True).filter(transport_booked=data['transport_booked']) speakers = speakers.filter(need_transport=True).filter(transport_booked=data['transport_booked'])
if data['hosting_booked'] != None: if data['accommodation_booked'] != None:
show_filters = True show_filters = True
speakers = speakers.filter(need_hosting=True).filter(hosting_booked=data['hosting_booked']) speakers = speakers.filter(need_accommodation=True).filter(accommodation_booked=data['accommodation_booked'])
return render(request, 'proposals/speaker_list.html', { return render(request, 'proposals/speaker_list.html', {
'speaker_list': speakers, 'speaker_list': speakers,
'filter_form': filter_form, 'filter_form': filter_form,