multiple choice for transports and connectors
This commit is contained in:
parent
ea72f19e83
commit
7ce9392cf1
|
@ -1,4 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
from django.db.models.signals import post_migrate
|
||||
|
||||
|
||||
class AccountsConfig(AppConfig):
|
||||
|
@ -6,3 +7,4 @@ class AccountsConfig(AppConfig):
|
|||
|
||||
def ready(self):
|
||||
import accounts.signals # noqa
|
||||
post_migrate.connect(accounts.signals.create_default_options, sender=self)
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.contrib.auth.models import User
|
|||
from django.forms.models import modelform_factory
|
||||
from django import forms
|
||||
|
||||
from django_select2.forms import Select2Widget
|
||||
from django_select2.forms import Select2Widget, Select2MultipleWidget
|
||||
|
||||
from .models import Participation, Profile
|
||||
|
||||
|
@ -13,12 +13,14 @@ UserForm = modelform_factory(User, fields=['first_name', 'last_name', 'email', '
|
|||
|
||||
ProfileForm = modelform_factory(Profile, fields=['biography'])
|
||||
|
||||
ParticipationForm = modelform_factory(Participation, fields=['transport', 'connector', 'sound', 'videotaped', 'video_licence', 'constraints'])
|
||||
ParticipationForm = modelform_factory(Participation, fields=['transport', 'connector', 'sound', 'videotaped', 'video_licence', 'constraints'],
|
||||
widgets={'transport': forms.CheckboxSelectMultiple(), 'connector': forms.CheckboxSelectMultiple()})
|
||||
|
||||
ProfileOrgaForm = modelform_factory(Profile, fields=['biography', 'notes'])
|
||||
|
||||
ParticipationOrgaForm = modelform_factory(Participation,
|
||||
fields=['transport', 'connector', 'sound', 'videotaped', 'video_licence', 'constraints', 'orga'])
|
||||
fields=['transport', 'connector', 'sound', 'videotaped', 'video_licence', 'constraints', 'orga'],
|
||||
widgets={'transport': forms.CheckboxSelectMultiple(), 'connector': forms.CheckboxSelectMultiple()})
|
||||
|
||||
class ParticipationField(forms.ModelChoiceField):
|
||||
def label_from_instance(self, obj):
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.7 on 2016-07-10 20:11
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0003_auto_20160709_2240'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Connector',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=64, unique=True)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Transport',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=64, unique=True)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='participation',
|
||||
name='connector',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='participation',
|
||||
name='transport',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='participation',
|
||||
name='connector',
|
||||
field=models.ManyToManyField(blank=True, to='accounts.Connector', verbose_name='I can output'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='participation',
|
||||
name='transport',
|
||||
field=models.ManyToManyField(blank=True, to='accounts.Transport', verbose_name="I'm ok to travel by"),
|
||||
),
|
||||
]
|
|
@ -26,6 +26,24 @@ class Profile(PonyConfModel):
|
|||
return reverse('profile')
|
||||
|
||||
|
||||
class Option(models.Model):
|
||||
name = models.CharField(max_length=64, unique=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Transport(Option):
|
||||
pass
|
||||
|
||||
|
||||
class Connector(Option):
|
||||
pass
|
||||
|
||||
|
||||
class Participation(PonyConfModel):
|
||||
|
||||
TRANSPORTS = IntEnum('Transport', 'train plane others')
|
||||
|
@ -37,9 +55,8 @@ class Participation(PonyConfModel):
|
|||
|
||||
arrival = models.DateTimeField(blank=True, null=True)
|
||||
departure = models.DateTimeField(blank=True, null=True)
|
||||
# TODO: These should multi-choice fields
|
||||
transport = models.IntegerField(choices=enum_to_choices(TRANSPORTS), blank=True, null=True)
|
||||
connector = models.IntegerField(choices=enum_to_choices(CONNECTORS), blank=True, null=True)
|
||||
transport = models.ManyToManyField(Transport, verbose_name="I'm ok to travel by", blank=True)
|
||||
connector = models.ManyToManyField(Connector, verbose_name="I can output", blank=True)
|
||||
constraints = models.TextField(blank=True)
|
||||
sound = models.BooleanField("I need sound", default=False)
|
||||
videotaped = models.BooleanField("I'm ok to be recorded on video", default=True)
|
||||
|
|
|
@ -5,7 +5,17 @@ from django.contrib.sites.shortcuts import get_current_site
|
|||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from .models import Participation, Profile
|
||||
from .models import Participation, Profile, Transport, Connector
|
||||
|
||||
|
||||
def create_default_options(sender, **kwargs):
|
||||
Transport.objects.get_or_create(name='Train')
|
||||
Transport.objects.get_or_create(name='Plain')
|
||||
Transport.objects.get_or_create(name='Carpooling')
|
||||
Connector.objects.get_or_create(name='VGA')
|
||||
Connector.objects.get_or_create(name='HDMI')
|
||||
Connector.objects.get_or_create(name='miniDP')
|
||||
Connector.objects.get_or_create(name='I need a computer')
|
||||
|
||||
|
||||
@receiver(user_logged_in)
|
||||
|
|
|
@ -23,3 +23,13 @@
|
|||
{% endblock %}
|
||||
|
||||
<a href="{% url 'password_change' %}" class="btn btn-warning">Change password</a>
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
{{ form.media.css }}
|
||||
{% endblock %}
|
||||
|
||||
{% block js_end %}
|
||||
{{ block.super }}
|
||||
{{ form.media.js }}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue