[TASK] Add datepicker to event forms.

This commit is contained in:
Jan Philipp Timme 2014-12-11 16:30:54 +01:00
parent 3c183a256b
commit 8d66c77a1b
6 changed files with 102 additions and 73 deletions

View File

@ -1,8 +1,17 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.contrib import admin from django.contrib import admin
from frontend.models import Project, PersonGlobalIdentity, CitaviProjectIdentity
from frontend.models import Project, PersonGlobalIdentity, CitaviProjectIdentity, HSHIdentity, VIVOIdentity
admin.site.register(Project) admin.site.register(Project)
admin.site.register(PersonGlobalIdentity) admin.site.register(PersonGlobalIdentity)
admin.site.register(CitaviProjectIdentity) admin.site.register(CitaviProjectIdentity)
admin.site.register(HSHIdentity)
admin.site.register(VIVOIdentity)
from frontend.models import Presentation, PresentationEvent, PresentationPerson, PresentationSubmission
admin.site.register(Presentation)
admin.site.register(PresentationEvent)
admin.site.register(PresentationPerson)
admin.site.register(PresentationSubmission)

View File

@ -93,40 +93,40 @@ PresentationPersonFormHelper.layout = Layout(
u'hshmembership' u'hshmembership'
) )
class PresentationPersonForm(forms.ModelForm): # class PresentationPersonForm(forms.ModelForm):
""" Modelform for PresentationPerson """ # """ Modelform for PresentationPerson """
def __init__(self, *args, **kwargs): # def __init__(self, *args, **kwargs):
super(PresentationPersonForm, self).__init__(*args, **kwargs) # super(PresentationPersonForm, self).__init__(*args, **kwargs)
self.helper = PresentationPersonFormHelper # self.helper = PresentationPersonFormHelper
#
given_name = forms.CharField( # given_name = forms.CharField(
label=u"Vorname", # label=u"Vorname",
max_length=255, # max_length=255,
required=True, # required=True,
) # )
#
additional_name = forms.CharField( # additional_name = forms.CharField(
label=u"Zweiter Vorname/Zusatz", # label=u"Zweiter Vorname/Zusatz",
max_length=255, # max_length=255,
required=False, # required=False,
) # )
#
family_name = forms.CharField( # family_name = forms.CharField(
label=u"Nachname", # label=u"Nachname",
max_length=255, # max_length=255,
required=True, # required=True,
) # )
#
hshmembership = forms.TypedChoiceField( # hshmembership = forms.TypedChoiceField(
choices=((u'yes', u'Ja'), (u'no', u'Nein'), (u'maybe', u'Maybe')), # choices=((u'yes', u'Ja'), (u'no', u'Nein'), (u'maybe', u'Maybe')),
initial=u'maybe', # initial=u'maybe',
required=True, # required=True,
widget=forms.RadioSelect() # widget=forms.RadioSelect()
) # )
#
class Meta: # class Meta:
model = PresentationPerson # model = PresentationPerson
fields = [u'given_name', u'additional_name', u'family_name', u'hshmembership'] # fields = [u'given_name', u'additional_name', u'family_name', u'hshmembership']
""" FormHelper for the PresentationEventForm""" """ FormHelper for the PresentationEventForm"""
@ -143,39 +143,39 @@ PresentationEventFormHelper.layout = Layout(
u'end_date' u'end_date'
) )
class PresentationEventForm(forms.ModelForm): # class PresentationEventForm(forms.ModelForm):
""" Form for the PresentationEventModel""" # """ Form for the PresentationEventModel"""
def __init__(self, *args, **kwargs): # def __init__(self, *args, **kwargs):
super(PresentationEventForm, self).__init__(*args, **kwargs) # super(PresentationEventForm, self).__init__(*args, **kwargs)
self.helper = PresentationEventFormHelper # self.helper = PresentationEventFormHelper
#
date = forms.DateField( # date = forms.DateField(
label=u"Datum", # label=u"Datum",
required=True , # required=True ,
) # )
name = forms.CharField( # name = forms.CharField(
label=u"Rahmen der Veranstaltung", # label=u"Rahmen der Veranstaltung",
max_length=255, # max_length=255,
required=True, # required=True,
) # )
workshop = forms.BooleanField( # workshop = forms.BooleanField(
label=u"Veranstaltung ist ein Workshop", # label=u"Veranstaltung ist ein Workshop",
required=False, # required=False,
) # )
place = forms.CharField( # place = forms.CharField(
label=u"Ort", # label=u"Ort",
max_length=255 , # max_length=255 ,
required=True, # required=True,
) # )
start_date = forms.DateField( # start_date = forms.DateField(
label=u"Startdatum" # label=u"Startdatum"
) # )
end_date = forms.DateField( # end_date = forms.DateField(
label=u"Enddatum" # label=u"Enddatum"
) # )
class Meta: # class Meta:
model = PresentationEvent # model = PresentationEvent
fields = [u'date', u'name', u'workshop', u'place', u'start_date', u'end_date'] # fields = [u'date', u'name', u'workshop', u'place', u'start_date', u'end_date']
class PresentationSubmissionForm(forms.ModelForm): class PresentationSubmissionForm(forms.ModelForm):
""" Form for the PresentationSubmission""" """ Form for the PresentationSubmission"""

View File

