forked from DGNum/gestioCOF
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
|
@ -346,4 +346,4 @@ class CalendarForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CalendarSubscription
|
model = CalendarSubscription
|
||||||
exclude = ['user']
|
exclude = ['user', 'token']
|
||||||
|
|
|
@ -17,7 +17,9 @@ class Migration(migrations.Migration):
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='CalendarSubscription',
|
name='CalendarSubscription',
|
||||||
fields=[
|
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)),
|
('subscribe_to_events', models.BooleanField(default=True)),
|
||||||
('shows', models.ManyToManyField(to='bda.Spectacle')),
|
('shows', models.ManyToManyField(to='bda.Spectacle')),
|
||||||
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
|
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
|
||||||
|
@ -25,7 +27,8 @@ class Migration(migrations.Migration):
|
||||||
),
|
),
|
||||||
migrations.AlterModelOptions(
|
migrations.AlterModelOptions(
|
||||||
name='custommail',
|
name='custommail',
|
||||||
options={'verbose_name': 'Mail personnalisable', 'verbose_name_plural': 'Mails personnalisables'},
|
options={'verbose_name': 'Mail personnalisable',
|
||||||
|
'verbose_name_plural': 'Mails personnalisables'},
|
||||||
),
|
),
|
||||||
migrations.AlterModelOptions(
|
migrations.AlterModelOptions(
|
||||||
name='eventoptionchoice',
|
name='eventoptionchoice',
|
||||||
|
@ -34,11 +37,14 @@ class Migration(migrations.Migration):
|
||||||
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', blank=True),
|
field=models.DateTimeField(null=True, verbose_name=b'Date de fin',
|
||||||
|
blank=True),
|
||||||
),
|
),
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='event',
|
model_name='event',
|
||||||
name='start_date',
|
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):
|
class CalendarSubscription(models.Model):
|
||||||
|
token = models.UUIDField()
|
||||||
user = models.OneToOneField(User)
|
user = models.OneToOneField(User)
|
||||||
shows = models.ManyToManyField(Spectacle)
|
shows = models.ManyToManyField(Spectacle)
|
||||||
subscribe_to_events = models.BooleanField(default=True)
|
subscribe_to_events = models.BooleanField(default=True)
|
||||||
|
|
|
@ -10,8 +10,10 @@
|
||||||
<p class="error">{{ error }}</p>
|
<p class="error">{{ error }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if token %}
|
||||||
<p>Calendrier disponible à
|
<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">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
|
@ -42,5 +42,6 @@ events_patterns = [
|
||||||
|
|
||||||
calendar_patterns = [
|
calendar_patterns = [
|
||||||
url(r'^subscription$', 'gestioncof.views.calendar'),
|
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
|
# coding: utf-8
|
||||||
|
|
||||||
import unicodecsv
|
import unicodecsv
|
||||||
|
import uuid
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from icalendar import Calendar, Event as Vevent
|
from icalendar import Calendar, Event as Vevent
|
||||||
|
|
||||||
|
@ -633,23 +634,26 @@ def calendar(request):
|
||||||
form = CalendarForm(request.POST, instance=instance)
|
form = CalendarForm(request.POST, instance=instance)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
subscription = form.save(commit=False)
|
subscription = form.save(commit=False)
|
||||||
|
if instance is None:
|
||||||
subscription.user = request.user
|
subscription.user = request.user
|
||||||
|
subscription.token = uuid.uuid4()
|
||||||
subscription.save()
|
subscription.save()
|
||||||
form.save_m2m()
|
form.save_m2m()
|
||||||
return render(request, "calendar_subscription.html",
|
return render(request, "calendar_subscription.html",
|
||||||
{'form': form, 'success': True})
|
{'form': form,
|
||||||
|
'success': True,
|
||||||
|
'token': str(subscription.token)})
|
||||||
else:
|
else:
|
||||||
return render(request, "calendar_subscription.html",
|
return render(request, "calendar_subscription.html",
|
||||||
{'form': form, 'error': "Formulaire incorrect"})
|
{'form': form, 'error': "Formulaire incorrect"})
|
||||||
else:
|
else:
|
||||||
return render(request, "calendar_subscription.html",
|
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, token):
|
||||||
def calendar_ics(request):
|
subscription = get_object_or_404(CalendarSubscription, token=token)
|
||||||
subscription, _ = CalendarSubscription.objects.get_or_create(
|
|
||||||
user=request.user)
|
|
||||||
vcal = Calendar()
|
vcal = Calendar()
|
||||||
for show in subscription.shows.all():
|
for show in subscription.shows.all():
|
||||||
vevent = Vevent()
|
vevent = Vevent()
|
||||||
|
|
Loading…
Reference in a new issue