From 8af49a1020bba94f8db617eba7a587e4373dc4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Fri, 15 Jul 2016 01:06:33 +0200 Subject: [PATCH] Ajout d'un calendrier dynamique MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ce patch propose aux adhérents du COF de télécharger un calendrier dynamique (`.ics`). Il est configurable : - On peut s'abonner ou non aux événements du COF. - On peut choisir les spectacles auxquels on veut s'abonner. --- cof/urls.py | 4 +- gestioncof/forms.py | 18 +++++- gestioncof/migrations/0005_add_calendar.py | 40 ++++++++++++ gestioncof/models.py | 16 +++-- .../templates/calendar_subscription.html | 22 +++++++ gestioncof/templates/home.html | 2 +- gestioncof/urls.py | 5 ++ gestioncof/views.py | 62 +++++++++++++++++-- requirements.txt | 1 + 9 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 gestioncof/migrations/0005_add_calendar.py create mode 100644 gestioncof/templates/calendar_subscription.html diff --git a/cof/urls.py b/cof/urls.py index b5d2b65a..1fd7b2c1 100644 --- a/cof/urls.py +++ b/cof/urls.py @@ -11,7 +11,7 @@ from django.contrib import admin from django.views.generic.base import TemplateView from gestioncof.urls import export_patterns, petitcours_patterns, \ - surveys_patterns, events_patterns + surveys_patterns, events_patterns, calendar_patterns autocomplete_light.autodiscover() admin.autodiscover() @@ -30,6 +30,8 @@ urlpatterns = patterns( url(r'^survey/', include(surveys_patterns)), # Evenements url(r'^event/', include(events_patterns)), + # Calendrier + url(r'^calendar/', include(calendar_patterns)), # Authentification url(r'^cof/denied$', TemplateView.as_view(template_name='cof-denied.html'), name="cof-denied"), diff --git a/gestioncof/forms.py b/gestioncof/forms.py index bf983df5..500f3a8b 100644 --- a/gestioncof/forms.py +++ b/gestioncof/forms.py @@ -6,10 +6,13 @@ from django.contrib.auth.models import User from django.forms.widgets import RadioSelect, CheckboxSelectMultiple from django.db.models import Max -from gestioncof.models import CofProfile, EventCommentValue +from gestioncof.models import CofProfile, EventCommentValue, \ + CalendarSubscription from gestioncof.widgets import TriStateCheckbox from gestioncof.shared import lock_table, unlock_table +from bda.models import Spectacle + class EventForm(forms.Form): def __init__(self, *args, **kwargs): @@ -330,3 +333,16 @@ class AdminEventForm(forms.Form): for name, value in self.cleaned_data.items(): if name.startswith('comment_'): yield (self.fields[name].comment_id, value) + + +class CalendarForm(forms.ModelForm): + events = forms.BooleanField(initial=True, label="S'abonner aux événements") + shows = forms.ModelMultipleChoiceField( + label="S'abonner aux spectacles suivants", + queryset=Spectacle.objects.filter(tirage__active=True).all(), + widget=forms.CheckboxSelectMultiple, + initial=Spectacle.objects.filter(tirage__active=True).all()) + + class Meta: + model = CalendarSubscription + exclude = ['user'] diff --git a/gestioncof/migrations/0005_add_calendar.py b/gestioncof/migrations/0005_add_calendar.py new file mode 100644 index 00000000..b8686bb5 --- /dev/null +++ b/gestioncof/migrations/0005_add_calendar.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + ('bda', '0004_mails-rappel'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('gestioncof', '0004_registration_mail'), + ] + + operations = [ + migrations.CreateModel( + name='CalendarSubscription', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, + auto_created=True, primary_key=True)), + ('events', models.BooleanField(default=True)), + ('shows', models.ManyToManyField(to='bda.Spectacle')), + ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.AlterField( + model_name='event', + name='end_date', + field=models.DateTimeField(null=True, verbose_name=b'Date de fin', + blank=True), + ), + migrations.AlterField( + model_name='event', + name='start_date', + field=models.DateTimeField(null=True, + verbose_name=b'Date de d\xc3\xa9but', + blank=True), + ), + ] diff --git a/gestioncof/models.py b/gestioncof/models.py index 540145d5..b3ef9921 100644 --- a/gestioncof/models.py +++ b/gestioncof/models.py @@ -7,6 +7,8 @@ from django.db.models.signals import post_save from petits_cours_models import * +from bda.models import Spectacle + OCCUPATION_CHOICES = ( ('exterieur', _(u"Extérieur")), ('1A', _(u"1A")), @@ -94,8 +96,7 @@ class CustomMail(models.Model): blank=True) class Meta: - verbose_name = "Mail personnalisable" - verbose_name_plural = "Mails personnalisables" + verbose_name = "Mails personnalisables" def __unicode__(self): return u"%s: %s" % (self.shortname, self.title) @@ -104,8 +105,8 @@ class CustomMail(models.Model): class Event(models.Model): title = models.CharField("Titre", max_length=200) location = models.CharField("Lieu", max_length=200) - start_date = models.DateField("Date de début", blank=True, null=True) - end_date = models.DateField("Date de fin", blank=True, null=True) + start_date = models.DateTimeField("Date de début", blank=True, null=True) + end_date = models.DateTimeField("Date de fin", blank=True, null=True) description = models.TextField("Description", blank=True) image = models.ImageField("Image", blank=True, null=True, upload_to="imgs/events/") @@ -159,7 +160,6 @@ class EventOptionChoice(models.Model): class Meta: verbose_name = "Choix" - verbose_name_plural = "Choix" def __unicode__(self): return unicode(self.value) @@ -232,3 +232,9 @@ class SurveyAnswer(models.Model): class Clipper(models.Model): username = models.CharField("Identifiant", max_length=20) fullname = models.CharField("Nom complet", max_length=200) + + +class CalendarSubscription(models.Model): + user = models.ForeignKey(User) + shows = models.ManyToManyField(Spectacle) + events = models.BooleanField(default=True) diff --git a/gestioncof/templates/calendar_subscription.html b/gestioncof/templates/calendar_subscription.html new file mode 100644 index 00000000..65a8b9e6 --- /dev/null +++ b/gestioncof/templates/calendar_subscription.html @@ -0,0 +1,22 @@ +{% extends "base_title.html" %} + +{% block realcontent %} + +{% if success %} +

Calendrier mis à jour avec succès

+{% endif %} + +{% if error %} +

{{ error }}

+{% endif %} + +

Calendrier disponible à +cette adresse

+ +
+{% csrf_token %} +{{ form.as_p }} + +
+ +{% endblock %} diff --git a/gestioncof/templates/home.html b/gestioncof/templates/home.html index ed567455..ab21c541 100644 --- a/gestioncof/templates/home.html +++ b/gestioncof/templates/home.html @@ -41,7 +41,7 @@

Divers