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"
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s - %s" % (self.user.username,
|
||||
self.matiere, self.niveau)
|
||||
return "{:s} - {!s} - {:s}".format(
|
||||
self.user.username, self.matiere, self.niveau
|
||||
)
|
||||
|
||||
|
||||
class PetitCoursDemande(models.Model):
|
||||
|
@ -63,7 +64,7 @@ class PetitCoursDemande(models.Model):
|
|||
freq = models.CharField(
|
||||
_("Fréquence"),
|
||||
help_text=_("Indiquez ici la fréquence envisagée "
|
||||
+ "(hebdomadaire, 2 fois par semaine, ...)"),
|
||||
"(hebdomadaire, 2 fois par semaine, ...)"),
|
||||
max_length=300, blank=True)
|
||||
lieu = models.CharField(
|
||||
_("Lieu (si préférence)"),
|
||||
|
@ -92,8 +93,9 @@ class PetitCoursDemande(models.Model):
|
|||
verbose_name_plural = "Demandes de petits cours"
|
||||
|
||||
def __str__(self):
|
||||
return "Demande %d du %s" % (self.id,
|
||||
self.created.strftime("%d %b %Y"))
|
||||
return "Demande {:d} du {:s}".format(
|
||||
self.id, self.created.strftime("%d %b %Y")
|
||||
)
|
||||
|
||||
|
||||
class PetitCoursAttribution(models.Model):
|
||||
|
@ -110,8 +112,9 @@ class PetitCoursAttribution(models.Model):
|
|||
verbose_name_plural = "Attributions de petits cours"
|
||||
|
||||
def __str__(self):
|
||||
return "Attribution de la demande %d à %s pour %s" \
|
||||
% (self.demande.id, self.user.username, self.matiere)
|
||||
return "Attribution de la demande {:d} à {:s} pour {!s}".format(
|
||||
self.demande.id, self.user.username, self.matiere
|
||||
)
|
||||
|
||||
|
||||
class PetitCoursAttributionCounter(models.Model):
|
||||
|
@ -124,5 +127,6 @@ class PetitCoursAttributionCounter(models.Model):
|
|||
verbose_name_plural = "Compteurs d'attributions de petits cours"
|
||||
|
||||
def __str__(self):
|
||||
return "%d demandes envoyées à %s pour %s" \
|
||||
% (self.count, self.user.username, self.matiere)
|
||||
return "{:d} demandes envoyées à {:s} pour {!s}".format(
|
||||
self.count, self.user.username, self.matiere
|
||||
)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.core import mail
|
||||
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 gestioncof.models import CofProfile
|
||||
from gestioncof.petits_cours_models import PetitCoursDemande, \
|
||||
PetitCoursAttribution, PetitCoursAttributionCounter, PetitCoursAbility, \
|
||||
PetitCoursSubject
|
||||
from gestioncof.petits_cours_models import (
|
||||
PetitCoursDemande, PetitCoursAttribution, PetitCoursAttributionCounter,
|
||||
PetitCoursAbility, PetitCoursSubject
|
||||
)
|
||||
from gestioncof.decorators import buro_required
|
||||
from gestioncof.shared import lock_table, unlock_tables
|
||||
|
||||
from captcha.fields import ReCaptchaField
|
||||
|
||||
from datetime import datetime
|
||||
import base64
|
||||
import json
|
||||
|
||||
|
||||
class DemandeListView(ListView):
|
||||
model = PetitCoursDemande
|
||||
|
@ -174,17 +174,19 @@ def _traitement_other_preparing(request, demande):
|
|||
proposals[matiere] = []
|
||||
for choice_id in range(min(3, len(candidates))):
|
||||
choice = int(
|
||||
request.POST["proposal-%d-%d" % (matiere.id, choice_id)])
|
||||
request.POST["proposal-{:d}-{:d}"
|
||||
.format(matiere.id, choice_id)]
|
||||
)
|
||||
if choice == -1:
|
||||
continue
|
||||
if choice not in candidates:
|
||||
errors.append("Choix invalide pour la proposition %d"
|
||||
"en %s" % (choice_id + 1, matiere))
|
||||
errors.append("Choix invalide pour la proposition {:d}"
|
||||
"en {!s}".format(choice_id + 1, matiere))
|
||||
continue
|
||||
user = candidates[choice]
|
||||
if user in proposals[matiere]:
|
||||
errors.append("La proposition %d en %s est un doublon"
|
||||
% (choice_id + 1, matiere))
|
||||
errors.append("La proposition {:d} en {!s} est un doublon"
|
||||
.format(choice_id + 1, matiere))
|
||||
continue
|
||||
proposals[matiere].append(user)
|
||||
attribdata[matiere.id].append(user.id)
|
||||
|
@ -193,10 +195,11 @@ def _traitement_other_preparing(request, demande):
|
|||
else:
|
||||
proposed_for[user].append(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:
|
||||
errors.append("Seulement %d proposition%s pour %s"
|
||||
% (len(proposals[matiere]),
|
||||
errors.append("Seulement {:d} proposition{:s} pour {!s}"
|
||||
.format(
|
||||
len(proposals[matiere]),
|
||||
"s" if len(proposals[matiere]) > 1 else "",
|
||||
matiere))
|
||||
else:
|
||||
|
@ -350,8 +353,9 @@ def inscription(request):
|
|||
profile.save()
|
||||
lock_table(PetitCoursAttributionCounter, PetitCoursAbility, User,
|
||||
PetitCoursSubject)
|
||||
abilities = PetitCoursAbility.objects \
|
||||
.filter(user=request.user).all()
|
||||
abilities = (
|
||||
PetitCoursAbility.objects.filter(user=request.user).all()
|
||||
)
|
||||
for ability in abilities:
|
||||
_get_attrib_counter(ability.user, ability.matiere)
|
||||
unlock_tables()
|
||||
|
|
Loading…
Reference in a new issue