Ajoute l'inscription à ses résultats du tirage

This commit is contained in:
Martin Pépin 2016-07-16 01:51:20 +02:00
parent 7b32edbd38
commit 0887cf824d
4 changed files with 24 additions and 14 deletions

View file

@ -336,14 +336,18 @@ class AdminEventForm(forms.Form):
class CalendarForm(forms.ModelForm):
subscribe_to_events = forms.BooleanField(initial=True,
label="S'abonner aux événements")
shows = forms.ModelMultipleChoiceField(
label="S'abonner aux spectacles suivants",
subscribe_to_events = forms.BooleanField(
initial=True,
label="Événements du COF.")
subscribe_to_my_shows = forms.BooleanField(
initial=True,
label="Les spectacles pour lesquels j'ai obtenu une place.")
other_shows = forms.ModelMultipleChoiceField(
label="Spectacles supplémentaires.",
queryset=Spectacle.objects.filter(tirage__active=True),
widget=forms.CheckboxSelectMultiple,
initial=Spectacle.objects.filter(tirage__active=True))
widget=forms.CheckboxSelectMultiple)
class Meta:
model = CalendarSubscription
exclude = ['user', 'token']
fields = ['subscribe_to_events', 'subscribe_to_my_shows',
'other_shows']

View file

@ -21,7 +21,8 @@ class Migration(migrations.Migration):
auto_created=True, primary_key=True)),
('token', models.UUIDField()),
('subscribe_to_events', models.BooleanField(default=True)),
('shows', models.ManyToManyField(to='bda.Spectacle')),
('subscribe_to_my_shows', models.BooleanField(default=True)),
('other_shows', models.ManyToManyField(to='bda.Spectacle')),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
],
),
@ -43,8 +44,7 @@ class Migration(migrations.Migration):
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),
),
]

View file

@ -239,5 +239,6 @@ class Clipper(models.Model):
class CalendarSubscription(models.Model):
token = models.UUIDField()
user = models.OneToOneField(User)
shows = models.ManyToManyField(Spectacle)
other_shows = models.ManyToManyField(Spectacle)
subscribe_to_events = models.BooleanField(default=True)
subscribe_to_my_shows = models.BooleanField(default=True)

View file

@ -24,7 +24,7 @@ from gestioncof.forms import UserProfileForm, EventStatusFilterForm, \
SurveyForm, SurveyStatusFilterForm, RegistrationUserForm, \
RegistrationProfileForm, AdminEventForm, EventForm, CalendarForm
from bda.models import Tirage
from bda.models import Tirage, Attribution
@login_required
@ -654,8 +654,13 @@ def calendar(request):
def calendar_ics(request, token):
subscription = get_object_or_404(CalendarSubscription, token=token)
shows = set(subscription.other_shows.all()) \
| {attr.show
for attr in Attribution.objects.filter(
participant__user=subscription.user,
participant__tirage__active=True)}
vcal = Calendar()
for show in subscription.shows.all():
for show in shows:
vevent = Vevent()
vevent.add('dtstart', show.date)
vevent.add('dtend', show.date + timedelta(seconds=7200))