Rend le calendrier plus dynamique
Plus besoin de s'authentifier pour accéder au calendrier : il suffit d'entrer la bonne url qui contient un token aléatoire propre à chaque utilisateur. Ce token ne change pas lorsqu'on modifie son inscription
This commit is contained in:
parent
301c374ee4
commit
7b32edbd38
6 changed files with 28 additions and 14 deletions
|
@ -346,4 +346,4 @@ class CalendarForm(forms.ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = CalendarSubscription
|
||||
exclude = ['user']
|
||||
exclude = ['user', 'token']
|
||||
|
|
|
@ -17,7 +17,9 @@ class Migration(migrations.Migration):
|
|||
migrations.CreateModel(
|
||||
name='CalendarSubscription',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False,
|
||||
auto_created=True, primary_key=True)),
|
||||
('token', models.UUIDField()),
|
||||
('subscribe_to_events', models.BooleanField(default=True)),
|
||||
('shows', models.ManyToManyField(to='bda.Spectacle')),
|
||||
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
|
||||
|
@ -25,7 +27,8 @@ class Migration(migrations.Migration):
|
|||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='custommail',
|
||||
options={'verbose_name': 'Mail personnalisable', 'verbose_name_plural': 'Mails personnalisables'},
|
||||
options={'verbose_name': 'Mail personnalisable',
|
||||
'verbose_name_plural': 'Mails personnalisables'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='eventoptionchoice',
|
||||
|
@ -34,11 +37,14 @@ class Migration(migrations.Migration):
|
|||
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),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -237,6 +237,7 @@ class Clipper(models.Model):
|
|||
|
||||
|
||||
class CalendarSubscription(models.Model):
|
||||
token = models.UUIDField()
|
||||
user = models.OneToOneField(User)
|
||||
shows = models.ManyToManyField(Spectacle)
|
||||
subscribe_to_events = models.BooleanField(default=True)
|
||||
|
|
|
@ -10,8 +10,10 @@
|
|||
<p class="error">{{ error }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% if token %}
|
||||
<p>Calendrier disponible à
|
||||
<a href="{% url 'gestioncof.views.calendar_ics' %}">cette adresse</a></p>
|
||||
<a href="{% url 'gestioncof.views.calendar_ics' token %}">cette adresse</a></p>
|
||||
{% endif %}
|
||||
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
|
|
|
@ -42,5 +42,6 @@ events_patterns = [
|
|||
|
||||
calendar_patterns = [
|
||||
url(r'^subscription$', 'gestioncof.views.calendar'),
|
||||
url(r'^calendar.ics$', 'gestioncof.views.calendar_ics')
|
||||
url(r'^(?P<token>[a-z0-9-]+)/calendar.ics$',
|
||||
'gestioncof.views.calendar_ics')
|
||||
]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# coding: utf-8
|
||||
|
||||
import unicodecsv
|
||||
import uuid
|
||||
from datetime import timedelta
|
||||
from icalendar import Calendar, Event as Vevent
|
||||
|
||||
|
@ -633,23 +634,26 @@ def calendar(request):
|
|||
form = CalendarForm(request.POST, instance=instance)
|
||||
if form.is_valid():
|
||||
subscription = form.save(commit=False)
|
||||
subscription.user = request.user
|
||||
if instance is None:
|
||||
subscription.user = request.user
|
||||
subscription.token = uuid.uuid4()
|
||||
subscription.save()
|
||||
form.save_m2m()
|
||||
return render(request, "calendar_subscription.html",
|
||||
{'form': form, 'success': True})
|
||||
{'form': form,
|
||||
'success': True,
|
||||
'token': str(subscription.token)})
|
||||
else:
|
||||
return render(request, "calendar_subscription.html",
|
||||
{'form': form, 'error': "Formulaire incorrect"})
|
||||
else:
|
||||
return render(request, "calendar_subscription.html",
|
||||
{'form': CalendarForm(instance=instance)})
|
||||
{'form': CalendarForm(instance=instance),
|
||||
'token': instance.token if instance else None})
|
||||
|
||||
|
||||
@cof_required
|
||||
def calendar_ics(request):
|
||||
subscription, _ = CalendarSubscription.objects.get_or_create(
|
||||
user=request.user)
|
||||
def calendar_ics(request, token):
|
||||
subscription = get_object_or_404(CalendarSubscription, token=token)
|
||||
vcal = Calendar()
|
||||
for show in subscription.shows.all():
|
||||
vevent = Vevent()
|
||||
|
|
Loading…
Reference in a new issue