forked from DGNum/gestioCOF
PEP8: fixed ' = ' → '=' on parameters
'unexpected spaces around keyword / parameter equals'
This commit is contained in:
parent
7de11f2285
commit
c7a3656ded
18 changed files with 496 additions and 379 deletions
|
@ -27,8 +27,10 @@ class ParticipantAdmin(admin.ModelAdmin):
|
|||
nb_places.short_description = "Nombre de places"
|
||||
def total(self, obj):
|
||||
tot = obj.total
|
||||
if tot: return u"%.02f €" % tot
|
||||
else: return u"0 €"
|
||||
if tot:
|
||||
return u"%.02f €" % tot
|
||||
else:
|
||||
return u"0 €"
|
||||
total.admin_order_field = "total"
|
||||
total.short_description = "Total à payer"
|
||||
list_display = ("user", "nb_places", "total", "paid", "paymenttype",
|
||||
|
|
|
@ -39,8 +39,10 @@ class Algorithm(object):
|
|||
member_shows[member] = {}
|
||||
for choice in choices:
|
||||
member = choice.participant
|
||||
if choice.spectacle in member_shows[member]: continue
|
||||
else: member_shows[member][choice.spectacle] = True
|
||||
if choice.spectacle in member_shows[member]:
|
||||
continue
|
||||
else:
|
||||
member_shows[member][choice.spectacle] = True
|
||||
showdict[choice.spectacle].requests.append(member)
|
||||
showdict[choice.spectacle].nrequests += 2 if choice.double else 1
|
||||
self.ranks[member][choice.spectacle] = next_rank[member]
|
||||
|
@ -97,4 +99,3 @@ class Algorithm(object):
|
|||
self.IncrementRanks(member, i)
|
||||
results.append((show, winners, losers))
|
||||
return results
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ class BaseBdaFormSet(BaseInlineFormSet):
|
|||
"""Checks that no two articles have the same title."""
|
||||
super(BaseBdaFormSet, self).clean()
|
||||
if any(self.errors):
|
||||
# Don't bother validating the formset unless each form is valid on its own
|
||||
# Don't bother validating the formset unless each form is valid on
|
||||
# its own
|
||||
return
|
||||
spectacles = []
|
||||
for i in range(0, self.total_form_count()):
|
||||
|
@ -38,4 +39,3 @@ class ResellForm(forms.Form):
|
|||
def __init__(self, participant, *args, **kwargs):
|
||||
super(ResellForm, self).__init__(*args, **kwargs)
|
||||
self.fields['spectacle'].queryset = participant.attributions.all().distinct()
|
||||
|
||||
|
|
|
@ -111,4 +111,3 @@ class Attribution(models.Model):
|
|||
|
||||
def __unicode__(self):
|
||||
return u"%s -- %s" % (self.participant, self.spectacle)
|
||||
|
||||
|
|
27
bda/views.py
27
bda/views.py
|
@ -23,6 +23,7 @@ from bda.algorithm import Algorithm
|
|||
|
||||
from bda.forms import BaseBdaFormSet, TokenForm, ResellForm
|
||||
|
||||
|
||||
@cof_required
|
||||
def etat_places(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
|
@ -60,12 +61,14 @@ def etat_places(request, tirage_id):
|
|||
return render(request, "etat-places.html",
|
||||
{"spectacles": spectacles, "total": total, 'tirage': tirage})
|
||||
|
||||
|
||||
def _hash_queryset(queryset):
|
||||
data = serializers.serialize("json", queryset)
|
||||
hasher = hashlib.sha256()
|
||||
hasher.update(data)
|
||||
return hasher.hexdigest()
|
||||
|
||||
|
||||
@cof_required
|
||||
def places(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
|
@ -99,6 +102,7 @@ def places(request, tirage_id):
|
|||
"total": total,
|
||||
"warning": warning})
|
||||
|
||||
|
||||
@cof_required
|
||||
def places_ics(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
|
@ -114,7 +118,8 @@ def places_ics(request, tirage_id):
|
|||
places_dict[place.spectacle].double = True
|
||||
else:
|
||||
place.double = False
|
||||
place.spectacle.dtend = place.spectacle.date + timedelta(seconds=7200)
|
||||
place.spectacle.dtend = place.spectacle.date + \
|
||||
timedelta(seconds=7200)
|
||||
places_dict[place.spectacle] = place
|
||||
spectacles.append(place.spectacle)
|
||||
filtered_places.append(place)
|
||||
|
@ -122,6 +127,7 @@ def places_ics(request, tirage_id):
|
|||
{"participant": participant,
|
||||
"places": filtered_places}, content_type="text/calendar")
|
||||
|
||||
|
||||
@cof_required
|
||||
def inscription(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
|
@ -170,7 +176,8 @@ def inscription(request, tirage_id):
|
|||
total_price = 0
|
||||
for choice in participant.choixspectacle_set.all():
|
||||
total_price += choice.spectacle.price
|
||||
if choice.double: total_price += choice.spectacle.price
|
||||
if choice.double:
|
||||
total_price += choice.spectacle.price
|
||||
return render(request, "inscription-bda.html",
|
||||
{ "formset": formset,
|
||||
"success": success,
|
||||
|
@ -179,6 +186,7 @@ def inscription(request, tirage_id):
|
|||
'tirage': tirage,
|
||||
"stateerror": stateerror})
|
||||
|
||||
|
||||
def do_tirage(request, tirage_id):
|
||||
tirage_elt = get_object_or_404(Tirage, id=tirage_id)
|
||||
form = TokenForm(request.POST)
|
||||
|
@ -221,8 +229,9 @@ def do_tirage(request, tirage_id):
|
|||
data["duration"] = time.time() - start
|
||||
if request.user.is_authenticated():
|
||||
members2 = {}
|
||||
members_uniq = {} # Participant objects are not shared accross spectacle results,
|
||||
# So assign a single object for each Participant id
|
||||
# Participant objects are not shared accross spectacle results,
|
||||
# so assign a single object for each Participant id
|
||||
members_uniq = {}
|
||||
for (show, members, _) in results:
|
||||
for (member, _, _, _) in members:
|
||||
if member.id not in members_uniq:
|
||||
|
@ -249,6 +258,7 @@ def do_tirage(request, tirage_id):
|
|||
else:
|
||||
return render(request, "bda-attrib.html", data)
|
||||
|
||||
|
||||
@buro_required
|
||||
def tirage(request, tirage_id):
|
||||
if request.POST:
|
||||
|
@ -259,6 +269,7 @@ def tirage(request, tirage_id):
|
|||
form = TokenForm()
|
||||
return render(request, "bda-token.html", {"form": form})
|
||||
|
||||
|
||||
def do_resell(request, form):
|
||||
spectacle = form.cleaned_data["spectacle"]
|
||||
count = form.cleaned_data["count"]
|
||||
|
@ -276,6 +287,7 @@ Contactez moi par email si vous êtes intéressé·e·s !
|
|||
fail_silently=False)
|
||||
return render(request, "bda-success.html", {"show": spectacle, "places": places})
|
||||
|
||||
|
||||
@login_required
|
||||
def revente(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
|
@ -291,6 +303,7 @@ def revente(request, tirage_id):
|
|||
form = ResellForm(participant)
|
||||
return render(request, "bda-revente.html", {"form": form, 'tirage': tirage})
|
||||
|
||||
|
||||
@buro_required
|
||||
def spectacle(request, tirage_id, spectacle_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
|
@ -317,19 +330,23 @@ def spectacle(request, tirage_id, spectacle_id):
|
|||
return render(request, "bda-participants.html",
|
||||
{"spectacle": spectacle, "participants": participants_info})
|
||||
|
||||
|
||||
class SpectacleListView(ListView):
|
||||
model = Spectacle
|
||||
template_name = 'spectacle_list.html'
|
||||
|
||||
def get_queryset(self):
|
||||
self.tirage = get_object_or_404(Tirage, id=self.kwargs['tirage_id'])
|
||||
categories = self.tirage.spectacle_set.all()
|
||||
return categories
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SpectacleListView, self).get_context_data(**kwargs)
|
||||
context['tirage_id'] = self.tirage.id
|
||||
context['tirage_name'] = self.tirage.title
|
||||
return context
|
||||
|
||||
|
||||
@buro_required
|
||||
def unpaid(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
|
@ -338,6 +355,7 @@ def unpaid(request, tirage_id):
|
|||
.filter(paid=False, nb_attributions__gt=0).all()
|
||||
return render(request, "bda-unpaid.html", {"unpaid": unpaid})
|
||||
|
||||
|
||||
@buro_required
|
||||
def liste_spectacles_ics(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
|
@ -347,4 +365,3 @@ def liste_spectacles_ics(request, tirage_id):
|
|||
return render(request, "liste_spectacles.ics",
|
||||
{"spectacles": spectacles, "tirage": tirage},
|
||||
content_type="text/calendar")
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
from django.conf.urls import patterns, include, url
|
||||
|
||||
import autocomplete_light
|
||||
autocomplete_light.autodiscover()
|
||||
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
from gestioncof.urls import export_patterns, petitcours_patterns, \
|
||||
surveys_patterns, events_patterns
|
||||
|
||||
autocomplete_light.autodiscover()
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Page d'accueil
|
||||
url(r'^$', 'gestioncof.views.home', name='home'),
|
||||
|
@ -67,4 +68,3 @@ urlpatterns = patterns('',
|
|||
url(r'^utile_cof/diff_cof$', 'gestioncof.views.liste_diffcof'),
|
||||
url(r'^utile_bda/bda_revente$', 'gestioncof.views.liste_bdarevente'),
|
||||
)
|
||||
|
||||
|
|
|
@ -9,9 +9,11 @@ from django.core.urlresolvers import reverse
|
|||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
def add_link_field(target_model='', field='', link_text=unicode, desc_text=unicode):
|
||||
def add_link(cls):
|
||||
reverse_name = target_model or cls.model.__name__.lower()
|
||||
|
||||
def link(self, instance):
|
||||
app_name = instance._meta.app_label
|
||||
reverse_path = "admin:%s_%s_change" % (app_name, reverse_name)
|
||||
|
@ -27,50 +29,61 @@ def add_link_field(target_model='', field='', link_text=unicode, desc_text=unico
|
|||
return cls
|
||||
return add_link
|
||||
|
||||
|
||||
class SurveyQuestionAnswerInline(admin.TabularInline):
|
||||
model = SurveyQuestionAnswer
|
||||
|
||||
|
||||
@add_link_field(desc_text=lambda x: "Réponses",
|
||||
link_text=lambda x: "Éditer les réponses")
|
||||
class SurveyQuestionInline(admin.TabularInline):
|
||||
model = SurveyQuestion
|
||||
|
||||
|
||||
class SurveyQuestionAdmin(admin.ModelAdmin):
|
||||
inlines = [
|
||||
SurveyQuestionAnswerInline,
|
||||
]
|
||||
|
||||
|
||||
class SurveyAdmin(admin.ModelAdmin):
|
||||
inlines = [
|
||||
SurveyQuestionInline,
|
||||
]
|
||||
|
||||
|
||||
class EventOptionChoiceInline(admin.TabularInline):
|
||||
model = EventOptionChoice
|
||||
|
||||
|
||||
@add_link_field(desc_text=lambda x: "Choix",
|
||||
link_text=lambda x: "Éditer les choix")
|
||||
class EventOptionInline(admin.TabularInline):
|
||||
model = EventOption
|
||||
|
||||
|
||||
class EventCommentFieldInline(admin.TabularInline):
|
||||
model = EventCommentField
|
||||
|
||||
|
||||
class EventOptionAdmin(admin.ModelAdmin):
|
||||
inlines = [
|
||||
EventOptionChoiceInline,
|
||||
]
|
||||
|
||||
|
||||
class EventAdmin(admin.ModelAdmin):
|
||||
inlines = [
|
||||
EventOptionInline,
|
||||
EventCommentFieldInline,
|
||||
]
|
||||
|
||||
|
||||
class CofProfileInline(admin.StackedInline):
|
||||
model = CofProfile
|
||||
inline_classes = ("collapse open",)
|
||||
|
||||
|
||||
class FkeyLookup(object):
|
||||
def __init__(self, fkeydecl, short_description=None, admin_order_field=None):
|
||||
self.fk, fkattrs = fkeydecl.split('__', 1)
|
||||
|
@ -89,6 +102,7 @@ class FkeyLookup(object):
|
|||
item = getattr(item, attr)
|
||||
return item
|
||||
|
||||
|
||||
def ProfileInfo(field, short_description, boolean=False):
|
||||
def getter(self):
|
||||
try:
|
||||
|
@ -108,6 +122,7 @@ User.profile_mailing_cof = ProfileInfo("mailing_cof", "ML COF", True)
|
|||
User.profile_mailing_bda = ProfileInfo("mailing_bda", "ML BDA", True)
|
||||
User.profile_mailing_bda_revente = ProfileInfo("mailing_bda_revente", "ML BDA-R", True)
|
||||
|
||||
|
||||
class UserProfileAdmin(UserAdmin):
|
||||
def is_buro(self, obj):
|
||||
try:
|
||||
|
@ -137,12 +152,15 @@ class UserProfileAdmin(UserAdmin):
|
|||
]
|
||||
|
||||
import autocomplete_light
|
||||
|
||||
def user_unicode(self):
|
||||
if self.first_name and self.last_name:
|
||||
return u"%s %s (%s)" % (self.first_name, self.last_name, self.username)
|
||||
else:
|
||||
return self.username
|
||||
User.__unicode__ = user_unicode
|
||||
|
||||
|
||||
class EventRegistrationAdmin(admin.ModelAdmin):
|
||||
form = autocomplete_light.modelform_factory(EventRegistration, exclude=[])
|
||||
list_display = ('__unicode__','event','user','paid')
|
||||
|
@ -150,15 +168,18 @@ class EventRegistrationAdmin(admin.ModelAdmin):
|
|||
search_fields = ('user__username', 'user__first_name', 'user__last_name',
|
||||
'user__email', 'event__title')
|
||||
|
||||
|
||||
class PetitCoursAbilityAdmin(admin.ModelAdmin):
|
||||
list_display = ('user','matiere','niveau','agrege')
|
||||
search_fields = ('user__username', 'user__first_name', 'user__last_name',
|
||||
'user__email', 'matiere__name', 'niveau')
|
||||
list_filter = ('matiere','niveau','agrege')
|
||||
|
||||
|
||||
class PetitCoursAttributionAdmin(admin.ModelAdmin):
|
||||
list_display = ('user','demande','matiere','rank',)
|
||||
|
||||
|
||||
class PetitCoursAttributionCounterAdmin(admin.ModelAdmin):
|
||||
list_display = ('user','matiere','count',)
|
||||
list_filter = ('matiere',)
|
||||
|
@ -171,6 +192,7 @@ class PetitCoursAttributionCounterAdmin(admin.ModelAdmin):
|
|||
queryset.update(count=0)
|
||||
reset.short_description = u"Remise à zéro du compteur"
|
||||
|
||||
|
||||
class PetitCoursDemandeAdmin(admin.ModelAdmin):
|
||||
list_display = ('name','email','agrege_requis','niveau','created',
|
||||
'traitee','processed')
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.db.models import Q
|
|||
from django.contrib.auth.models import User
|
||||
from gestioncof.models import CofProfile, Clipper
|
||||
|
||||
|
||||
def autocomplete(request):
|
||||
if "q" not in request.GET:
|
||||
raise Http404
|
||||
|
|
|
@ -3,6 +3,7 @@ from django.http import HttpResponse, HttpResponseForbidden
|
|||
from django.template.defaultfilters import slugify
|
||||
from django.apps import apps
|
||||
|
||||
|
||||
def export(qs, fields=None):
|
||||
model = qs.model
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
|
@ -29,6 +30,7 @@ def export(qs, fields=None):
|
|||
# Return CSV file to browser as download
|
||||
return response
|
||||
|
||||
|
||||
def admin_list_export(request, model_name, app_label, queryset=None, fields=None, list_display=True):
|
||||
"""
|
||||
Put the following line in your urls.py BEFORE your admin include
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django_cas_ng.decorators import user_passes_test
|
||||
|
||||
|
||||
def is_cof(user):
|
||||
try:
|
||||
profile = user.profile
|
||||
|
@ -10,6 +11,7 @@ def is_cof(user):
|
|||
cof_required = user_passes_test(lambda u: is_cof(u))
|
||||
cof_required_customdenied = user_passes_test(lambda u: is_cof(u), login_url="cof-denied")
|
||||
|
||||
|
||||
def is_buro(user):
|
||||
try:
|
||||
profile = user.profile
|
||||
|
|
|
@ -10,6 +10,7 @@ from gestioncof.models import CofProfile, EventCommentValue
|
|||
from gestioncof.widgets import TriStateCheckbox
|
||||
from gestioncof.shared import lock_table, unlock_table
|
||||
|
||||
|
||||
class EventForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
event = kwargs.pop("event")
|
||||
|
@ -48,6 +49,7 @@ class EventForm(forms.Form):
|
|||
if name.startswith('option_'):
|
||||
yield (self.fields[name].option_id, value)
|
||||
|
||||
|
||||
class SurveyForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
survey = kwargs.pop("survey")
|
||||
|
@ -84,6 +86,7 @@ class SurveyForm(forms.Form):
|
|||
if name.startswith('question_'):
|
||||
yield (self.fields[name].question_id, value)
|
||||
|
||||
|
||||
class SurveyStatusFilterForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
survey = kwargs.pop("survey")
|
||||
|
@ -109,6 +112,7 @@ class SurveyStatusFilterForm(forms.Form):
|
|||
if name.startswith('question_'):
|
||||
yield (self.fields[name].question_id, self.fields[name].answer_id, value)
|
||||
|
||||
|
||||
class EventStatusFilterForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
event = kwargs.pop("event")
|
||||
|
@ -148,6 +152,7 @@ class EventStatusFilterForm(forms.Form):
|
|||
elif name == "event_has_paid":
|
||||
yield ("has_paid", None, value)
|
||||
|
||||
|
||||
class UserProfileForm(forms.ModelForm):
|
||||
first_name = forms.CharField(label=_(u'Prénom'), max_length=30)
|
||||
last_name = forms.CharField(label=_(u'Nom'), max_length=30)
|
||||
|
@ -176,6 +181,7 @@ class UserProfileForm(forms.ModelForm):
|
|||
model = CofProfile
|
||||
fields = ("phone", "mailing_cof", "mailing_bda", "mailing_bda_revente", )
|
||||
|
||||
|
||||
class RegistrationUserForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kw):
|
||||
super(RegistrationUserForm, self).__init__(*args, **kw)
|
||||
|
@ -185,6 +191,7 @@ class RegistrationUserForm(forms.ModelForm):
|
|||
model = User
|
||||
fields = ("username", "first_name", "last_name", "email")
|
||||
|
||||
|
||||
class RegistrationProfileForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kw):
|
||||
super(RegistrationProfileForm, self).__init__(*args, **kw)
|
||||
|
@ -230,6 +237,7 @@ STATUS_CHOICES = (('no','Non'),
|
|||
('wait', 'Oui mais attente paiement'),
|
||||
('paid', 'Oui payé'),)
|
||||
|
||||
|
||||
class AdminEventForm(forms.Form):
|
||||
status = forms.ChoiceField(label="Inscription", choices=STATUS_CHOICES, widget=RadioSelect)
|
||||
|
||||
|
@ -239,9 +247,9 @@ class AdminEventForm(forms.Form):
|
|||
registration = kwargs.pop("current_registration", None)
|
||||
current_choices = registration.options.all() if registration is not None else []
|
||||
paid = kwargs.pop("paid", None)
|
||||
if paid == True:
|
||||
if paid is True:
|
||||
kwargs["initial"] = {"status": "paid"}
|
||||
elif paid == False:
|
||||
elif paid is False:
|
||||
kwargs["initial"] = {"status": "wait"}
|
||||
else:
|
||||
kwargs["initial"] = {"status": "no"}
|
||||
|
@ -295,4 +303,3 @@ class AdminEventForm(forms.Form):
|
|||
for name, value in self.cleaned_data.items():
|
||||
if name.startswith('comment_'):
|
||||
yield (self.fields[name].comment_id, value)
|
||||
|
||||
|
|
|
@ -29,9 +29,11 @@ TYPE_COMMENT_FIELD = (
|
|||
('char', _(u"Texte court")),
|
||||
)
|
||||
|
||||
|
||||
def choices_length(choices):
|
||||
return reduce(lambda m, choice: max(m, len(choice[0])), choices, 0)
|
||||
|
||||
|
||||
class CofProfile(models.Model):
|
||||
user = models.OneToOneField(User, related_name="profile")
|
||||
login_clipper = models.CharField("Login clipper", max_length=8, blank=True)
|
||||
|
@ -45,7 +47,6 @@ class CofProfile(models.Model):
|
|||
departement = models.CharField(_(u"Département"), max_length=50, blank=True)
|
||||
type_cotiz = models.CharField(_(u"Type de cotisation"),
|
||||
default="normalien",
|
||||
choices = TYPE_COTIZ_CHOICES,
|
||||
max_length=choices_length(TYPE_COTIZ_CHOICES))
|
||||
mailing_cof = models.BooleanField("Recevoir les mails COF", default=False)
|
||||
mailing_bda = models.BooleanField("Recevoir les mails BdA", default=False)
|
||||
|
@ -63,17 +64,20 @@ class CofProfile(models.Model):
|
|||
def __unicode__(self):
|
||||
return unicode(self.user.username)
|
||||
|
||||
|
||||
def create_user_profile(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
CofProfile.objects.get_or_create(user=instance)
|
||||
post_save.connect(create_user_profile, sender=User)
|
||||
|
||||
|
||||
class Club(models.Model):
|
||||
name = models.CharField("Nom", max_length=200)
|
||||
description = models.TextField("Description")
|
||||
respos = models.ManyToManyField(User, related_name="clubs_geres")
|
||||
membres = models.ManyToManyField(User, related_name="clubs")
|
||||
|
||||
|
||||
class CustomMail(models.Model):
|
||||
shortname = models.SlugField(max_length=50, blank=False)
|
||||
title = models.CharField("Titre", max_length=200, blank=False)
|
||||
|
@ -86,6 +90,7 @@ class CustomMail(models.Model):
|
|||
def __unicode__(self):
|
||||
return u"%s: %s" % (self.shortname, self.title)
|
||||
|
||||
|
||||
class Event(models.Model):
|
||||
title = models.CharField("Titre", max_length=200)
|
||||
location = models.CharField("Lieu", max_length=200)
|
||||
|
@ -101,6 +106,7 @@ class Event(models.Model):
|
|||
def __unicode__(self):
|
||||
return unicode(self.title)
|
||||
|
||||
|
||||
class EventCommentField(models.Model):
|
||||
event = models.ForeignKey(Event, related_name="commentfields")
|
||||
name = models.CharField("Champ", max_length=200)
|
||||
|
@ -113,11 +119,13 @@ class EventCommentField(models.Model):
|
|||
def __unicode__(self):
|
||||
return unicode(self.name)
|
||||
|
||||
|
||||
class EventCommentValue(models.Model):
|
||||
commentfield = models.ForeignKey(EventCommentField, related_name="values")
|
||||
registration = models.ForeignKey("EventRegistration", related_name="comments")
|
||||
content = models.TextField("Contenu", blank=True, null=True)
|
||||
|
||||
|
||||
class EventOption(models.Model):
|
||||
event = models.ForeignKey(Event, related_name="options")
|
||||
name = models.CharField("Option", max_length=200)
|
||||
|
@ -129,6 +137,7 @@ class EventOption(models.Model):
|
|||
def __unicode__(self):
|
||||
return unicode(self.name)
|
||||
|
||||
|
||||
class EventOptionChoice(models.Model):
|
||||
event_option = models.ForeignKey(EventOption, related_name="choices")
|
||||
value = models.CharField("Valeur", max_length=200)
|
||||
|
@ -139,6 +148,7 @@ class EventOptionChoice(models.Model):
|
|||
def __unicode__(self):
|
||||
return unicode(self.value)
|
||||
|
||||
|
||||
class EventRegistration(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
event = models.ForeignKey(Event)
|
||||
|
@ -153,6 +163,7 @@ class EventRegistration(models.Model):
|
|||
def __unicode__(self):
|
||||
return u"Inscription de %s à %s" % (unicode(self.user), unicode(self.event.title))
|
||||
|
||||
|
||||
class Survey(models.Model):
|
||||
title = models.CharField("Titre", max_length=200)
|
||||
details = models.TextField("Détails", blank=True)
|
||||
|
@ -165,6 +176,7 @@ class Survey(models.Model):
|
|||
def __unicode__(self):
|
||||
return unicode(self.title)
|
||||
|
||||
|
||||
class SurveyQuestion(models.Model):
|
||||
survey = models.ForeignKey(Survey, related_name="questions")
|
||||
question = models.CharField("Question", max_length=200)
|
||||
|
@ -176,6 +188,7 @@ class SurveyQuestion(models.Model):
|
|||
def __unicode__(self):
|
||||
return unicode(self.question)
|
||||
|
||||
|
||||
class SurveyQuestionAnswer(models.Model):
|
||||
survey_question = models.ForeignKey(SurveyQuestion, related_name="answers")
|
||||
answer = models.CharField("Réponse", max_length=200)
|
||||
|
@ -186,6 +199,7 @@ class SurveyQuestionAnswer(models.Model):
|
|||
def __unicode__(self):
|
||||
return unicode(self.answer)
|
||||
|
||||
|
||||
class SurveyAnswer(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
survey = models.ForeignKey(Survey)
|
||||
|
@ -195,6 +209,7 @@ class SurveyAnswer(models.Model):
|
|||
verbose_name = "Réponses"
|
||||
unique_together = ("user", "survey")
|
||||
|
||||
|
||||
class Clipper(models.Model):
|
||||
username = models.CharField("Identifiant", max_length=20)
|
||||
fullname = models.CharField("Nom complet", max_length=200)
|
||||
|
|
|
@ -26,11 +26,13 @@ from datetime import datetime
|
|||
import base64
|
||||
import simplejson
|
||||
|
||||
|
||||
def render_template(template_path, data):
|
||||
tmpl = loader.get_template(template_path)
|
||||
context = Context(data)
|
||||
return tmpl.render(context)
|
||||
|
||||
|
||||
class DemandeListView(ListView):
|
||||
model = PetitCoursDemande
|
||||
template_name = "petits_cours_demandes_list.html"
|
||||
|
@ -43,6 +45,7 @@ class DemandeListView(ListView):
|
|||
def dispatch(self, *args, **kwargs):
|
||||
return super(DemandeListView, self).dispatch(*args, **kwargs)
|
||||
|
||||
|
||||
@buro_required
|
||||
def details(request, demande_id):
|
||||
demande = get_object_or_404(PetitCoursDemande, id=demande_id)
|
||||
|
@ -51,6 +54,7 @@ def details(request, demande_id):
|
|||
{"demande": demande,
|
||||
"attributions": attributions})
|
||||
|
||||
|
||||
def _get_attrib_counter(user, matiere):
|
||||
counter, created = PetitCoursAttributionCounter.objects.get_or_create(user=user,
|
||||
matiere=matiere)
|
||||
|
@ -60,6 +64,7 @@ def _get_attrib_counter(user, matiere):
|
|||
counter.save()
|
||||
return counter
|
||||
|
||||
|
||||
def _get_demande_candidates(demande, redo=False):
|
||||
for matiere in demande.matieres.all():
|
||||
candidates = PetitCoursAbility.objects.filter(matiere=matiere, niveau=demande.niveau)
|
||||
|
@ -75,6 +80,7 @@ def _get_demande_candidates(demande, redo = False):
|
|||
candidates = candidates.order_by('?').select_related().all()
|
||||
yield (matiere, candidates)
|
||||
|
||||
|
||||
@buro_required
|
||||
def traitement(request, demande_id, redo=False):
|
||||
demande = get_object_or_404(PetitCoursDemande, id=demande_id)
|
||||
|
@ -110,10 +116,12 @@ def traitement(request, demande_id, redo = False):
|
|||
return _finalize_traitement(request, demande, proposals,
|
||||
proposed_for, unsatisfied, attribdata, redo)
|
||||
|
||||
|
||||
@buro_required
|
||||
def retraitement(request, demande_id):
|
||||
return traitement(request, demande_id, redo=True)
|
||||
|
||||
|
||||
def _finalize_traitement(request, demande, proposals, proposed_for,
|
||||
unsatisfied, attribdata, redo=False, errors=None):
|
||||
proposals = proposals.items()
|
||||
|
@ -136,6 +144,7 @@ def _finalize_traitement(request, demande, proposals, proposed_for,
|
|||
"errors": errors,
|
||||
})
|
||||
|
||||
|
||||
def _generate_eleve_email(demande, proposed_for):
|
||||
proposed_mails = []
|
||||
for user, matieres in proposed_for:
|
||||
|
@ -143,6 +152,7 @@ def _generate_eleve_email(demande, proposed_for):
|
|||
proposed_mails.append((user, msg))
|
||||
return proposed_mails
|
||||
|
||||
|
||||
def _traitement_other_preparing(request, demande):
|
||||
redo = "redo" in request.POST
|
||||
unsatisfied = []
|
||||
|
@ -181,6 +191,7 @@ def _traitement_other_preparing(request, demande):
|
|||
unsatisfied.append(matiere)
|
||||
return _finalize_traitement(request, demande, proposals, proposed_for, unsatisfied, attribdata, errors=errors)
|
||||
|
||||
|
||||
def _traitement_other(request, demande, redo):
|
||||
if request.method == "POST":
|
||||
if "preparing" in request.POST:
|
||||
|
@ -220,6 +231,7 @@ def _traitement_other(request, demande, redo):
|
|||
"proposed_for": proposed_for,
|
||||
})
|
||||
|
||||
|
||||
def _traitement_post(request, demande):
|
||||
proposals = {}
|
||||
proposed_for = {}
|
||||
|
@ -280,6 +292,7 @@ def _traitement_post(request, demande):
|
|||
"redo": redo,
|
||||
})
|
||||
|
||||
|
||||
class BaseMatieresFormSet(BaseInlineFormSet):
|
||||
def clean(self):
|
||||
super(BaseMatieresFormSet, self).clean()
|
||||
|
@ -298,6 +311,7 @@ class BaseMatieresFormSet(BaseInlineFormSet):
|
|||
raise forms.ValidationError("Vous ne pouvez pas vous inscrire deux fois pour la même matiere avec le même niveau.")
|
||||
matieres.append((matiere, niveau))
|
||||
|
||||
|
||||
@login_required
|
||||
def inscription(request):
|
||||
profile, created = CofProfile.objects.get_or_create(user=request.user)
|
||||
|
@ -337,6 +351,7 @@ class DemandeForm(ModelForm):
|
|||
fields = ('name', 'email', 'phone', 'quand', 'freq', 'lieu', 'matieres', 'agrege_requis', 'niveau', 'remarques')
|
||||
widgets = {'matieres': forms.CheckboxSelectMultiple}
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def demande(request):
|
||||
success = False
|
||||
|
@ -349,6 +364,7 @@ def demande(request):
|
|||
form = DemandeForm()
|
||||
return render(request, "demande-petit-cours.html", {"form": form, "success": success})
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def demande_raw(request):
|
||||
success = False
|
||||
|
|
|
@ -12,6 +12,7 @@ from gestioncof.models import CofProfile, CustomMail
|
|||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class COFCASBackend(CASBackend):
|
||||
def authenticate_cas(self, ticket, service, request):
|
||||
"""Verifies CAS ticket and gets or creates User object"""
|
||||
|
@ -57,6 +58,7 @@ class COFCASBackend(CASBackend):
|
|||
user.save()
|
||||
return user
|
||||
|
||||
|
||||
def context_processor(request):
|
||||
'''Append extra data to the context of the given request'''
|
||||
data = {
|
||||
|
@ -65,17 +67,20 @@ def context_processor (request):
|
|||
}
|
||||
return data
|
||||
|
||||
|
||||
def lock_table(*models):
|
||||
query = "LOCK TABLES "
|
||||
for i, model in enumerate(models):
|
||||
table = model._meta.db_table
|
||||
if i > 0: query += ", "
|
||||
if i > 0:
|
||||
query += ", "
|
||||
query += "%s WRITE" % table
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(query)
|
||||
row = cursor.fetchone()
|
||||
return row
|
||||
|
||||
|
||||
def unlock_tables(*models):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("UNLOCK TABLES")
|
||||
|
@ -84,8 +89,10 @@ def unlock_tables(*models):
|
|||
|
||||
unlock_table = unlock_tables
|
||||
|
||||
|
||||
def send_custom_mail(to, shortname, context=None, from_email="cof@ens.fr"):
|
||||
if context is None: context = {}
|
||||
if context is None:
|
||||
context = {}
|
||||
if isinstance(to, DjangoUser):
|
||||
context["nom"] = to.get_full_name()
|
||||
context["prenom"] = to.first_name
|
||||
|
|
|
@ -20,6 +20,7 @@ from gestioncof.forms import UserProfileForm, EventStatusFilterForm, \
|
|||
|
||||
from bda.models import Tirage
|
||||
|
||||
|
||||
@login_required
|
||||
def home(request):
|
||||
data = {"surveys": Survey.objects.filter(old=False).all(),
|
||||
|
@ -29,11 +30,13 @@ def home(request):
|
|||
"open_tirages": Tirage.objects.filter(active=True).all()}
|
||||
return render(request, "home.html", data)
|
||||
|
||||
|
||||
def login(request):
|
||||
if request.user.is_authenticated():
|
||||
return redirect("gestioncof.views.home")
|
||||
return render(request, "login_switch.html", {})
|
||||
|
||||
|
||||
def login_ext(request):
|
||||
if request.method == "POST" and "username" in request.POST:
|
||||
try:
|
||||
|
@ -48,6 +51,7 @@ def login_ext(request):
|
|||
pass
|
||||
return django_login_view(request, template_name='login.html')
|
||||
|
||||
|
||||
@login_required
|
||||
def logout(request):
|
||||
try:
|
||||
|
@ -59,6 +63,7 @@ def logout(request):
|
|||
else:
|
||||
return redirect("django.contrib.auth.views.logout")
|
||||
|
||||
|
||||
@login_required
|
||||
def survey(request, survey_id):
|
||||
survey = get_object_or_404(Survey, id=survey_id)
|
||||
|
@ -113,6 +118,7 @@ def survey(request, survey_id):
|
|||
form = SurveyForm(survey=survey)
|
||||
return render(request, "survey.html", {"survey": survey, "form": form, "success": success, "deleted": deleted, "current_answer": current_answer})
|
||||
|
||||
|
||||
def get_event_form_choices(event, form):
|
||||
all_choices = []
|
||||
for option_id, choices_ids in form.choices():
|
||||
|
@ -143,6 +149,7 @@ def update_event_form_comments(event, form, registration):
|
|||
storage.content = value
|
||||
storage.save()
|
||||
|
||||
|
||||
@login_required
|
||||
def event(request, event_id):
|
||||
event = get_object_or_404(Event, id=event_id)
|
||||
|
@ -205,6 +212,7 @@ def event_status(request, event_id):
|
|||
choices_count[choice.id] += 1
|
||||
return render(request, "event_status.html", {"event": event, "user_choices": user_choices, "options": options, "choices_count": choices_count, "form": form})
|
||||
|
||||
|
||||
@buro_required
|
||||
def survey_status(request, survey_id):
|
||||
survey = get_object_or_404(Survey, id=survey_id)
|
||||
|
@ -231,6 +239,7 @@ def survey_status(request, survey_id):
|
|||
answers_count[answer.id] += 1
|
||||
return render(request, "survey_status.html", {"survey": survey, "user_answers": user_answers, "questions": questions, "answers_count": answers_count, "form": form})
|
||||
|
||||
|
||||
@login_required
|
||||
def profile(request):
|
||||
success = False
|
||||
|
@ -243,10 +252,12 @@ def profile(request):
|
|||
form = UserProfileForm(instance=request.user.profile)
|
||||
return render(request, "profile.html", {"form": form, "success": success})
|
||||
|
||||
|
||||
def registration_set_ro_fields(user_form, profile_form):
|
||||
user_form.fields['username'].widget.attrs['readonly'] = True
|
||||
profile_form.fields['login_clipper'].widget.attrs['readonly'] = True
|
||||
|
||||
|
||||
@buro_required
|
||||
def registration_form(request, login_clipper=None, username=None):
|
||||
member = None
|
||||
|
@ -328,6 +339,7 @@ def registration_form2(request, login_clipper = None, username = None):
|
|||
event_forms = [AdminEventForm(event=event) for event in events]
|
||||
return render(request, "registration_form.html", {"user_form": user_form, "profile_form": profile_form, "member": member, "login_clipper": login_clipper, "event_forms": event_forms})
|
||||
|
||||
|
||||
@buro_required
|
||||
def registration(request):
|
||||
if request.POST:
|
||||
|
@ -341,7 +353,8 @@ def registration(request):
|
|||
event_forms = [AdminEventForm(request_dict, event=event) for event in events]
|
||||
user_form.is_valid()
|
||||
profile_form.is_valid()
|
||||
for event_form in event_forms: event_form.is_valid()
|
||||
for event_form in event_forms:
|
||||
event_form.is_valid()
|
||||
member = None
|
||||
login_clipper = None
|
||||
if "user_exists" in request_dict and request_dict["user_exists"]:
|
||||
|
@ -358,8 +371,10 @@ def registration(request):
|
|||
except Clipper.DoesNotExist:
|
||||
pass
|
||||
for form in event_forms:
|
||||
if not form.is_valid(): break
|
||||
if form.cleaned_data['status'] == 'no': continue
|
||||
if not form.is_valid():
|
||||
break
|
||||
if form.cleaned_data['status'] == 'no':
|
||||
continue
|
||||
all_choices = get_event_form_choices(form.event, form)
|
||||
if user_form.is_valid() and profile_form.is_valid() and not any([not form.is_valid() for form in event_forms]):
|
||||
member = user_form.save()
|
||||
|
@ -398,6 +413,7 @@ def registration(request):
|
|||
else:
|
||||
return render(request, "registration.html")
|
||||
|
||||
|
||||
@buro_required
|
||||
def export_members(request):
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
|
@ -411,6 +427,7 @@ def export_members(request):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@buro_required
|
||||
def csv_export_mega(filename, qs):
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
|
@ -426,6 +443,7 @@ def csv_export_mega(filename, qs):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@buro_required
|
||||
def export_mega_remarksonly(request):
|
||||
filename = 'remarques_mega_2015.csv'
|
||||
|
@ -444,6 +462,7 @@ def export_mega_remarksonly(request):
|
|||
|
||||
return response
|
||||
|
||||
|
||||
@buro_required
|
||||
def export_mega_bytype(request, type):
|
||||
types = {"orga-actif": "Orga élève",
|
||||
|
@ -460,6 +479,7 @@ def export_mega_bytype(request, type):
|
|||
qs = EventRegistration.objects.filter(event=event).filter(options__id__exact=participant_type)
|
||||
return csv_export_mega(type + '_mega_2015.csv', qs)
|
||||
|
||||
|
||||
@buro_required
|
||||
def export_mega_orgas(request):
|
||||
event = Event.objects.get(title="Mega 15")
|
||||
|
@ -469,6 +489,7 @@ def export_mega_orgas(request):
|
|||
qs = EventRegistration.objects.filter(event=event).exclude(options__id__in=(participant_type_a, participant_type_b))
|
||||
return csv_export_mega('orgas_mega_15.csv', qs)
|
||||
|
||||
|
||||
@buro_required
|
||||
def export_mega_participants(request):
|
||||
event = Event.objects.get(title="Mega 15")
|
||||
|
@ -478,36 +499,41 @@ def export_mega_participants(request):
|
|||
qs = EventRegistration.objects.filter(event=event).filter(options__id__in=(participant_type_a, participant_type_b))
|
||||
return csv_export_mega('participants_mega_15.csv', qs)
|
||||
|
||||
|
||||
@buro_required
|
||||
def export_mega(request):
|
||||
event = Event.objects.filter(title="Mega 15")
|
||||
qs = EventRegistration.objects.filter(event=event).order_by("user__username")
|
||||
return csv_export_mega('all_mega_2015.csv', qs)
|
||||
|
||||
|
||||
@buro_required
|
||||
def utile_cof(request):
|
||||
return render(request, "utile_cof.html", {})
|
||||
|
||||
|
||||
@buro_required
|
||||
def utile_bda(request):
|
||||
tirages = Tirage.objects.all()
|
||||
return render(request, "utile_bda.html", {'tirages': tirages})
|
||||
|
||||
|
||||
@buro_required
|
||||
def liste_bdadiff(request):
|
||||
titre = "BdA diffusion"
|
||||
personnes = CofProfile.objects.filter(mailing_bda=True, is_cof=True).all()
|
||||
return render(request, "liste_mails.html", {"titre": titre, "personnes": personnes})
|
||||
|
||||
|
||||
@buro_required
|
||||
def liste_bdarevente(request):
|
||||
titre = "BdA revente"
|
||||
personnes = CofProfile.objects.filter(mailing_bda_revente=True, is_cof=True).all()
|
||||
return render(request, "liste_mails.html", {"titre": titre, "personnes": personnes})
|
||||
|
||||
|
||||
@buro_required
|
||||
def liste_diffcof(request):
|
||||
titre = "Diffusion COF"
|
||||
personnes = CofProfile.objects.filter(mailing_cof=True, is_cof=True).all()
|
||||
return render(request, "liste_mails.html", {"titre": titre, "personnes": personnes})
|
||||
|
||||
|
|
Loading…
Reference in a new issue