Corrections

- Typos dans les modèles
- Choix d'un `OneToOneField` dans `CalendarSubscription`
- Suppressions d'un `except` catch-all
- Amélioration de la vue calendar
This commit is contained in:
Martin Pépin 2016-07-15 02:49:56 +02:00
parent 8af49a1020
commit b5704c7f6d
4 changed files with 29 additions and 25 deletions

View file

@ -339,9 +339,9 @@ class CalendarForm(forms.ModelForm):
events = forms.BooleanField(initial=True, label="S'abonner aux événements") events = forms.BooleanField(initial=True, label="S'abonner aux événements")
shows = forms.ModelMultipleChoiceField( shows = forms.ModelMultipleChoiceField(
label="S'abonner aux spectacles suivants", label="S'abonner aux spectacles suivants",
queryset=Spectacle.objects.filter(tirage__active=True).all(), queryset=Spectacle.objects.filter(tirage__active=True),
widget=forms.CheckboxSelectMultiple, widget=forms.CheckboxSelectMultiple,
initial=Spectacle.objects.filter(tirage__active=True).all()) initial=Spectacle.objects.filter(tirage__active=True))
class Meta: class Meta:
model = CalendarSubscription model = CalendarSubscription

View file

@ -17,24 +17,28 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='CalendarSubscription', name='CalendarSubscription',
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
auto_created=True, primary_key=True)), ('subscribe_to_events', models.BooleanField(default=True)),
('events', models.BooleanField(default=True)),
('shows', models.ManyToManyField(to='bda.Spectacle')), ('shows', models.ManyToManyField(to='bda.Spectacle')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), ('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
], ],
), ),
migrations.AlterModelOptions(
name='custommail',
options={'verbose_name': 'Mail personnalisable', 'verbose_name_plural': 'Mails personnalisables'},
),
migrations.AlterModelOptions(
name='eventoptionchoice',
options={'verbose_name': 'Choix', 'verbose_name_plural': 'Choix'},
),
migrations.AlterField( migrations.AlterField(
model_name='event', model_name='event',
name='end_date', name='end_date',
field=models.DateTimeField(null=True, verbose_name=b'Date de fin', field=models.DateTimeField(null=True, verbose_name=b'Date de fin', blank=True),
blank=True),
), ),
migrations.AlterField( migrations.AlterField(
model_name='event', model_name='event',
name='start_date', name='start_date',
field=models.DateTimeField(null=True, field=models.DateTimeField(null=True, verbose_name=b'Date de d\xc3\xa9but', blank=True),
verbose_name=b'Date de d\xc3\xa9but',
blank=True),
), ),
] ]

View file

@ -96,7 +96,8 @@ class CustomMail(models.Model):
blank=True) blank=True)
class Meta: class Meta:
verbose_name = "Mails personnalisables" verbose_name = "Mail personnalisable"
verbose_name_plural = "Mails personnalisables"
def __unicode__(self): def __unicode__(self):
return u"%s: %s" % (self.shortname, self.title) return u"%s: %s" % (self.shortname, self.title)
@ -160,6 +161,7 @@ class EventOptionChoice(models.Model):
class Meta: class Meta:
verbose_name = "Choix" verbose_name = "Choix"
verbose_name_plural = "Choix"
def __unicode__(self): def __unicode__(self):
return unicode(self.value) return unicode(self.value)
@ -235,6 +237,6 @@ class Clipper(models.Model):
class CalendarSubscription(models.Model): class CalendarSubscription(models.Model):
user = models.ForeignKey(User) user = models.OneToOneField(User)
shows = models.ManyToManyField(Spectacle) shows = models.ManyToManyField(Spectacle)
events = models.BooleanField(default=True) subscribe_to_events = models.BooleanField(default=True)

View file

@ -4,8 +4,7 @@ import unicodecsv
from datetime import timedelta from datetime import timedelta
from icalendar import Calendar, Event as Vevent from icalendar import Calendar, Event as Vevent
from django.shortcuts import redirect, get_object_or_404, render, \ from django.shortcuts import redirect, get_object_or_404, render
HttpResponse
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import login as django_login_view from django.contrib.auth.views import login as django_login_view
@ -626,10 +625,13 @@ def liste_diffcof(request):
@cof_required @cof_required
def calendar(request): def calendar(request):
try:
instance = CalendarSubscription.objects.get(user=request.user)
except CalendarSubscription.DoesNotExist:
instance = None
if request.method == 'POST': if request.method == 'POST':
form = CalendarForm(request.POST) form = CalendarForm(request.POST, instance=instance)
if form.is_valid(): if form.is_valid():
CalendarSubscription.objects.filter(user=request.user).delete()
subscription = form.save(commit=False) subscription = form.save(commit=False)
subscription.user = request.user subscription.user = request.user
subscription.save() subscription.save()
@ -640,12 +642,8 @@ def calendar(request):
return render(request, "calendar_subscription.html", return render(request, "calendar_subscription.html",
{'form': form, 'error': "Formulaire incorect"}) {'form': form, 'error': "Formulaire incorect"})
else: else:
try: return render(request, "calendar_subscription.html",
subscription = CalendarSubscription.objects.get(user=request.user) {'form': CalendarForm(instance=instance)})
form = CalendarForm(instance=subscription)
except:
form = CalendarForm()
return render(request, "calendar_subscription.html", {'form': form})
@cof_required @cof_required
@ -660,7 +658,7 @@ def calendar_ics(request):
vevent.add('summary', show.title) vevent.add('summary', show.title)
vevent.add('location', show.location.name) vevent.add('location', show.location.name)
vcal.add_component(vevent) vcal.add_component(vevent)
if subscription.events: if subscription.subscribe_to_events:
for event in Event.objects.filter(old=False).all(): for event in Event.objects.filter(old=False).all():
vevent = Vevent() vevent = Vevent()
vevent.add('dtstart', event.start_date) vevent.add('dtstart', event.start_date)