@ -2,6 +2,8 @@ from django import forms
from frontend.models import Presentation, PresentationEvent, PresentationPerson from frontend.models import Presentation, PresentationEvent, PresentationPerson
from django.forms.models import inlineformset_factory from django.forms.models import inlineformset_factory
from bootstrap3_datetime.widgets import DateTimePicker
PresentationPersonInlineFormset = inlineformset_factory( PresentationPersonInlineFormset = inlineformset_factory(
Presentation, Presentation,
@ -15,5 +17,10 @@ PresentationEventInlineFormset = inlineformset_factory(
Presentation, Presentation,
PresentationEvent, PresentationEvent,
extra=1, extra=1,
can_delete=False can_delete=False,
) widgets={
'date': DateTimePicker(options={"format": "YYYY-MM-DD", 'pickSeconds': False}),
'start_date': DateTimePicker(options={"format": "YYYY-MM-DD", 'pickSeconds': False}),
'end_date': DateTimePicker(options={"format": "YYYY-MM-DD", 'pickSeconds': False})
}
)

View File

@ -22,12 +22,19 @@ class Presentation(models.Model):
type = models.CharField(max_length=255, choices=((u'main', u'Hauptvortrag'), (u'other', u'andere Veranstaltung')), default=u'main', verbose_name='Veranstaltungstyp') type = models.CharField(max_length=255, choices=((u'main', u'Hauptvortrag'), (u'other', u'andere Veranstaltung')), default=u'main', verbose_name='Veranstaltungstyp')
abstract = models.TextField(verbose_name=u'Zusammenfassung') abstract = models.TextField(verbose_name=u'Zusammenfassung')
def __unicode__(self):
return self.title
class PresentationSubmission(models.Model): class PresentationSubmission(models.Model):
""" Submission containing a Presentation """ """ Submission containing a Presentation """
email = models.EmailField(max_length=255, verbose_name='E-Mail Adresse') email = models.EmailField(max_length=255, verbose_name='E-Mail Adresse')
comment = models.TextField(verbose_name=u'Kommentar') comment = models.TextField(verbose_name=u'Kommentar')
presentation = models.ForeignKey(Presentation, blank=False, null=False, db_index=True) presentation = models.ForeignKey(Presentation, blank=False, null=False, db_index=True)
def __unicode__(self):
return self.email
class PresentationEvent(models.Model): class PresentationEvent(models.Model):
"""Veranstaltung""" """Veranstaltung"""
date = models.DateField(verbose_name='Veranstaltungsdatum') date = models.DateField(verbose_name='Veranstaltungsdatum')
@ -38,6 +45,9 @@ class PresentationEvent(models.Model):
end_date = models.DateField(verbose_name='Enddatum') end_date = models.DateField(verbose_name='Enddatum')
presentation = models.ForeignKey(Presentation, blank=False, null=False, db_index=True) presentation = models.ForeignKey(Presentation, blank=False, null=False, db_index=True)
def __unicode__(self):
return self.name
class PresentationPerson(models.Model): class PresentationPerson(models.Model):
""" Person Model for PresentationForm""" """ Person Model for PresentationForm"""
given_name = models.CharField(max_length=255, verbose_name='Vorname') given_name = models.CharField(max_length=255, verbose_name='Vorname')
@ -46,6 +56,9 @@ class PresentationPerson(models.Model):
hshmembership = models.CharField(max_length=255, choices=((u'yes', u'Ja'), (u'no', u'Nein'), (u'maybe', u'Maybe')), default=u'maybe', verbose_name='Hochschulangehörigkeit') hshmembership = models.CharField(max_length=255, choices=((u'yes', u'Ja'), (u'no', u'Nein'), (u'maybe', u'Maybe')), default=u'maybe', verbose_name='Hochschulangehörigkeit')
presentation = models.ForeignKey(Presentation, blank=False, null=False, db_index=True) presentation = models.ForeignKey(Presentation, blank=False, null=False, db_index=True)
def __unicode__(self):
return self.given_name + ' ' + self.family_name
class PersonGlobalIdentity(models.Model): class PersonGlobalIdentity(models.Model):
""" Model representing a global person identity in django. Can be used to link any foreign identity to it. """ """ Model representing a global person identity in django. Can be used to link any foreign identity to it. """

View File

@ -23,6 +23,7 @@
}); });
}) })
</script> </script>
{{ event_formset.media }}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% if success %} {% if success %}

View File

@ -15,7 +15,7 @@ from django.contrib.auth.views import login, logout
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm
from frontend.forms import PresentationForm, PresentationEventForm, PresentationPersonForm, PresentationSubmissionForm from frontend.forms import PresentationForm, PresentationSubmissionForm
from frontend.forms import PresentationEventFormHelper, PresentationPersonFormHelper from frontend.forms import PresentationEventFormHelper, PresentationPersonFormHelper
from frontend.models import Presentation, PresentationEvent, PresentationPerson from frontend.models import Presentation, PresentationEvent, PresentationPerson
from frontend.formsets import PresentationEventInlineFormset, PresentationPersonInlineFormset from frontend.formsets import PresentationEventInlineFormset, PresentationPersonInlineFormset
@ -177,7 +177,6 @@ class PresentationAddView(ProtectedTemplateView):
person_ok = self.person_formset.is_valid() person_ok = self.person_formset.is_valid()
""" Only other event type needs a valid event formset. """ """ Only other event type needs a valid event formset. """
print(presentation_ok, person_ok, event_ok, submission_ok) print(presentation_ok, person_ok, event_ok, submission_ok)
print(self.submission_form)
if presentation_ok and self.presentation_form.cleaned_data[u'type'] == 'other': if presentation_ok and self.presentation_form.cleaned_data[u'type'] == 'other':
event_ok = self.event_formset.is_valid() event_ok = self.event_formset.is_valid()
else: else: