forked from DGNum/gestioCOF
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:
parent
8af49a1020
commit
b5704c7f6d
4 changed files with 29 additions and 25 deletions
|
@ -339,9 +339,9 @@ 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(),
|
||||
queryset=Spectacle.objects.filter(tirage__active=True),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
initial=Spectacle.objects.filter(tirage__active=True).all())
|
||||
initial=Spectacle.objects.filter(tirage__active=True))
|
||||
|
||||
class Meta:
|
||||
model = CalendarSubscription
|
||||
|
|
|
@ -17,24 +17,28 @@ class Migration(migrations.Migration):
|
|||
migrations.CreateModel(
|
||||
name='CalendarSubscription',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False,
|
||||
auto_created=True, primary_key=True)),
|
||||
('events', models.BooleanField(default=True)),
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('subscribe_to_events', models.BooleanField(default=True)),
|
||||
('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(
|
||||
model_name='event',
|
||||
name='end_date',
|
||||
field=models.DateTimeField(null=True, verbose_name=b'Date de fin',
|
||||
blank=True),
|
||||
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),
|
||||
field=models.DateTimeField(null=True, verbose_name=b'Date de d\xc3\xa9but', blank=True),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -96,7 +96,8 @@ class CustomMail(models.Model):
|
|||
blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Mails personnalisables"
|
||||
verbose_name = "Mail personnalisable"
|
||||
verbose_name_plural = "Mails personnalisables"
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s: %s" % (self.shortname, self.title)
|
||||
|
@ -160,6 +161,7 @@ class EventOptionChoice(models.Model):
|
|||
|
||||
class Meta:
|
||||
verbose_name = "Choix"
|
||||
verbose_name_plural = "Choix"
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.value)
|
||||
|
@ -235,6 +237,6 @@ class Clipper(models.Model):
|
|||
|
||||
|
||||
class CalendarSubscription(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
user = models.OneToOneField(User)
|
||||
shows = models.ManyToManyField(Spectacle)
|
||||
events = models.BooleanField(default=True)
|
||||
subscribe_to_events = models.BooleanField(default=True)
|
||||
|
|
|
@ -4,8 +4,7 @@ import unicodecsv
|
|||
from datetime import timedelta
|
||||
from icalendar import Calendar, Event as Vevent
|
||||
|
||||
from django.shortcuts import redirect, get_object_or_404, render, \
|
||||
HttpResponse
|
||||
from django.shortcuts import redirect, get_object_or_404, render
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.views import login as django_login_view
|
||||
|
@ -626,10 +625,13 @@ def liste_diffcof(request):
|
|||
|
||||
@cof_required
|
||||
def calendar(request):
|
||||
try:
|
||||
instance = CalendarSubscription.objects.get(user=request.user)
|
||||
except CalendarSubscription.DoesNotExist:
|
||||
instance = None
|
||||
if request.method == 'POST':
|
||||
form = CalendarForm(request.POST)
|
||||
form = CalendarForm(request.POST, instance=instance)
|
||||
if form.is_valid():
|
||||
CalendarSubscription.objects.filter(user=request.user).delete()
|
||||
subscription = form.save(commit=False)
|
||||
subscription.user = request.user
|
||||
subscription.save()
|
||||
|
@ -640,12 +642,8 @@ def calendar(request):
|
|||
return render(request, "calendar_subscription.html",
|
||||
{'form': form, 'error': "Formulaire incorect"})
|
||||
else:
|
||||
try:
|
||||
subscription = CalendarSubscription.objects.get(user=request.user)
|
||||
form = CalendarForm(instance=subscription)
|
||||
except:
|
||||
form = CalendarForm()
|
||||
return render(request, "calendar_subscription.html", {'form': form})
|
||||
return render(request, "calendar_subscription.html",
|
||||
{'form': CalendarForm(instance=instance)})
|
||||
|
||||
|
||||
@cof_required
|
||||
|
@ -660,7 +658,7 @@ def calendar_ics(request):
|
|||
vevent.add('summary', show.title)
|
||||
vevent.add('location', show.location.name)
|
||||
vcal.add_component(vevent)
|
||||
if subscription.events:
|
||||
if subscription.subscribe_to_events:
|
||||
for event in Event.objects.filter(old=False).all():
|
||||
vevent = Vevent()
|
||||
vevent.add('dtstart', event.start_date)
|
||||
|
|
Loading…
Reference in a new issue