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

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):
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)

View File

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

View File

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

View File

@ -32,9 +32,8 @@
<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 "Transport booked:" %}</b> {{ participation.transport_booked|yesno }}</li>
<li><b>{% trans "Need hosting:" %}</b> {{ participation.need_hosting|yesno }}</li>
<li><b>{% trans "Ok for homstay:" %}</b> {{ participation.homestay|yesno }}</li>
<li><b>{% trans "Hosting booked:" %}</b> {{ participation.hosting_booked|yesno }}</li>
<li><b>{% trans "Need accommodation:" %}</b> {{ participation.get_accommodation_display }}</li>
<li><b>{% trans "Accommodation booked:" %}</b> {{ participation.accommodation_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 "Need sound:" %}</b> {{ participation.sound|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']):
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']]))
if len(data['hosting']):
if len(data['accommodation']):
show_filters = True
queries = []
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))
speakers = speakers.filter(reduce(lambda x, y: x | y, [Q(accommodation__pk=pk) for pk in data['accommodation']]))
if data['sound'] != None:
show_filters = True
speakers = speakers.filter(sound=data['sound'])
if data['transport_booked'] != None:
show_filters = True
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
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', {
'speaker_list': speakers,
'filter_form': filter_form,