forked from DGNum/gestioCOF
Style and PEP8
- Drop `%` in favour of `.format` which has a better specification - Remove a string concatenation - Remove the trailing slashes according to the PEP8: https://www.python.org/dev/peps/pep-0008/#maximum-line-length NB. We let some which will disappear in the next commit. - Remove an unused import and change the imports order
This commit is contained in:
parent
bb4e9dde4f
commit
2bc5f3d646
2 changed files with 36 additions and 28 deletions
|
@ -46,8 +46,9 @@ class PetitCoursAbility(models.Model):
|
||||||
verbose_name_plural = "Compétences des petits cours"
|
verbose_name_plural = "Compétences des petits cours"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s - %s - %s" % (self.user.username,
|
return "{:s} - {!s} - {:s}".format(
|
||||||
self.matiere, self.niveau)
|
self.user.username, self.matiere, self.niveau
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PetitCoursDemande(models.Model):
|
class PetitCoursDemande(models.Model):
|
||||||
|
@ -63,7 +64,7 @@ class PetitCoursDemande(models.Model):
|
||||||
freq = models.CharField(
|
freq = models.CharField(
|
||||||
_("Fréquence"),
|
_("Fréquence"),
|
||||||
help_text=_("Indiquez ici la fréquence envisagée "
|
help_text=_("Indiquez ici la fréquence envisagée "
|
||||||
+ "(hebdomadaire, 2 fois par semaine, ...)"),
|
"(hebdomadaire, 2 fois par semaine, ...)"),
|
||||||
max_length=300, blank=True)
|
max_length=300, blank=True)
|
||||||
lieu = models.CharField(
|
lieu = models.CharField(
|
||||||
_("Lieu (si préférence)"),
|
_("Lieu (si préférence)"),
|
||||||
|
@ -92,8 +93,9 @@ class PetitCoursDemande(models.Model):
|
||||||
verbose_name_plural = "Demandes de petits cours"
|
verbose_name_plural = "Demandes de petits cours"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Demande %d du %s" % (self.id,
|
return "Demande {:d} du {:s}".format(
|
||||||
self.created.strftime("%d %b %Y"))
|
self.id, self.created.strftime("%d %b %Y")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PetitCoursAttribution(models.Model):
|
class PetitCoursAttribution(models.Model):
|
||||||
|
@ -110,8 +112,9 @@ class PetitCoursAttribution(models.Model):
|
||||||
verbose_name_plural = "Attributions de petits cours"
|
verbose_name_plural = "Attributions de petits cours"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Attribution de la demande %d à %s pour %s" \
|
return "Attribution de la demande {:d} à {:s} pour {!s}".format(
|
||||||
% (self.demande.id, self.user.username, self.matiere)
|
self.demande.id, self.user.username, self.matiere
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PetitCoursAttributionCounter(models.Model):
|
class PetitCoursAttributionCounter(models.Model):
|
||||||
|
@ -124,5 +127,6 @@ class PetitCoursAttributionCounter(models.Model):
|
||||||
verbose_name_plural = "Compteurs d'attributions de petits cours"
|
verbose_name_plural = "Compteurs d'attributions de petits cours"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%d demandes envoyées à %s pour %s" \
|
return "{:d} demandes envoyées à {:s} pour {!s}".format(
|
||||||
% (self.count, self.user.username, self.matiere)
|
self.count, self.user.username, self.matiere
|
||||||
|
)
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
|
@ -16,18 +19,15 @@ from django.contrib.auth.decorators import login_required
|
||||||
from django.db.models import Min
|
from django.db.models import Min
|
||||||
|
|
||||||
from gestioncof.models import CofProfile
|
from gestioncof.models import CofProfile
|
||||||
from gestioncof.petits_cours_models import PetitCoursDemande, \
|
from gestioncof.petits_cours_models import (
|
||||||
PetitCoursAttribution, PetitCoursAttributionCounter, PetitCoursAbility, \
|
PetitCoursDemande, PetitCoursAttribution, PetitCoursAttributionCounter,
|
||||||
PetitCoursSubject
|
PetitCoursAbility, PetitCoursSubject
|
||||||
|
)
|
||||||
from gestioncof.decorators import buro_required
|
from gestioncof.decorators import buro_required
|
||||||
from gestioncof.shared import lock_table, unlock_tables
|
from gestioncof.shared import lock_table, unlock_tables
|
||||||
|
|
||||||
from captcha.fields import ReCaptchaField
|
from captcha.fields import ReCaptchaField
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
import base64
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
class DemandeListView(ListView):
|
class DemandeListView(ListView):
|
||||||
model = PetitCoursDemande
|
model = PetitCoursDemande
|
||||||
|
@ -174,17 +174,19 @@ def _traitement_other_preparing(request, demande):
|
||||||
proposals[matiere] = []
|
proposals[matiere] = []
|
||||||
for choice_id in range(min(3, len(candidates))):
|
for choice_id in range(min(3, len(candidates))):
|
||||||
choice = int(
|
choice = int(
|
||||||
request.POST["proposal-%d-%d" % (matiere.id, choice_id)])
|
request.POST["proposal-{:d}-{:d}"
|
||||||
|
.format(matiere.id, choice_id)]
|
||||||
|
)
|
||||||
if choice == -1:
|
if choice == -1:
|
||||||
continue
|
continue
|
||||||
if choice not in candidates:
|
if choice not in candidates:
|
||||||
errors.append("Choix invalide pour la proposition %d"
|
errors.append("Choix invalide pour la proposition {:d}"
|
||||||
"en %s" % (choice_id + 1, matiere))
|
"en {!s}".format(choice_id + 1, matiere))
|
||||||
continue
|
continue
|
||||||
user = candidates[choice]
|
user = candidates[choice]
|
||||||
if user in proposals[matiere]:
|
if user in proposals[matiere]:
|
||||||
errors.append("La proposition %d en %s est un doublon"
|
errors.append("La proposition {:d} en {!s} est un doublon"
|
||||||
% (choice_id + 1, matiere))
|
.format(choice_id + 1, matiere))
|
||||||
continue
|
continue
|
||||||
proposals[matiere].append(user)
|
proposals[matiere].append(user)
|
||||||
attribdata[matiere.id].append(user.id)
|
attribdata[matiere.id].append(user.id)
|
||||||
|
@ -193,12 +195,13 @@ def _traitement_other_preparing(request, demande):
|
||||||
else:
|
else:
|
||||||
proposed_for[user].append(matiere)
|
proposed_for[user].append(matiere)
|
||||||
if not proposals[matiere]:
|
if not proposals[matiere]:
|
||||||
errors.append("Aucune proposition pour %s" % (matiere,))
|
errors.append("Aucune proposition pour {!s}".format(matiere))
|
||||||
elif len(proposals[matiere]) < 3:
|
elif len(proposals[matiere]) < 3:
|
||||||
errors.append("Seulement %d proposition%s pour %s"
|
errors.append("Seulement {:d} proposition{:s} pour {!s}"
|
||||||
% (len(proposals[matiere]),
|
.format(
|
||||||
"s" if len(proposals[matiere]) > 1 else "",
|
len(proposals[matiere]),
|
||||||
matiere))
|
"s" if len(proposals[matiere]) > 1 else "",
|
||||||
|
matiere))
|
||||||
else:
|
else:
|
||||||
unsatisfied.append(matiere)
|
unsatisfied.append(matiere)
|
||||||
return _finalize_traitement(request, demande, proposals, proposed_for,
|
return _finalize_traitement(request, demande, proposals, proposed_for,
|
||||||
|
@ -350,8 +353,9 @@ def inscription(request):
|
||||||
profile.save()
|
profile.save()
|
||||||
lock_table(PetitCoursAttributionCounter, PetitCoursAbility, User,
|
lock_table(PetitCoursAttributionCounter, PetitCoursAbility, User,
|
||||||
PetitCoursSubject)
|
PetitCoursSubject)
|
||||||
abilities = PetitCoursAbility.objects \
|
abilities = (
|
||||||
.filter(user=request.user).all()
|
PetitCoursAbility.objects.filter(user=request.user).all()
|
||||||
|
)
|
||||||
for ability in abilities:
|
for ability in abilities:
|
||||||
_get_attrib_counter(ability.user, ability.matiere)
|
_get_attrib_counter(ability.user, ability.matiere)
|
||||||
unlock_tables()
|
unlock_tables()
|
||||||
|
|
Loading…
Add table
Reference in a new issue