diff --git a/frontend/forms.py b/frontend/forms.py index 6a4b4d7..1b78833 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from django import forms -from frontend.models import Project, PersonGlobalIdentity, PresentationPerson, Presentation, PresentationEvent +from frontend.models import Project, PersonGlobalIdentity, PresentationPerson, Presentation, PresentationEvent, PresentationSubmission from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit, Layout @@ -177,6 +177,26 @@ class PresentationEventForm(forms.ModelForm): model = PresentationEvent fields = [u'date', u'name', u'workshop', u'place', u'start_date', u'end_date'] +class PresentationSubmissionForm(forms.ModelForm): + """ Form for the PresentationSubmission""" + def __init__(self, *args, **kwargs): + super(PresentationSubmissionForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.form_tag = False + self.helper.label_class = u'col-lg-2' + self.helper.field_class = u'col-lg-4' + self.helper.layout = Layout( + u'comment', + u'email', + ) + + comment = forms.CharField(label='Kommentar') + email = forms.EmailField(label='E-Mail Adresse') + + class Meta: + model = PresentationSubmission + fields = [u'comment', u'email'] + class PresentationForm(forms.ModelForm): @@ -190,19 +210,13 @@ class PresentationForm(forms.ModelForm): self.helper.layout = Layout( u'title', u'type', - u'abstract', - u'comments', - u'email' + u'abstract' ) - title = forms.CharField() - type = forms.ChoiceField(choices=[(u'new', u'Hauptvortrag'), (u'existing', u'andere Veranstaltung')], initial=u'new', widget=forms.RadioSelect()) + title = forms.CharField(label='Titel') + type = forms.ChoiceField(choices=[(u'main', u'Hauptvortrag'), (u'other', u'andere Veranstaltung')], initial=u'main', widget=forms.RadioSelect(), label='Veranstaltungstyp') abstract = forms.TextInput() - # Event (other event) - comments = forms.CharField() - email = forms.EmailField() - class Meta: model = Presentation fields = [u'title', u'type', u'abstract'] diff --git a/frontend/models.py b/frontend/models.py index 7d6a823..fc5ff43 100644 --- a/frontend/models.py +++ b/frontend/models.py @@ -18,26 +18,32 @@ class Project(models.Model): class Presentation(models.Model): """ Presention Model for PresentationForm""" - title = models.CharField(max_length=255) - type = models.CharField(max_length=255) - abstract = models.TextField() + title = models.CharField(max_length=255, verbose_name='Titel') + 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') + +class PresentationSubmission(models.Model): + """ Submission containing a Presentation """ + email = models.EmailField(max_length=255, verbose_name='E-Mail Adresse') + comment = models.TextField(verbose_name=u'Kommentar') + presentation = models.ForeignKey(Presentation, blank=False, null=False, db_index=True) class PresentationEvent(models.Model): """Veranstaltung""" - date = models.DateField() - name = models.CharField(max_length=255) - workshop = models.BooleanField() - place = models.CharField(max_length=255) - start_date = models.DateField() - end_date = models.DateField() - presentatiom = models.ForeignKey(Presentation, blank=False, null=False, db_index=True) + date = models.DateField(verbose_name='Veranstaltungsdatum') + name = models.CharField(max_length=255, verbose_name='Name') + workshop = models.BooleanField(verbose_name='Workshop') + place = models.CharField(max_length=255, verbose_name='Ort') + start_date = models.DateField(verbose_name='Startdatum') + end_date = models.DateField(verbose_name='Enddatum') + presentation = models.ForeignKey(Presentation, blank=False, null=False, db_index=True) class PresentationPerson(models.Model): """ Person Model for PresentationForm""" - given_name = models.CharField(max_length=255) - additional_name = models.CharField(max_length=255) - family_name = models.CharField(max_length=255) - hshmembership = models.CharField(max_length=255, choices=((u'yes', u'Ja'), (u'no', u'Nein'), (u'maybe', u'Maybe')), default=u'maybe') + given_name = models.CharField(max_length=255, verbose_name='Vorname') + additional_name = models.CharField(max_length=255, verbose_name='Namenszusatz', blank=True) + family_name = models.CharField(max_length=255, verbose_name='Nachname') + 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) diff --git a/frontend/templates/index.html b/frontend/templates/index.html index a3cbb37..32f137d 100644 --- a/frontend/templates/index.html +++ b/frontend/templates/index.html @@ -5,7 +5,6 @@ Feel free to discover.

diff --git a/frontend/templates/presentation-add.html b/frontend/templates/presentation-add.html index 9fec6a6..725a595 100644 --- a/frontend/templates/presentation-add.html +++ b/frontend/templates/presentation-add.html @@ -68,6 +68,8 @@ {% endfor %} +
+ {% crispy submission_form %}
diff --git a/frontend/views.py b/frontend/views.py index 9992a7c..60e90a3 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -15,7 +15,7 @@ from django.contrib.auth.views import login, logout from django.core.urlresolvers import reverse from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm -from frontend.forms import PresentationForm, PresentationEventForm, PresentationPersonForm +from frontend.forms import PresentationForm, PresentationEventForm, PresentationPersonForm, PresentationSubmissionForm from frontend.forms import PresentationEventFormHelper, PresentationPersonFormHelper from frontend.models import Presentation, PresentationEvent, PresentationPerson from frontend.formsets import PresentationEventInlineFormset, PresentationPersonInlineFormset @@ -118,6 +118,7 @@ class PresentationAddView(ProtectedTemplateView): """ These guys are passed through using get_context_data(). """ presentation_form = None + submission_form = None person_formset = None event_formset = None person_formhelper = PresentationPersonFormHelper @@ -142,12 +143,14 @@ class PresentationAddView(ProtectedTemplateView): def create_blank_forms(self): """ Create blank form + formsets for the user to fill. """ self.presentation_form = PresentationForm(prefix='presentation') + self.submission_form = PresentationSubmissionForm(prefix='submission') self.person_formset = PresentationPersonInlineFormset(prefix='person') self.event_formset = PresentationEventInlineFormset(prefix='event') def get_context_data(self, **kwargs): """ Add form + formsets to template context. """ kwargs[u'presentation_form'] = self.presentation_form + kwargs[u'submission_form'] = self.submission_form kwargs[u'person_formset'] = self.person_formset kwargs[u'event_formset'] = self.event_formset kwargs[u'person_formhelper'] = self.person_formhelper @@ -159,30 +162,39 @@ class PresentationAddView(ProtectedTemplateView): def handle_forms(self, request, *args, **kwargs): """ Once a POST came in, try and validate the forms, saving the data. """ presentation = None - success = 0 - """ Check the PresentationForm first and save it. """ + presentation_ok = False + person_ok = False + event_ok = False + submission_ok = False + """ Create all the forms and formsets based on request params to do validation. """ self.presentation_form = PresentationForm(request.POST, request.FILES, prefix='presentation') - if self.presentation_form.is_valid(): - presentation = self.presentation_form.save() - success += 1 - """ If the PresentationForm was good, we now have a Presentation to use for the other guys. """ - if presentation != None: - """ Get the person formset, validate and save. """ - person_formset = PresentationPersonInlineFormset(request.POST, request.FILES, instance=presentation, prefix='person') - if person_formset.is_valid(): - person_formset.save() - success += 1 - """ Get the event formset, validate and save. """ - event_formset = PresentationEventInlineFormset(request.POST, request.FILES, instance=presentation, prefix='event') - if event_formset.is_valid(): - event_formset.save() - success += 1 + self.person_formset = PresentationPersonInlineFormset(request.POST, request.FILES, prefix='person') + self.event_formset = PresentationEventInlineFormset(request.POST, request.FILES, prefix='event') + self.submission_form = PresentationSubmissionForm(request.POST, request.FILES, prefix='submission') + """ Check all for validity """ + presentation_ok = self.presentation_form.is_valid() + submission_ok = self.submission_form.is_valid() + person_ok = self.person_formset.is_valid() + """ Only other event type needs a valid event formset. """ + 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': + event_ok = self.event_formset.is_valid() else: - """ Create the formsets without the PresentationInstance, so their validation results can be displayed. """ - self.person_formset = PresentationPersonInlineFormset(request.POST, request.FILES, prefix='person') - self.event_formset = PresentationEventInlineFormset(request.POST, request.FILES, prefix='event') - """ Everything was good, go to success URI or something, i don't know. """ - if success == 3: + event_ok = True + """ Only if everything is alright, store it.""" + if presentation_ok == True and person_ok == True and event_ok == True and submission_ok == True: + presentation = self.presentation_form.save() + """ Now we can create the other ones based on the saved presentation to save them, too. """ + submission_form = PresentationSubmissionForm(request.POST, request.FILES, instance=presentation, prefix='submission') + submission_form.save() + person_formset = PresentationPersonInlineFormset(request.POST, request.FILES, instance=presentation, prefix='person') + person_formset.save() + """ Conditionally save the events depending on whether they are needed. """ + if presentation.type == 'other': + event_formset = PresentationEventInlineFormset(request.POST, request.FILES, instance=presentation, prefix='event') + event_formset.save() + """ we're done. """ self.success = True self.create_blank_forms() else: