PEP8: Enforced other rules, including 80 cols
This commit is contained in:
parent
c7a3656ded
commit
88bccc0e60
23 changed files with 571 additions and 324 deletions
|
@ -56,10 +56,12 @@ def details(request, demande_id):
|
|||
|
||||
|
||||
def _get_attrib_counter(user, matiere):
|
||||
counter, created = PetitCoursAttributionCounter.objects.get_or_create(user=user,
|
||||
matiere=matiere)
|
||||
counter, created = PetitCoursAttributionCounter.\
|
||||
objects.get_or_create(user=user, matiere=matiere)
|
||||
if created:
|
||||
mincount = PetitCoursAttributionCounter.objects.filter(matiere=matiere).exclude(user=user).all().aggregate(Min('count'))
|
||||
mincount = PetitCoursAttributionCounter.objects.\
|
||||
filter(matiere=matiere).exclude(user=user).all().\
|
||||
aggregate(Min('count'))
|
||||
counter.count = mincount['count__min']
|
||||
counter.save()
|
||||
return counter
|
||||
|
@ -67,14 +69,15 @@ def _get_attrib_counter(user, matiere):
|
|||
|
||||
def _get_demande_candidates(demande, redo=False):
|
||||
for matiere in demande.matieres.all():
|
||||
candidates = PetitCoursAbility.objects.filter(matiere=matiere, niveau=demande.niveau)
|
||||
candidates = PetitCoursAbility.objects.filter(matiere=matiere,
|
||||
niveau=demande.niveau)
|
||||
candidates = candidates.filter(user__profile__is_cof=True,
|
||||
user__profile__petits_cours_accept=True)
|
||||
if demande.agrege_requis:
|
||||
candidates = candidates.filter(agrege=True)
|
||||
if redo:
|
||||
attributions = PetitCoursAttribution.objects.filter(demande=demande,
|
||||
matiere=matiere).all()
|
||||
attributions = PetitCoursAttribution.objects.\
|
||||
filter(demande=demande, matiere=matiere).all()
|
||||
for attrib in attributions:
|
||||
candidates = candidates.exclude(user=attrib.user)
|
||||
candidates = candidates.order_by('?').select_related().all()
|
||||
|
@ -131,7 +134,11 @@ def _finalize_traitement(request, demande, proposals, proposed_for,
|
|||
mainmail = render_template("petits-cours-mail-demandeur.txt",
|
||||
{"proposals": proposals,
|
||||
"unsatisfied": unsatisfied,
|
||||
"extra": "<textarea name=\"extra\" style=\"width:99%; height: 90px;\"></textarea>"})
|
||||
"extra":
|
||||
'<textarea name="extra" '
|
||||
'style="width:99%; height: 90px;">'
|
||||
'</textarea>'
|
||||
})
|
||||
return render(request, "traitement_demande_petit_cours.html",
|
||||
{"demande": demande,
|
||||
"unsatisfied": unsatisfied,
|
||||
|
@ -139,16 +146,18 @@ def _finalize_traitement(request, demande, proposals, proposed_for,
|
|||
"proposed_for": proposed_for,
|
||||
"proposed_mails": proposed_mails,
|
||||
"mainmail": mainmail,
|
||||
"attribdata": base64.b64encode(simplejson.dumps(attribdata)),
|
||||
"attribdata":
|
||||
base64.b64encode(simplejson.dumps(attribdata)),
|
||||
"redo": redo,
|
||||
"errors": errors,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
def _generate_eleve_email(demande, proposed_for):
|
||||
proposed_mails = []
|
||||
for user, matieres in proposed_for:
|
||||
msg = render_template("petits-cours-mail-eleve.txt", {"demande": demande, "matieres": matieres})
|
||||
msg = render_template("petits-cours-mail-eleve.txt",
|
||||
{"demande": demande, "matieres": matieres})
|
||||
proposed_mails.append((user, msg))
|
||||
return proposed_mails
|
||||
|
||||
|
@ -167,15 +176,18 @@ def _traitement_other_preparing(request, demande):
|
|||
attribdata[matiere.id] = []
|
||||
proposals[matiere] = []
|
||||
for choice_id in range(min(3, len(candidates))):
|
||||
choice = int(request.POST["proposal-%d-%d" % (matiere.id, choice_id)])
|
||||
choice = int(
|
||||
request.POST["proposal-%d-%d" % (matiere.id, choice_id)])
|
||||
if choice == -1:
|
||||
continue
|
||||
if choice not in candidates:
|
||||
errors.append(u"Choix invalide pour la proposition %d en %s" % (choice_id + 1, matiere))
|
||||
errors.append(u"Choix invalide pour la proposition %d"
|
||||
"en %s" % (choice_id + 1, matiere))
|
||||
continue
|
||||
user = candidates[choice]
|
||||
if user in proposals[matiere]:
|
||||
errors.append(u"La proposition %d en %s est un doublon" % (choice_id + 1, matiere))
|
||||
errors.append(u"La proposition %d en %s est un doublon" %
|
||||
(choice_id + 1, matiere))
|
||||
continue
|
||||
proposals[matiere].append(user)
|
||||
attribdata[matiere.id].append(user.id)
|
||||
|
@ -186,10 +198,14 @@ def _traitement_other_preparing(request, demande):
|
|||
if not proposals[matiere]:
|
||||
errors.append(u"Aucune proposition pour %s" % (matiere,))
|
||||
elif len(proposals[matiere]) < 3:
|
||||
errors.append(u"Seulement %d proposition%s pour %s" % (len(proposals[matiere]), "s" if len(proposals[matiere]) > 1 else "", matiere))
|
||||
errors.append(u"Seulement %d proposition%s pour %s" %
|
||||
(len(proposals[matiere]), "s"
|
||||
if len(proposals[matiere]) > 1 else "",
|
||||
matiere))
|
||||
else:
|
||||
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):
|
||||
|
@ -229,7 +245,7 @@ def _traitement_other(request, demande, redo):
|
|||
"unsatisfied": unsatisfied,
|
||||
"proposals": proposals,
|
||||
"proposed_for": proposed_for,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
def _traitement_post(request, demande):
|
||||
|
@ -270,13 +286,15 @@ def _traitement_post(request, demande):
|
|||
mails_to_send.append(msg)
|
||||
mails_to_send.append(EmailMessage("Cours particuliers ENS", mainmail,
|
||||
frommail, [demande.email],
|
||||
[bccaddress], headers={'Reply-To': replyto}))
|
||||
[bccaddress],
|
||||
headers={'Reply-To': replyto}))
|
||||
connection = mail.get_connection(fail_silently=True)
|
||||
connection.send_messages(mails_to_send)
|
||||
lock_table(PetitCoursAttributionCounter, PetitCoursAttribution, User)
|
||||
for matiere in proposals:
|
||||
for rank, user in enumerate(proposals[matiere]):
|
||||
counter = PetitCoursAttributionCounter.objects.get(user=user, matiere=matiere)
|
||||
counter = PetitCoursAttributionCounter.objects.get(user=user,
|
||||
matiere=matiere)
|
||||
counter.count += 1
|
||||
counter.save()
|
||||
attrib = PetitCoursAttribution(user=user, matiere=matiere,
|
||||
|
@ -290,14 +308,15 @@ def _traitement_post(request, demande):
|
|||
return render(request, "traitement_demande_petit_cours_success.html",
|
||||
{"demande": demande,
|
||||
"redo": redo,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
class BaseMatieresFormSet(BaseInlineFormSet):
|
||||
def clean(self):
|
||||
super(BaseMatieresFormSet, 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
|
||||
matieres = []
|
||||
for i in range(0, self.total_form_count()):
|
||||
|
@ -308,7 +327,9 @@ class BaseMatieresFormSet(BaseInlineFormSet):
|
|||
niveau = form.cleaned_data['niveau']
|
||||
delete = form.cleaned_data['DELETE']
|
||||
if not delete and (matiere, niveau) in matieres:
|
||||
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))
|
||||
|
||||
|
||||
|
@ -318,7 +339,8 @@ def inscription(request):
|
|||
if not profile.is_cof:
|
||||
return redirect("cof-denied")
|
||||
MatieresFormSet = inlineformset_factory(User, PetitCoursAbility,
|
||||
fields=("matiere", "niveau", "agrege",),
|
||||
fields=("matiere", "niveau",
|
||||
"agrege",),
|
||||
formset=BaseMatieresFormSet)
|
||||
success = False
|
||||
if request.method == "POST":
|
||||
|
@ -328,8 +350,10 @@ def inscription(request):
|
|||
profile.petits_cours_accept = "receive_proposals" in request.POST
|
||||
profile.petits_cours_remarques = request.POST["remarques"]
|
||||
profile.save()
|
||||
lock_table(PetitCoursAttributionCounter, PetitCoursAbility, User, PetitCoursSubject)
|
||||
abilities = PetitCoursAbility.objects.filter(user=request.user).all()
|
||||
lock_table(PetitCoursAttributionCounter, PetitCoursAbility, User,
|
||||
PetitCoursSubject)
|
||||
abilities = PetitCoursAbility.objects.\
|
||||
filter(user=request.user).all()
|
||||
for ability in abilities:
|
||||
counter = _get_attrib_counter(ability.user, ability.matiere)
|
||||
unlock_tables()
|
||||
|
@ -337,7 +361,11 @@ def inscription(request):
|
|||
formset = MatieresFormSet(instance=request.user)
|
||||
else:
|
||||
formset = MatieresFormSet(instance=request.user)
|
||||
return render(request, "inscription-petit-cours.html", {"formset": formset, "success": success, "receive_proposals": profile.petits_cours_accept, "remarques": profile.petits_cours_remarques})
|
||||
return render(request, "inscription-petit-cours.html",
|
||||
{"formset": formset, "success": success,
|
||||
"receive_proposals": profile.petits_cours_accept,
|
||||
"remarques": profile.petits_cours_remarques})
|
||||
|
||||
|
||||
class DemandeForm(ModelForm):
|
||||
captcha = ReCaptchaField(attrs={'theme': 'clean', 'lang': 'fr'})
|
||||
|
@ -348,7 +376,8 @@ class DemandeForm(ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = PetitCoursDemande
|
||||
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}
|
||||
|
||||
|
||||
|
@ -362,7 +391,8 @@ def demande(request):
|
|||
success = True
|
||||
else:
|
||||
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
|
||||
|
@ -375,4 +405,5 @@ def demande_raw(request):
|
|||
success = True
|
||||
else:
|
||||
form = DemandeForm()
|
||||
return render(request, "demande-petit-cours-raw.html", {"form": form, "success": success})
|
||||
return render(request, "demande-petit-cours-raw.html",
|
||||
{"form": form, "success": success})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue