2019-10-05 17:37:08 +02:00
|
|
|
import csv
|
2016-07-15 23:31:26 +02:00
|
|
|
import uuid
|
2016-07-15 01:06:33 +02:00
|
|
|
from datetime import timedelta
|
2019-02-04 22:09:57 +01:00
|
|
|
from smtplib import SMTPRecipientsRefused
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
from custommail.shortcuts import send_custom_mail
|
|
|
|
from django.contrib import messages
|
2012-06-27 23:28:35 +02:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2019-10-06 00:28:32 +02:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2018-10-06 12:35:49 +02:00
|
|
|
from django.contrib.auth.models import User
|
2017-05-30 20:44:30 +02:00
|
|
|
from django.contrib.auth.views import (
|
2019-03-25 23:05:47 +01:00
|
|
|
LoginView as DjangoLoginView,
|
|
|
|
LogoutView as DjangoLogoutView,
|
2018-01-22 21:41:02 +01:00
|
|
|
redirect_to_login,
|
2017-05-30 20:44:30 +02:00
|
|
|
)
|
2016-11-05 18:04:54 +01:00
|
|
|
from django.contrib.sites.models import Site
|
2018-10-06 12:35:49 +02:00
|
|
|
from django.http import Http404, HttpResponse, HttpResponseForbidden
|
|
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
2019-03-19 10:18:56 +01:00
|
|
|
from django.urls import reverse_lazy
|
2016-08-03 17:54:12 +02:00
|
|
|
from django.utils import timezone
|
2017-05-30 20:44:30 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2019-10-06 00:28:32 +02:00
|
|
|
from django.views.generic import FormView, TemplateView
|
2019-03-25 23:05:47 +01:00
|
|
|
from django_cas_ng.views import LogoutView as CasLogoutView
|
2018-10-06 12:35:49 +02:00
|
|
|
from icalendar import Calendar, Event as Vevent
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
from bda.models import Spectacle, Tirage
|
2016-07-15 01:06:33 +02:00
|
|
|
from gestioncof.decorators import buro_required, cof_required
|
2017-05-26 00:58:59 +02:00
|
|
|
from gestioncof.forms import (
|
2018-10-06 12:35:49 +02:00
|
|
|
CalendarForm,
|
|
|
|
ClubsForm,
|
|
|
|
EventForm,
|
|
|
|
EventFormset,
|
|
|
|
EventStatusFilterForm,
|
2019-03-25 23:05:47 +01:00
|
|
|
ExteAuthenticationForm,
|
2018-10-06 12:35:49 +02:00
|
|
|
GestioncofConfigForm,
|
2019-10-06 00:01:41 +02:00
|
|
|
PhoneForm,
|
2018-10-06 12:35:49 +02:00
|
|
|
ProfileForm,
|
|
|
|
RegistrationPassUserForm,
|
|
|
|
RegistrationProfileForm,
|
|
|
|
RegistrationUserForm,
|
|
|
|
SurveyForm,
|
|
|
|
SurveyStatusFilterForm,
|
|
|
|
UserForm,
|
2017-05-26 00:58:59 +02:00
|
|
|
)
|
2018-10-06 12:35:49 +02:00
|
|
|
from gestioncof.models import (
|
|
|
|
CalendarSubscription,
|
|
|
|
Club,
|
|
|
|
CofProfile,
|
|
|
|
Event,
|
|
|
|
EventCommentField,
|
|
|
|
EventCommentValue,
|
|
|
|
EventOption,
|
|
|
|
EventOptionChoice,
|
|
|
|
EventRegistration,
|
|
|
|
Survey,
|
|
|
|
SurveyAnswer,
|
|
|
|
SurveyQuestion,
|
|
|
|
SurveyQuestionAnswer,
|
|
|
|
)
|
|
|
|
from utils.views.autocomplete import Select2QuerySetView
|
2016-06-06 11:19:27 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2019-10-06 00:28:32 +02:00
|
|
|
class HomeView(LoginRequiredMixin, TemplateView):
|
|
|
|
template_name = "gestioncof/home.html"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
context["surveys"] = Survey.objects.filter(old=False)
|
|
|
|
context["events"] = Event.objects.filter(old=False)
|
|
|
|
context["open_surveys"] = Survey.objects.filter(survey_open=True, old=False)
|
|
|
|
context["active_tirages"] = Tirage.objects.filter(active=True)
|
|
|
|
context["open_tirages"] = Tirage.objects.filter(
|
2018-10-06 12:35:49 +02:00
|
|
|
active=True, ouverture__lte=timezone.now()
|
2019-10-06 00:28:32 +02:00
|
|
|
)
|
|
|
|
context["now"] = timezone.now()
|
|
|
|
return context
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
def login(request):
|
2017-11-19 18:41:39 +01:00
|
|
|
if request.user.is_authenticated:
|
|
|
|
return redirect("home")
|
2016-07-28 01:31:50 +02:00
|
|
|
context = {}
|
2018-10-06 12:35:49 +02:00
|
|
|
if request.method == "GET" and "next" in request.GET:
|
|
|
|
context["next"] = request.GET["next"]
|
2016-07-28 01:31:50 +02:00
|
|
|
return render(request, "login_switch.html", context)
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2019-03-25 23:05:47 +01:00
|
|
|
class LoginExtView(DjangoLoginView):
|
|
|
|
template_name = "login.html"
|
|
|
|
form_class = ExteAuthenticationForm
|
|
|
|
|
|
|
|
def form_invalid(self, form):
|
|
|
|
# forms.non_field_errors() returns strings for some reason
|
|
|
|
non_field_errors = form.errors["__all__"].as_data()
|
2019-03-25 23:30:55 +01:00
|
|
|
for e in non_field_errors:
|
|
|
|
if e.code in ["has_clipper", "no_password"]:
|
|
|
|
return render(self.request, "login_error.html", {"error_code": e.code})
|
2019-03-25 23:05:47 +01:00
|
|
|
return super().form_invalid(form)
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
|
|
|
|
@login_required
|
2017-05-30 20:44:30 +02:00
|
|
|
def logout(request, next_page=None):
|
|
|
|
if next_page is None:
|
2018-10-06 12:35:49 +02:00
|
|
|
next_page = request.GET.get("next", None)
|
2017-05-30 20:44:30 +02:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
profile = getattr(request.user, "profile", None)
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
if profile and profile.login_clipper:
|
2018-10-06 12:35:49 +02:00
|
|
|
msg = _("Déconnexion de GestioCOF et CAS réussie. À bientôt {}.")
|
2019-03-25 23:05:47 +01:00
|
|
|
logout_view = CasLogoutView.as_view()
|
2012-06-27 23:28:35 +02:00
|
|
|
else:
|
2018-10-06 12:35:49 +02:00
|
|
|
msg = _("Déconnexion de GestioCOF réussie. À bientôt {}.")
|
2019-03-25 23:05:47 +01:00
|
|
|
logout_view = DjangoLogoutView.as_view(
|
|
|
|
next_page=next_page, template_name="logout.html"
|
|
|
|
)
|
2017-05-30 20:44:30 +02:00
|
|
|
|
|
|
|
messages.success(request, msg.format(request.user.get_short_name()))
|
2019-03-25 23:05:47 +01:00
|
|
|
return logout_view(request)
|
2012-06-27 23:28:35 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-06-27 23:28:35 +02:00
|
|
|
@login_required
|
|
|
|
def survey(request, survey_id):
|
2017-04-09 17:37:15 +02:00
|
|
|
survey = get_object_or_404(
|
2018-10-06 12:35:49 +02:00
|
|
|
Survey.objects.prefetch_related("questions", "questions__answers"), id=survey_id
|
2017-04-09 17:37:15 +02:00
|
|
|
)
|
2016-08-24 23:57:55 +02:00
|
|
|
if not survey.survey_open or survey.old:
|
2012-06-27 23:28:35 +02:00
|
|
|
raise Http404
|
|
|
|
success = False
|
2012-07-11 17:39:20 +02:00
|
|
|
deleted = False
|
2012-06-27 23:28:35 +02:00
|
|
|
if request.method == "POST":
|
2016-07-09 21:19:37 +02:00
|
|
|
form = SurveyForm(request.POST, survey=survey)
|
2018-10-06 12:35:49 +02:00
|
|
|
if request.POST.get("delete"):
|
2012-06-27 23:28:35 +02:00
|
|
|
try:
|
2018-10-06 12:35:49 +02:00
|
|
|
current_answer = SurveyAnswer.objects.get(
|
|
|
|
user=request.user, survey=survey
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
current_answer.delete()
|
|
|
|
current_answer = None
|
2012-06-27 23:28:35 +02:00
|
|
|
except SurveyAnswer.DoesNotExist:
|
2012-07-11 17:39:20 +02:00
|
|
|
current_answer = None
|
2016-07-09 21:19:37 +02:00
|
|
|
form = SurveyForm(survey=survey)
|
2012-06-27 23:28:35 +02:00
|
|
|
success = True
|
2012-07-11 17:39:20 +02:00
|
|
|
deleted = True
|
|
|
|
else:
|
|
|
|
if form.is_valid():
|
|
|
|
all_answers = []
|
|
|
|
for question_id, answers_ids in form.answers():
|
2018-10-06 12:35:49 +02:00
|
|
|
question = get_object_or_404(
|
|
|
|
SurveyQuestion, id=question_id, survey=survey
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
if type(answers_ids) != list:
|
|
|
|
answers_ids = [answers_ids]
|
|
|
|
if not question.multi_answers and len(answers_ids) > 1:
|
|
|
|
raise Http404
|
|
|
|
for answer_id in answers_ids:
|
|
|
|
if not answer_id:
|
|
|
|
continue
|
|
|
|
answer_id = int(answer_id)
|
|
|
|
answer = SurveyQuestionAnswer.objects.get(
|
2018-10-06 12:35:49 +02:00
|
|
|
id=answer_id, survey_question=question
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
all_answers.append(answer)
|
|
|
|
try:
|
2016-07-09 22:31:56 +02:00
|
|
|
current_answer = SurveyAnswer.objects.get(
|
2018-10-06 12:35:49 +02:00
|
|
|
user=request.user, survey=survey
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
except SurveyAnswer.DoesNotExist:
|
2018-10-06 12:35:49 +02:00
|
|
|
current_answer = SurveyAnswer(user=request.user, survey=survey)
|
2012-07-11 17:39:20 +02:00
|
|
|
current_answer.save()
|
2019-04-17 18:21:59 +02:00
|
|
|
current_answer.answers.set(all_answers)
|
2012-07-11 17:39:20 +02:00
|
|
|
current_answer.save()
|
|
|
|
success = True
|
2012-06-27 23:28:35 +02:00
|
|
|
else:
|
|
|
|
try:
|
2018-10-06 12:35:49 +02:00
|
|
|
current_answer = SurveyAnswer.objects.get(user=request.user, survey=survey)
|
|
|
|
form = SurveyForm(survey=survey, current_answers=current_answer.answers)
|
2012-06-27 23:28:35 +02:00
|
|
|
except SurveyAnswer.DoesNotExist:
|
2012-07-11 17:39:20 +02:00
|
|
|
current_answer = None
|
2016-07-09 21:19:37 +02:00
|
|
|
form = SurveyForm(survey=survey)
|
2017-01-29 16:24:07 +01:00
|
|
|
# Messages
|
|
|
|
if success:
|
|
|
|
if deleted:
|
2018-10-06 12:35:49 +02:00
|
|
|
messages.success(request, "Votre réponse a bien été supprimée")
|
2017-01-29 16:24:07 +01:00
|
|
|
else:
|
2018-10-06 12:35:49 +02:00
|
|
|
messages.success(
|
|
|
|
request,
|
|
|
|
"Votre réponse a bien été enregistrée ! Vous "
|
|
|
|
"pouvez cependant la modifier jusqu'à la fin "
|
|
|
|
"du sondage.",
|
|
|
|
)
|
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"gestioncof/survey.html",
|
|
|
|
{"survey": survey, "form": form, "current_answer": current_answer},
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
def get_event_form_choices(event, form):
|
|
|
|
all_choices = []
|
|
|
|
for option_id, choices_ids in form.choices():
|
2018-10-06 12:35:49 +02:00
|
|
|
option = get_object_or_404(EventOption, id=option_id, event=event)
|
2013-09-05 22:20:52 +02:00
|
|
|
if type(choices_ids) != list:
|
|
|
|
choices_ids = [choices_ids]
|
|
|
|
if not option.multi_choices and len(choices_ids) > 1:
|
|
|
|
raise Http404
|
|
|
|
for choice_id in choices_ids:
|
|
|
|
if not choice_id:
|
|
|
|
continue
|
|
|
|
choice_id = int(choice_id)
|
2018-10-06 12:35:49 +02:00
|
|
|
choice = EventOptionChoice.objects.get(id=choice_id, event_option=option)
|
2013-09-05 22:20:52 +02:00
|
|
|
all_choices.append(choice)
|
|
|
|
return all_choices
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
def update_event_form_comments(event, form, registration):
|
|
|
|
for commentfield_id, value in form.comments():
|
2018-10-06 12:35:49 +02:00
|
|
|
field = get_object_or_404(EventCommentField, id=commentfield_id, event=event)
|
2014-08-19 12:54:22 +02:00
|
|
|
if value == field.default:
|
|
|
|
continue
|
2016-07-09 22:31:56 +02:00
|
|
|
(storage, _) = EventCommentValue.objects.get_or_create(
|
2018-10-06 12:35:49 +02:00
|
|
|
commentfield=field, registration=registration
|
|
|
|
)
|
2014-08-19 12:54:22 +02:00
|
|
|
storage.content = value
|
|
|
|
storage.save()
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2012-07-11 17:39:20 +02:00
|
|
|
@login_required
|
|
|
|
def event(request, event_id):
|
2016-07-09 21:19:37 +02:00
|
|
|
event = get_object_or_404(Event, id=event_id)
|
2016-08-06 15:34:01 +02:00
|
|
|
if (not event.registration_open) or event.old:
|
2012-07-11 17:39:20 +02:00
|
|
|
raise Http404
|
|
|
|
success = False
|
|
|
|
if request.method == "POST":
|
2016-07-09 21:19:37 +02:00
|
|
|
form = EventForm(request.POST, event=event)
|
2012-07-11 17:39:20 +02:00
|
|
|
if form.is_valid():
|
2013-09-05 22:20:52 +02:00
|
|
|
all_choices = get_event_form_choices(event, form)
|
2018-10-06 12:35:49 +02:00
|
|
|
(current_registration, _) = EventRegistration.objects.get_or_create(
|
|
|
|
user=request.user, event=event
|
|
|
|
)
|
2019-04-17 18:21:59 +02:00
|
|
|
current_registration.options.set(all_choices)
|
2012-07-11 17:39:20 +02:00
|
|
|
current_registration.save()
|
|
|
|
success = True
|
|
|
|
else:
|
|
|
|
try:
|
2018-10-06 12:35:49 +02:00
|
|
|
current_registration = EventRegistration.objects.get(
|
|
|
|
user=request.user, event=event
|
|
|
|
)
|
|
|
|
form = EventForm(event=event, current_choices=current_registration.options)
|
2012-07-11 17:39:20 +02:00
|
|
|
except EventRegistration.DoesNotExist:
|
2016-07-09 21:19:37 +02:00
|
|
|
form = EventForm(event=event)
|
2017-01-30 13:12:01 +01:00
|
|
|
# Messages
|
|
|
|
if success:
|
2018-10-06 12:35:49 +02:00
|
|
|
messages.success(
|
|
|
|
request,
|
|
|
|
"Votre inscription a bien été enregistrée ! "
|
|
|
|
"Vous pouvez cependant la modifier jusqu'à "
|
|
|
|
"la fin des inscriptions.",
|
|
|
|
)
|
|
|
|
return render(request, "gestioncof/event.html", {"event": event, "form": form})
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2012-07-11 17:39:20 +02:00
|
|
|
|
|
|
|
def clean_post_for_status(initial):
|
2013-09-05 22:20:52 +02:00
|
|
|
d = initial.copy()
|
2012-07-11 17:39:20 +02:00
|
|
|
for k, v in d.items():
|
|
|
|
if k.startswith("id_"):
|
|
|
|
del d[k]
|
2013-09-05 22:20:52 +02:00
|
|
|
d[k[3:]] = v
|
2012-07-11 17:39:20 +02:00
|
|
|
return d
|
|
|
|
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
@buro_required
|
2012-07-11 17:39:20 +02:00
|
|
|
def event_status(request, event_id):
|
2016-07-09 21:19:37 +02:00
|
|
|
event = get_object_or_404(Event, id=event_id)
|
|
|
|
registrations_query = EventRegistration.objects.filter(event=event)
|
2012-07-11 17:39:20 +02:00
|
|
|
post_data = clean_post_for_status(request.POST)
|
2016-07-09 21:19:37 +02:00
|
|
|
form = EventStatusFilterForm(post_data or None, event=event)
|
2012-07-11 17:39:20 +02:00
|
|
|
if form.is_valid():
|
|
|
|
for option_id, choice_id, value in form.filters():
|
2013-09-05 22:20:52 +02:00
|
|
|
if option_id == "has_paid":
|
|
|
|
if value == "yes":
|
2016-07-09 21:19:37 +02:00
|
|
|
registrations_query = registrations_query.filter(paid=True)
|
2013-09-05 22:20:52 +02:00
|
|
|
elif value == "no":
|
2018-10-06 12:35:49 +02:00
|
|
|
registrations_query = registrations_query.filter(paid=False)
|
2013-09-05 22:20:52 +02:00
|
|
|
continue
|
2018-10-06 12:35:49 +02:00
|
|
|
choice = get_object_or_404(
|
|
|
|
EventOptionChoice, id=choice_id, event_option__id=option_id
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
if value == "none":
|
|
|
|
continue
|
|
|
|
if value == "yes":
|
2016-07-09 22:31:56 +02:00
|
|
|
registrations_query = registrations_query.filter(
|
2018-10-06 12:35:49 +02:00
|
|
|
options__id__exact=choice.id
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
elif value == "no":
|
2016-07-09 22:31:56 +02:00
|
|
|
registrations_query = registrations_query.exclude(
|
2018-10-06 12:35:49 +02:00
|
|
|
options__id__exact=choice.id
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
user_choices = registrations_query.prefetch_related("user").all()
|
2016-07-09 21:19:37 +02:00
|
|
|
options = EventOption.objects.filter(event=event).all()
|
2012-07-11 17:39:20 +02:00
|
|
|
choices_count = {}
|
|
|
|
for option in options:
|
|
|
|
for choice in option.choices.all():
|
|
|
|
choices_count[choice.id] = 0
|
|
|
|
for user_choice in user_choices:
|
|
|
|
for choice in user_choice.options.all():
|
|
|
|
choices_count[choice.id] += 1
|
2018-10-06 12:35:49 +02:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"event_status.html",
|
|
|
|
{
|
|
|
|
"event": event,
|
|
|
|
"user_choices": user_choices,
|
|
|
|
"options": options,
|
|
|
|
"choices_count": choices_count,
|
|
|
|
"form": form,
|
|
|
|
},
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
@buro_required
|
2012-07-11 17:39:20 +02:00
|
|
|
def survey_status(request, survey_id):
|
2016-07-09 21:19:37 +02:00
|
|
|
survey = get_object_or_404(Survey, id=survey_id)
|
|
|
|
answers_query = SurveyAnswer.objects.filter(survey=survey)
|
2012-07-11 17:39:20 +02:00
|
|
|
post_data = clean_post_for_status(request.POST)
|
2016-07-09 21:19:37 +02:00
|
|
|
form = SurveyStatusFilterForm(post_data or None, survey=survey)
|
2012-07-11 17:39:20 +02:00
|
|
|
if form.is_valid():
|
|
|
|
for question_id, answer_id, value in form.filters():
|
2018-10-06 12:35:49 +02:00
|
|
|
answer = get_object_or_404(
|
|
|
|
SurveyQuestionAnswer, id=answer_id, survey_question__id=question_id
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
if value == "none":
|
|
|
|
continue
|
|
|
|
if value == "yes":
|
2018-10-06 12:35:49 +02:00
|
|
|
answers_query = answers_query.filter(answers__id__exact=answer.id)
|
2012-07-11 17:39:20 +02:00
|
|
|
elif value == "no":
|
2018-10-06 12:35:49 +02:00
|
|
|
answers_query = answers_query.exclude(answers__id__exact=answer.id)
|
2012-07-11 17:39:20 +02:00
|
|
|
user_answers = answers_query.prefetch_related("user").all()
|
2016-07-09 21:19:37 +02:00
|
|
|
questions = SurveyQuestion.objects.filter(survey=survey).all()
|
2012-07-11 17:39:20 +02:00
|
|
|
answers_count = {}
|
|
|
|
for question in questions:
|
|
|
|
for answer in question.answers.all():
|
|
|
|
answers_count[answer.id] = 0
|
|
|
|
for user_answer in user_answers:
|
|
|
|
for answer in user_answer.answers.all():
|
|
|
|
answers_count[answer.id] += 1
|
2018-10-06 12:35:49 +02:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"survey_status.html",
|
|
|
|
{
|
|
|
|
"survey": survey,
|
|
|
|
"user_answers": user_answers,
|
|
|
|
"questions": questions,
|
|
|
|
"answers_count": answers_count,
|
|
|
|
"form": form,
|
|
|
|
},
|
|
|
|
)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2019-10-06 00:01:41 +02:00
|
|
|
@login_required
|
2012-07-11 17:39:20 +02:00
|
|
|
def profile(request):
|
2018-08-05 18:11:10 +02:00
|
|
|
user = request.user
|
|
|
|
data = request.POST if request.method == "POST" else None
|
|
|
|
user_form = UserForm(data=data, instance=user, prefix="u")
|
2019-10-06 00:01:41 +02:00
|
|
|
profile_form_klass = ProfileForm if user.profile.is_cof else PhoneForm
|
|
|
|
profile_form = profile_form_klass(data=data, instance=user.profile, prefix="p")
|
2012-07-11 17:39:20 +02:00
|
|
|
if request.method == "POST":
|
2018-08-05 18:11:10 +02:00
|
|
|
if user_form.is_valid() and profile_form.is_valid():
|
|
|
|
user_form.save()
|
|
|
|
profile_form.save()
|
2018-10-06 12:35:49 +02:00
|
|
|
messages.success(request, _("Votre profil a été mis à jour avec succès !"))
|
2018-08-05 18:11:10 +02:00
|
|
|
context = {"user_form": user_form, "profile_form": profile_form}
|
|
|
|
return render(request, "gestioncof/profile.html", context)
|
2012-07-11 17:39:20 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
def registration_set_ro_fields(user_form, profile_form):
|
2018-10-06 12:35:49 +02:00
|
|
|
user_form.fields["username"].widget.attrs["readonly"] = True
|
|
|
|
profile_form.fields["login_clipper"].widget.attrs["readonly"] = True
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
@buro_required
|
2018-10-06 12:35:49 +02:00
|
|
|
def registration_form2(request, login_clipper=None, username=None, fullname=None):
|
2016-07-09 21:19:37 +02:00
|
|
|
events = Event.objects.filter(old=False).all()
|
2016-08-13 02:56:42 +02:00
|
|
|
member = None
|
2013-09-05 22:20:52 +02:00
|
|
|
if login_clipper:
|
2016-07-09 21:19:37 +02:00
|
|
|
try: # check if the given user is already registered
|
2016-08-13 02:56:42 +02:00
|
|
|
member = User.objects.get(username=login_clipper)
|
2013-09-05 22:20:52 +02:00
|
|
|
username = member.username
|
|
|
|
login_clipper = None
|
|
|
|
except User.DoesNotExist:
|
|
|
|
# new user, but prefill
|
2016-08-13 02:56:42 +02:00
|
|
|
# user
|
2018-10-06 12:35:49 +02:00
|
|
|
user_form = RegistrationUserForm(
|
|
|
|
initial={
|
|
|
|
"username": login_clipper,
|
|
|
|
"email": "%s@clipper.ens.fr" % login_clipper,
|
|
|
|
}
|
|
|
|
)
|
2016-12-25 02:02:22 +01:00
|
|
|
if fullname:
|
|
|
|
bits = fullname.split(" ")
|
2018-10-06 12:35:49 +02:00
|
|
|
user_form.fields["first_name"].initial = bits[0]
|
2013-09-05 22:20:52 +02:00
|
|
|
if len(bits) > 1:
|
2018-10-06 12:35:49 +02:00
|
|
|
user_form.fields["last_name"].initial = " ".join(bits[1:])
|
2016-08-13 02:56:42 +02:00
|
|
|
# profile
|
2018-10-06 12:35:49 +02:00
|
|
|
profile_form = RegistrationProfileForm(
|
|
|
|
initial={"login_clipper": login_clipper}
|
|
|
|
)
|
2013-09-05 22:20:52 +02:00
|
|
|
registration_set_ro_fields(user_form, profile_form)
|
2016-08-23 17:40:24 +02:00
|
|
|
# events & clubs
|
2018-10-06 12:35:49 +02:00
|
|
|
event_formset = EventFormset(events=events, prefix="events")
|
2016-09-24 18:44:35 +02:00
|
|
|
clubs_form = ClubsForm()
|
2013-09-05 22:20:52 +02:00
|
|
|
if username:
|
2016-07-09 21:19:37 +02:00
|
|
|
member = get_object_or_404(User, username=username)
|
|
|
|
(profile, _) = CofProfile.objects.get_or_create(user=member)
|
2013-09-05 22:20:52 +02:00
|
|
|
# already existing, prefill
|
2016-07-09 21:19:37 +02:00
|
|
|
user_form = RegistrationUserForm(instance=member)
|
|
|
|
profile_form = RegistrationProfileForm(instance=profile)
|
2013-09-05 22:20:52 +02:00
|
|
|
registration_set_ro_fields(user_form, profile_form)
|
2016-08-13 02:56:42 +02:00
|
|
|
# events
|
2016-08-07 18:47:59 +02:00
|
|
|
current_registrations = []
|
2013-09-05 22:20:52 +02:00
|
|
|
for event in events:
|
|
|
|
try:
|
2016-08-07 18:47:59 +02:00
|
|
|
current_registrations.append(
|
2018-10-06 12:35:49 +02:00
|
|
|
EventRegistration.objects.get(user=member, event=event)
|
|
|
|
)
|
2013-09-05 22:20:52 +02:00
|
|
|
except EventRegistration.DoesNotExist:
|
2016-08-07 18:47:59 +02:00
|
|
|
current_registrations.append(None)
|
|
|
|
event_formset = EventFormset(
|
2018-10-06 12:35:49 +02:00
|
|
|
events=events, prefix="events", current_registrations=current_registrations
|
|
|
|
)
|
2016-08-23 17:40:24 +02:00
|
|
|
# Clubs
|
2018-10-06 12:35:49 +02:00
|
|
|
clubs_form = ClubsForm(initial={"clubs": member.clubs.all()})
|
2013-09-05 22:20:52 +02:00
|
|
|
elif not login_clipper:
|
|
|
|
# new user
|
2016-08-17 15:34:01 +02:00
|
|
|
user_form = RegistrationPassUserForm()
|
2013-09-05 22:20:52 +02:00
|
|
|
profile_form = RegistrationProfileForm()
|
2018-10-06 12:35:49 +02:00
|
|
|
event_formset = EventFormset(events=events, prefix="events")
|
2016-08-23 17:40:24 +02:00
|
|
|
clubs_form = ClubsForm()
|
2018-10-06 12:35:49 +02:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"gestioncof/registration_form.html",
|
|
|
|
{
|
|
|
|
"member": member,
|
|
|
|
"login_clipper": login_clipper,
|
|
|
|
"user_form": user_form,
|
|
|
|
"profile_form": profile_form,
|
|
|
|
"event_formset": event_formset,
|
|
|
|
"clubs_form": clubs_form,
|
|
|
|
},
|
|
|
|
)
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2019-02-04 22:09:57 +01:00
|
|
|
def notify_new_member(request, member: User):
|
|
|
|
if not member.email:
|
|
|
|
messages.warning(
|
|
|
|
request,
|
|
|
|
"GestioCOF n'a pas d'adresse mail pour {}, ".format(member)
|
|
|
|
+ "aucun email de bienvenue n'a été envoyé",
|
|
|
|
)
|
2019-06-17 21:21:30 +02:00
|
|
|
return
|
|
|
|
|
2019-02-04 22:09:57 +01:00
|
|
|
# Try to send a welcome email and report SMTP errors
|
|
|
|
try:
|
|
|
|
send_custom_mail(
|
|
|
|
"welcome", "cof@ens.fr", [member.email], context={"member": member}
|
|
|
|
)
|
|
|
|
except SMTPRecipientsRefused:
|
|
|
|
messages.error(
|
|
|
|
request,
|
2019-02-04 22:20:59 +01:00
|
|
|
"Error lors de l'envoi de l'email de bienvenue à {} ({})".format(
|
|
|
|
member, member.email
|
|
|
|
),
|
2019-02-04 22:09:57 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
@buro_required
|
2012-07-11 17:39:20 +02:00
|
|
|
def registration(request):
|
2013-09-05 22:20:52 +02:00
|
|
|
if request.POST:
|
|
|
|
request_dict = request.POST.copy()
|
2016-08-17 15:34:01 +02:00
|
|
|
member = None
|
|
|
|
login_clipper = None
|
2016-08-14 12:10:50 +02:00
|
|
|
|
|
|
|
# -----
|
|
|
|
# Remplissage des formulaires
|
|
|
|
# -----
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
if "password1" in request_dict or "password2" in request_dict:
|
2016-08-17 15:34:01 +02:00
|
|
|
user_form = RegistrationPassUserForm(request_dict)
|
|
|
|
else:
|
2016-08-24 15:38:04 +02:00
|
|
|
user_form = RegistrationUserForm(request_dict)
|
2016-08-17 15:34:01 +02:00
|
|
|
profile_form = RegistrationProfileForm(request_dict)
|
2016-08-23 17:40:24 +02:00
|
|
|
clubs_form = ClubsForm(request_dict)
|
2016-08-17 15:34:01 +02:00
|
|
|
events = Event.objects.filter(old=False).all()
|
2018-10-06 12:35:49 +02:00
|
|
|
event_formset = EventFormset(events=events, data=request_dict, prefix="events")
|
2013-09-05 22:20:52 +02:00
|
|
|
if "user_exists" in request_dict and request_dict["user_exists"]:
|
|
|
|
username = request_dict["username"]
|
|
|
|
try:
|
2016-08-14 12:10:50 +02:00
|
|
|
member = User.objects.get(username=username)
|
2016-07-09 21:19:37 +02:00
|
|
|
user_form = RegistrationUserForm(request_dict, instance=member)
|
2016-12-25 02:02:22 +01:00
|
|
|
if member.profile.login_clipper:
|
|
|
|
login_clipper = member.profile.login_clipper
|
|
|
|
except User.DoesNotExist:
|
2017-09-04 13:25:09 +02:00
|
|
|
pass
|
2016-08-24 16:26:43 +02:00
|
|
|
else:
|
2017-09-04 13:25:09 +02:00
|
|
|
pass
|
2016-08-14 12:10:50 +02:00
|
|
|
|
|
|
|
# -----
|
|
|
|
# Validation des formulaires
|
|
|
|
# -----
|
|
|
|
|
|
|
|
if user_form.is_valid():
|
2013-09-05 22:20:52 +02:00
|
|
|
member = user_form.save()
|
2016-08-14 12:10:50 +02:00
|
|
|
profile, _ = CofProfile.objects.get_or_create(user=member)
|
2014-08-19 12:54:22 +02:00
|
|
|
was_cof = profile.is_cof
|
2016-08-14 12:10:50 +02:00
|
|
|
# Maintenant on remplit le formulaire de profil
|
2018-10-06 12:35:49 +02:00
|
|
|
profile_form = RegistrationProfileForm(request_dict, instance=profile)
|
|
|
|
if (
|
|
|
|
profile_form.is_valid()
|
|
|
|
and event_formset.is_valid()
|
|
|
|
and clubs_form.is_valid()
|
|
|
|
):
|
2016-08-23 17:40:24 +02:00
|
|
|
# Enregistrement du profil
|
2016-08-14 12:10:50 +02:00
|
|
|
profile = profile_form.save()
|
|
|
|
if profile.is_cof and not was_cof:
|
2019-02-04 22:09:57 +01:00
|
|
|
notify_new_member(request, member)
|
2016-08-23 17:40:24 +02:00
|
|
|
# Enregistrement des inscriptions aux événements
|
2016-08-14 12:10:50 +02:00
|
|
|
for form in event_formset:
|
2018-10-06 12:35:49 +02:00
|
|
|
if "status" not in form.cleaned_data:
|
|
|
|
form.cleaned_data["status"] = "no"
|
|
|
|
if form.cleaned_data["status"] == "no":
|
2016-08-14 12:10:50 +02:00
|
|
|
try:
|
2018-10-06 12:35:49 +02:00
|
|
|
current_registration = EventRegistration.objects.get(
|
|
|
|
user=member, event=form.event
|
|
|
|
)
|
2016-08-14 12:10:50 +02:00
|
|
|
current_registration.delete()
|
|
|
|
except EventRegistration.DoesNotExist:
|
|
|
|
pass
|
|
|
|
continue
|
|
|
|
all_choices = get_event_form_choices(form.event, form)
|
2018-10-06 12:35:49 +02:00
|
|
|
(
|
|
|
|
current_registration,
|
|
|
|
created_reg,
|
|
|
|
) = EventRegistration.objects.get_or_create(
|
|
|
|
user=member, event=form.event
|
|
|
|
)
|
|
|
|
update_event_form_comments(form.event, form, current_registration)
|
2019-04-17 18:21:59 +02:00
|
|
|
current_registration.options.set(all_choices)
|
2018-10-06 12:35:49 +02:00
|
|
|
current_registration.paid = form.cleaned_data["status"] == "paid"
|
2016-08-14 12:10:50 +02:00
|
|
|
current_registration.save()
|
2016-12-22 12:28:03 +01:00
|
|
|
# if form.event.title == "Mega 15" and created_reg:
|
|
|
|
# field = EventCommentField.objects.get(
|
|
|
|
# event=form.event, name="Commentaires")
|
|
|
|
# try:
|
|
|
|
# comments = EventCommentValue.objects.get(
|
|
|
|
# commentfield=field,
|
|
|
|
# registration=current_registration).content
|
|
|
|
# except EventCommentValue.DoesNotExist:
|
|
|
|
# comments = field.default
|
|
|
|
# FIXME : il faut faire quelque chose de propre ici,
|
|
|
|
# par exemple écrire un mail générique pour
|
|
|
|
# l'inscription aux événements et/ou donner la
|
|
|
|
# possibilité d'associer un mail aux événements
|
|
|
|
# send_custom_mail(...)
|
2016-08-23 17:40:24 +02:00
|
|
|
# Enregistrement des inscriptions aux clubs
|
|
|
|
member.clubs.clear()
|
2018-10-06 12:35:49 +02:00
|
|
|
for club in clubs_form.cleaned_data["clubs"]:
|
2016-08-23 17:40:24 +02:00
|
|
|
club.membres.add(member)
|
|
|
|
club.save()
|
2017-05-23 06:41:57 +02:00
|
|
|
|
|
|
|
# ---
|
|
|
|
# Success
|
|
|
|
# ---
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
msg = (
|
|
|
|
"L'inscription de {:s} (<tt>{:s}</tt>) a été "
|
|
|
|
"enregistrée avec succès.".format(
|
|
|
|
member.get_full_name(), member.email
|
|
|
|
)
|
|
|
|
)
|
2017-05-23 06:41:57 +02:00
|
|
|
if profile.is_cof:
|
|
|
|
msg += "\nIl est désormais membre du COF n°{:d} !".format(
|
2018-10-06 12:35:49 +02:00
|
|
|
member.profile.id
|
|
|
|
)
|
|
|
|
messages.success(request, msg, extra_tags="safe")
|
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"gestioncof/registration_post.html",
|
|
|
|
{
|
|
|
|
"user_form": user_form,
|
|
|
|
"profile_form": profile_form,
|
|
|
|
"member": member,
|
|
|
|
"login_clipper": login_clipper,
|
|
|
|
"event_formset": event_formset,
|
|
|
|
"clubs_form": clubs_form,
|
|
|
|
},
|
|
|
|
)
|
2013-09-05 22:20:52 +02:00
|
|
|
else:
|
|
|
|
return render(request, "registration.html")
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-08-23 20:10:25 +02:00
|
|
|
# -----
|
|
|
|
# Clubs
|
|
|
|
# -----
|
|
|
|
|
|
|
|
|
2016-08-23 18:57:59 +02:00
|
|
|
@login_required
|
|
|
|
def membres_club(request, name):
|
|
|
|
# Vérification des permissions : l'utilisateur doit être membre du burô
|
|
|
|
# ou respo du club.
|
|
|
|
user = request.user
|
|
|
|
club = get_object_or_404(Club, name=name)
|
2018-10-06 12:35:49 +02:00
|
|
|
if not request.user.profile.is_buro and club not in user.clubs_geres.all():
|
|
|
|
return HttpResponseForbidden("<h1>Permission denied</h1>")
|
2016-08-23 21:09:47 +02:00
|
|
|
members_no_respo = club.membres.exclude(clubs_geres=club).all()
|
2018-10-06 12:35:49 +02:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"membres_clubs.html",
|
|
|
|
{"club": club, "members_no_respo": members_no_respo},
|
|
|
|
)
|
2016-08-23 21:09:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
@buro_required
|
|
|
|
def change_respo(request, club_name, user_id):
|
|
|
|
club = get_object_or_404(Club, name=club_name)
|
|
|
|
user = get_object_or_404(User, id=user_id)
|
|
|
|
if user in club.respos.all():
|
|
|
|
club.respos.remove(user)
|
|
|
|
elif user in club.membres.all():
|
|
|
|
club.respos.add(user)
|
|
|
|
else:
|
|
|
|
raise Http404
|
2018-10-06 12:35:49 +02:00
|
|
|
return redirect("membres-club", name=club_name)
|
2016-08-23 18:57:59 +02:00
|
|
|
|
|
|
|
|
2016-08-23 20:10:25 +02:00
|
|
|
@cof_required
|
|
|
|
def liste_clubs(request):
|
|
|
|
clubs = Club.objects
|
|
|
|
if request.user.profile.is_buro:
|
2018-10-06 12:35:49 +02:00
|
|
|
data = {"owned_clubs": clubs.all()}
|
2016-08-23 20:10:25 +02:00
|
|
|
else:
|
2018-10-06 12:35:49 +02:00
|
|
|
data = {
|
|
|
|
"owned_clubs": request.user.clubs_geres.all(),
|
|
|
|
"other_clubs": clubs.exclude(respos=request.user),
|
|
|
|
}
|
|
|
|
return render(request, "liste_clubs.html", data)
|
2016-08-23 20:10:25 +02:00
|
|
|
|
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
@buro_required
|
|
|
|
def export_members(request):
|
2018-10-06 12:35:49 +02:00
|
|
|
response = HttpResponse(content_type="text/csv")
|
|
|
|
response["Content-Disposition"] = "attachment; filename=membres_cof.csv"
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2019-10-05 17:37:08 +02:00
|
|
|
writer = csv.writer(response)
|
2016-07-09 21:19:37 +02:00
|
|
|
for profile in CofProfile.objects.filter(is_cof=True).all():
|
2013-09-05 22:20:52 +02:00
|
|
|
user = profile.user
|
2018-10-06 12:35:49 +02:00
|
|
|
bits = [
|
|
|
|
user.id,
|
|
|
|
user.username,
|
|
|
|
user.first_name,
|
|
|
|
user.last_name,
|
|
|
|
user.email,
|
|
|
|
profile.phone,
|
|
|
|
profile.occupation,
|
|
|
|
profile.departement,
|
|
|
|
profile.type_cotiz,
|
|
|
|
]
|
2017-05-22 00:39:36 +02:00
|
|
|
writer.writerow([str(bit) for bit in bits])
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
return response
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2018-09-09 07:20:18 +02:00
|
|
|
# ----------------------------------------
|
|
|
|
# Début des exports Mega machins hardcodés
|
|
|
|
# ----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
MEGA_YEAR = 2018
|
|
|
|
MEGA_EVENT_NAME = "MEGA 2018"
|
|
|
|
MEGA_COMMENTFIELD_NAME = "Commentaires"
|
|
|
|
MEGA_CONSCRITORGAFIELD_NAME = "Orga ? Conscrit ?"
|
|
|
|
MEGA_CONSCRIT = "Conscrit"
|
|
|
|
MEGA_ORGA = "Orga"
|
|
|
|
|
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
def csv_export_mega(filename, qs):
|
2018-10-06 12:35:49 +02:00
|
|
|
response = HttpResponse(content_type="text/csv")
|
|
|
|
response["Content-Disposition"] = "attachment; filename=" + filename
|
2019-10-05 17:37:08 +02:00
|
|
|
writer = csv.writer(response)
|
2014-08-19 12:54:22 +02:00
|
|
|
|
|
|
|
for reg in qs.all():
|
2013-09-05 22:20:52 +02:00
|
|
|
user = reg.user
|
2016-05-24 00:02:25 +02:00
|
|
|
profile = user.profile
|
2018-10-06 12:35:49 +02:00
|
|
|
comments = "---".join([comment.content for comment in reg.comments.all()])
|
|
|
|
bits = [
|
|
|
|
user.username,
|
|
|
|
user.first_name,
|
|
|
|
user.last_name,
|
|
|
|
user.email,
|
|
|
|
profile.phone,
|
|
|
|
user.id,
|
|
|
|
profile.comments if profile.comments else "",
|
|
|
|
comments,
|
|
|
|
]
|
2016-07-09 22:31:56 +02:00
|
|
|
|
2017-05-22 00:39:36 +02:00
|
|
|
writer.writerow([str(bit) for bit in bits])
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
return response
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
@buro_required
|
2014-08-19 12:54:22 +02:00
|
|
|
def export_mega_remarksonly(request):
|
2018-10-06 12:35:49 +02:00
|
|
|
filename = "remarques_mega_{}.csv".format(MEGA_YEAR)
|
|
|
|
response = HttpResponse(content_type="text/csv")
|
|
|
|
response["Content-Disposition"] = "attachment; filename=" + filename
|
2019-10-05 17:37:08 +02:00
|
|
|
writer = csv.writer(response)
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2018-09-09 07:20:18 +02:00
|
|
|
event = Event.objects.get(title=MEGA_EVENT_NAME)
|
|
|
|
commentfield = event.commentfields.get(name=MEGA_COMMENTFIELD_NAME)
|
2014-08-19 12:54:22 +02:00
|
|
|
for val in commentfield.values.all():
|
|
|
|
reg = val.registration
|
2013-09-05 22:20:52 +02:00
|
|
|
user = reg.user
|
2016-05-24 00:02:25 +02:00
|
|
|
profile = user.profile
|
2018-10-06 12:35:49 +02:00
|
|
|
bits = [
|
|
|
|
user.username,
|
|
|
|
user.first_name,
|
|
|
|
user.last_name,
|
|
|
|
user.email,
|
|
|
|
profile.phone,
|
|
|
|
profile.id,
|
|
|
|
profile.comments,
|
|
|
|
val.content,
|
|
|
|
]
|
2017-05-22 00:39:36 +02:00
|
|
|
writer.writerow([str(bit) for bit in bits])
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
return response
|
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2017-09-05 15:21:19 +02:00
|
|
|
# @buro_required
|
|
|
|
# def export_mega_bytype(request, type):
|
|
|
|
# types = {"orga-actif": "Orga élève",
|
|
|
|
# "orga-branleur": "Orga étudiant",
|
|
|
|
# "conscrit-eleve": "Conscrit élève",
|
|
|
|
# "conscrit-etudiant": "Conscrit étudiant"}
|
|
|
|
#
|
|
|
|
# if type not in types:
|
|
|
|
# raise Http404
|
|
|
|
#
|
|
|
|
# event = Event.objects.get(title="MEGA 2017")
|
|
|
|
# type_option = event.options.get(name="Type")
|
|
|
|
# participant_type = type_option.choices.get(value=types[type]).id
|
|
|
|
# qs = EventRegistration.objects.filter(event=event).filter(
|
|
|
|
# options__id__exact=participant_type)
|
|
|
|
# return csv_export_mega(type + '_mega_2017.csv', qs)
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
@buro_required
|
|
|
|
def export_mega_orgas(request):
|
2018-09-09 07:20:18 +02:00
|
|
|
event = Event.objects.get(title=MEGA_EVENT_NAME)
|
|
|
|
type_option = event.options.get(name=MEGA_CONSCRITORGAFIELD_NAME)
|
|
|
|
participant_type = type_option.choices.get(value=MEGA_ORGA).id
|
2017-09-05 15:21:19 +02:00
|
|
|
qs = EventRegistration.objects.filter(event=event).filter(
|
|
|
|
options__id=participant_type
|
|
|
|
)
|
2018-10-06 12:35:49 +02:00
|
|
|
return csv_export_mega("orgas_mega_{}.csv".format(MEGA_YEAR), qs)
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-05-21 23:57:36 +02:00
|
|
|
@buro_required
|
2014-08-19 12:54:22 +02:00
|
|
|
def export_mega_participants(request):
|
2018-09-09 07:20:18 +02:00
|
|
|
event = Event.objects.get(title=MEGA_EVENT_NAME)
|
|
|
|
type_option = event.options.get(name=MEGA_CONSCRITORGAFIELD_NAME)
|
|
|
|
participant_type = type_option.choices.get(value=MEGA_CONSCRIT).id
|
2016-07-09 22:31:56 +02:00
|
|
|
qs = EventRegistration.objects.filter(event=event).filter(
|
2017-09-05 15:21:19 +02:00
|
|
|
options__id=participant_type
|
|
|
|
)
|
2018-10-06 12:35:49 +02:00
|
|
|
return csv_export_mega("conscrits_mega_{}.csv".format(MEGA_YEAR), qs)
|
2014-08-19 12:54:22 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2014-08-19 12:54:22 +02:00
|
|
|
@buro_required
|
|
|
|
def export_mega(request):
|
2019-04-17 18:33:43 +02:00
|
|
|
event = Event.objects.get(title=MEGA_EVENT_NAME)
|
2018-10-06 12:35:49 +02:00
|
|
|
qs = EventRegistration.objects.filter(event=event).order_by("user__username")
|
|
|
|
return csv_export_mega("all_mega_{}.csv".format(MEGA_YEAR), qs)
|
|
|
|
|
2018-09-09 07:20:18 +02:00
|
|
|
|
|
|
|
# ------------------------------
|
|
|
|
# Fin des exports Mega hardcodés
|
|
|
|
# ------------------------------
|
2013-09-05 22:20:52 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
@buro_required
|
|
|
|
def utile_cof(request):
|
2017-01-10 23:26:11 +01:00
|
|
|
return render(request, "gestioncof/utile_cof.html", {})
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2013-09-05 22:20:52 +02:00
|
|
|
|
|
|
|
@buro_required
|
|
|
|
def utile_bda(request):
|
2016-06-06 18:43:56 +02:00
|
|
|
tirages = Tirage.objects.all()
|
2018-10-06 12:35:49 +02:00
|
|
|
return render(request, "utile_bda.html", {"tirages": tirages})
|
2016-05-21 23:57:36 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-05-21 23:57:36 +02:00
|
|
|
@buro_required
|
|
|
|
def liste_bdadiff(request):
|
|
|
|
titre = "BdA diffusion"
|
2016-07-09 21:19:37 +02:00
|
|
|
personnes = CofProfile.objects.filter(mailing_bda=True, is_cof=True).all()
|
2018-10-06 12:35:49 +02:00
|
|
|
return render(request, "liste_mails.html", {"titre": titre, "personnes": personnes})
|
2016-07-09 21:19:37 +02:00
|
|
|
|
|
|
|
|
2016-05-21 23:57:36 +02:00
|
|
|
@buro_required
|
|
|
|
def liste_bdarevente(request):
|
|
|
|
titre = "BdA revente"
|
2018-10-06 12:35:49 +02:00
|
|
|
personnes = CofProfile.objects.filter(mailing_bda_revente=True, is_cof=True).all()
|
|
|
|
return render(request, "liste_mails.html", {"titre": titre, "personnes": personnes})
|
2016-05-21 23:57:36 +02:00
|
|
|
|
2016-07-09 21:19:37 +02:00
|
|
|
|
2016-05-21 23:57:36 +02:00
|
|
|
@buro_required
|
|
|
|
def liste_diffcof(request):
|
|
|
|
titre = "Diffusion COF"
|
2016-07-09 21:19:37 +02:00
|
|
|
personnes = CofProfile.objects.filter(mailing_cof=True, is_cof=True).all()
|
2018-10-06 12:35:49 +02:00
|
|
|
return render(request, "liste_mails.html", {"titre": titre, "personnes": personnes})
|
2016-07-15 01:06:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
@cof_required
|
|
|
|
def calendar(request):
|
2016-07-15 02:49:56 +02:00
|
|
|
try:
|
|
|
|
instance = CalendarSubscription.objects.get(user=request.user)
|
|
|
|
except CalendarSubscription.DoesNotExist:
|
|
|
|
instance = None
|
2018-10-06 12:35:49 +02:00
|
|
|
if request.method == "POST":
|
2016-07-15 02:49:56 +02:00
|
|
|
form = CalendarForm(request.POST, instance=instance)
|
2016-07-15 01:06:33 +02:00
|
|
|
if form.is_valid():
|
|
|
|
subscription = form.save(commit=False)
|
2016-07-15 23:31:26 +02:00
|
|
|
if instance is None:
|
|
|
|
subscription.user = request.user
|
|
|
|
subscription.token = uuid.uuid4()
|
2016-07-15 01:06:33 +02:00
|
|
|
subscription.save()
|
|
|
|
form.save_m2m()
|
2018-10-06 12:35:49 +02:00
|
|
|
messages.success(request, "Calendrier mis à jour avec succès.")
|
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"gestioncof/calendar_subscription.html",
|
|
|
|
{"form": form, "token": str(subscription.token)},
|
|
|
|
)
|
2016-07-15 01:06:33 +02:00
|
|
|
else:
|
2017-01-30 13:46:16 +01:00
|
|
|
messages.error(request, "Formulaire incorrect.")
|
2018-10-06 12:35:49 +02:00
|
|
|
return render(
|
|
|
|
request, "gestioncof/calendar_subscription.html", {"form": form}
|
|
|
|
)
|
2016-07-15 01:06:33 +02:00
|
|
|
else:
|
2018-10-06 12:35:49 +02:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"gestioncof/calendar_subscription.html",
|
|
|
|
{
|
|
|
|
"form": CalendarForm(instance=instance),
|
|
|
|
"token": instance.token if instance else None,
|
|
|
|
},
|
|
|
|
)
|
2016-07-15 01:06:33 +02:00
|
|
|
|
|
|
|
|
2016-07-15 23:31:26 +02:00
|
|
|
def calendar_ics(request, token):
|
|
|
|
subscription = get_object_or_404(CalendarSubscription, token=token)
|
2016-07-16 18:22:53 +02:00
|
|
|
shows = subscription.other_shows.all()
|
|
|
|
if subscription.subscribe_to_my_shows:
|
|
|
|
shows |= Spectacle.objects.filter(
|
2018-10-06 12:35:49 +02:00
|
|
|
attribues__participant__user=subscription.user, tirage__active=True
|
|
|
|
)
|
2016-07-16 18:22:53 +02:00
|
|
|
shows = shows.distinct()
|
2016-07-15 01:06:33 +02:00
|
|
|
vcal = Calendar()
|
2016-11-05 18:04:54 +01:00
|
|
|
site = Site.objects.get_current()
|
2016-07-16 01:51:20 +02:00
|
|
|
for show in shows:
|
2016-07-15 01:06:33 +02:00
|
|
|
vevent = Vevent()
|
2018-10-06 12:35:49 +02:00
|
|
|
vevent.add("dtstart", show.date)
|
|
|
|
vevent.add("dtend", show.date + timedelta(seconds=7200))
|
|
|
|
vevent.add("summary", show.title)
|
|
|
|
vevent.add("location", show.location.name)
|
|
|
|
vevent.add(
|
|
|
|
"uid", "show-{:d}-{:d}@{:s}".format(show.pk, show.tirage_id, site.domain)
|
|
|
|
)
|
2016-07-15 01:06:33 +02:00
|
|
|
vcal.add_component(vevent)
|
2016-07-15 02:49:56 +02:00
|
|
|
if subscription.subscribe_to_events:
|
2016-07-15 01:06:33 +02:00
|
|
|
for event in Event.objects.filter(old=False).all():
|
|
|
|
vevent = Vevent()
|
2018-10-06 12:35:49 +02:00
|
|
|
vevent.add("dtstart", event.start_date)
|
|
|
|
vevent.add("dtend", event.end_date)
|
|
|
|
vevent.add("summary", event.title)
|
|
|
|
vevent.add("location", event.location)
|
|
|
|
vevent.add("description", event.description)
|
|
|
|
vevent.add("uid", "event-{:d}@{:s}".format(event.pk, site.domain))
|
2016-07-15 01:06:33 +02:00
|
|
|
vcal.add_component(vevent)
|
|
|
|
response = HttpResponse(content=vcal.to_ical())
|
2018-10-06 12:35:49 +02:00
|
|
|
response["Content-Type"] = "text/calendar"
|
2016-07-15 01:06:33 +02:00
|
|
|
return response
|
2017-05-26 00:58:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ConfigUpdate(FormView):
|
|
|
|
form_class = GestioncofConfigForm
|
|
|
|
template_name = "gestioncof/banner_update.html"
|
|
|
|
success_url = reverse_lazy("home")
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
if request.user is None or not request.user.is_superuser:
|
2018-01-22 21:59:07 +01:00
|
|
|
return redirect_to_login(request.get_full_path())
|
2017-05-26 00:58:59 +02:00
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
form.save()
|
|
|
|
return super().form_valid(form)
|
2017-11-19 18:41:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
# Autocomplete views
|
|
|
|
#
|
|
|
|
# https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#create-an-autocomplete-view
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
class UserAutocomplete(Select2QuerySetView):
|
|
|
|
model = User
|
2018-10-06 12:35:49 +02:00
|
|
|
search_fields = ("username", "first_name", "last_name")
|
2017-11-19 18:41:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
user_autocomplete = buro_required(UserAutocomplete.as_view())
|