From 76aade171d5f7bfb6995fde2103a7f1052494420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Wed, 2 Aug 2017 20:25:43 +0200 Subject: [PATCH] tracks views --- cfp/forms.py | 25 ++++++++++++++++++ cfp/models.py | 8 +++--- cfp/templates/cfp/staff/base.html | 2 +- cfp/templates/cfp/staff/track_form.html | 23 ++++++++++++++++ cfp/templates/cfp/staff/track_list.html | 35 +++++++++++++++++++++++++ cfp/templatetags/cfp_tags.py | 7 +++++ cfp/urls.py | 3 +++ cfp/views.py | 31 +++++++++++++++++++++- 8 files changed, 128 insertions(+), 6 deletions(-) create mode 100644 cfp/templates/cfp/staff/track_form.html create mode 100644 cfp/templates/cfp/staff/track_list.html diff --git a/cfp/forms.py b/cfp/forms.py index e974ac1..86da851 100644 --- a/cfp/forms.py +++ b/cfp/forms.py @@ -141,3 +141,28 @@ class CreateUserForm(forms.ModelForm): if commit: user.save() return user + + +class TrackForm(forms.ModelForm): + class Meta: + model = Track + fields = ['name', 'description'] + + def __init__(self, *args, **kwargs): + self.conference = kwargs.pop('conference') + super().__init__(*args, **kwargs) + + # we should manually check (site, name) uniqueness as the site is not part of the form + def clean_name(self): + name = self.cleaned_data['name'] + if (not self.instance or self.instance.name != name) \ + and Track.objects.filter(site=self.conference.site, name=name).exists(): + raise self.instance.unique_error_message(self._meta.model, ['name']) + return name + + def save(self, commit=True): + track = super().save(commit=False) + track.site = self.conference.site + if commit: + track.save() + return track diff --git a/cfp/models.py b/cfp/models.py index 3f8f4c1..1478e94 100644 --- a/cfp/models.py +++ b/cfp/models.py @@ -145,14 +145,14 @@ class Track(PonyConfModel): class Meta: unique_together = ('site', 'name') - #def estimated_duration(self): - # return sum([talk.estimated_duration for talk in self.talk_set.all()]) + def estimated_duration(self): + return sum([talk.estimated_duration for talk in self.talk_set.all()]) def __str__(self): return self.name - #def get_absolute_url(self): - # return reverse('list-talks') + '?track=%s' % self.slug + def get_absolute_url(self): + return reverse('talk-list') + '?track=%s' % self.slug class TalkCategory(models.Model): # type of talk (conf 30min, 1h, stand, …) diff --git a/cfp/templates/cfp/staff/base.html b/cfp/templates/cfp/staff/base.html index dcf58f2..c9be51d 100644 --- a/cfp/templates/cfp/staff/base.html +++ b/cfp/templates/cfp/staff/base.html @@ -8,7 +8,6 @@