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