From 28487bc48352944f8446659551f0a05bf45cdee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Fri, 17 Jun 2016 13:26:55 +0200 Subject: [PATCH] Code cleanup --- gestioncof/admin.py | 37 +++++++++----- gestioncof/petits_cours_models.py | 81 +++++++++++++++++++------------ 2 files changed, 73 insertions(+), 45 deletions(-) diff --git a/gestioncof/admin.py b/gestioncof/admin.py index 785ab6a2..ee0f1409 100644 --- a/gestioncof/admin.py +++ b/gestioncof/admin.py @@ -9,7 +9,7 @@ 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_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): @@ -30,7 +30,8 @@ def add_link_field(target_model = '', field = '', link_text = unicode, desc_text class SurveyQuestionAnswerInline(admin.TabularInline): model = SurveyQuestionAnswer -@add_link_field(desc_text = lambda x: "Réponses", link_text = lambda x: "Éditer les réponses") +@add_link_field(desc_text=lambda x: "Réponses", + link_text=lambda x: "Éditer les réponses") class SurveyQuestionInline(admin.TabularInline): model = SurveyQuestion @@ -47,7 +48,8 @@ class SurveyAdmin(admin.ModelAdmin): class EventOptionChoiceInline(admin.TabularInline): model = EventOptionChoice -@add_link_field(desc_text = lambda x: "Choix", link_text = lambda x: "Éditer les choix") +@add_link_field(desc_text=lambda x: "Choix", + link_text=lambda x: "Éditer les choix") class EventOptionInline(admin.TabularInline): model = EventOption @@ -67,7 +69,6 @@ class EventAdmin(admin.ModelAdmin): class CofProfileInline(admin.StackedInline): model = CofProfile - #form = BaseDynamicEntityForm inline_classes = ("collapse open",) class FkeyLookup(object): @@ -80,14 +81,15 @@ class FkeyLookup(object): def __get__(self, obj, klass): if obj is None: - return self # hack required to make Django validate (if obj is None, then we're a class, and classes are callable ) - + return self # hack required to make Django validate (if obj is + # None, then we're a class, and classes are callable + # ) item = getattr(obj, self.fk) for attr in self.fkattrs: item = getattr(item, attr) return item -def ProfileInfo(field, short_description, boolean = False): +def ProfileInfo(field, short_description, boolean=False): def getter(self): try: return getattr(self.profile, field) @@ -121,9 +123,14 @@ class UserProfileAdmin(UserAdmin): return False is_cof.short_description = 'Membre du COF' is_cof.boolean = True - list_display = ('profile_num',) + UserAdmin.list_display + ('profile_login_clipper','profile_phone','profile_occupation','profile_mailing_cof','profile_mailing_bda','profile_mailing_bda_revente','is_cof','is_buro',) + list_display = ('profile_num',) + UserAdmin.list_display \ + + ( 'profile_login_clipper','profile_phone','profile_occupation', + 'profile_mailing_cof','profile_mailing_bda', + 'profile_mailing_bda_revente','is_cof','is_buro',) list_display_links = ('username','email','first_name','last_name') - list_filter = UserAdmin.list_filter + ('profile__is_cof', 'profile__is_buro', 'profile__mailing_cof', 'profile__mailing_bda') + list_filter = UserAdmin.list_filter \ + + ( 'profile__is_cof', 'profile__is_buro', 'profile__mailing_cof', + 'profile__mailing_bda') search_fields = UserAdmin.search_fields + ('profile__phone',) inlines = [ CofProfileInline, @@ -140,11 +147,13 @@ class EventRegistrationAdmin(admin.ModelAdmin): form = autocomplete_light.modelform_factory(EventRegistration, exclude=[]) list_display = ('__unicode__','event','user','paid') list_filter = ('paid',) - search_fields = ('user__username', 'user__first_name', 'user__last_name', 'user__email', 'event__title') + 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') + search_fields = ('user__username', 'user__first_name', 'user__last_name', + 'user__email', 'matiere__name', 'niveau') list_filter = ('matiere','niveau','agrege') class PetitCoursAttributionAdmin(admin.ModelAdmin): @@ -153,10 +162,12 @@ class PetitCoursAttributionAdmin(admin.ModelAdmin): class PetitCoursAttributionCounterAdmin(admin.ModelAdmin): list_display = ('user','matiere','count',) list_filter = ('matiere',) - search_fields = ('user__username', 'user__first_name', 'user__last_name', 'user__email', 'matiere__name') + search_fields = ('user__username', 'user__first_name', 'user__last_name', + 'user__email', 'matiere__name') class PetitCoursDemandeAdmin(admin.ModelAdmin): - list_display = ('name','email','agrege_requis','niveau','created','traitee','processed') + list_display = ('name','email','agrege_requis','niveau','created', + 'traitee','processed') list_filter = ('traitee','niveau') admin.site.register(Survey, SurveyAdmin) diff --git a/gestioncof/petits_cours_models.py b/gestioncof/petits_cours_models.py index b9e03794..25f7ec15 100644 --- a/gestioncof/petits_cours_models.py +++ b/gestioncof/petits_cours_models.py @@ -17,9 +17,9 @@ LEVELS_CHOICES = ( ) class PetitCoursSubject(models.Model): - name = models.CharField(_(u"Matière"), max_length = 30) - users = models.ManyToManyField(User, related_name = "petits_cours_matieres", - through = "PetitCoursAbility") + name = models.CharField(_(u"Matière"), max_length=30) + users = models.ManyToManyField(User, related_name="petits_cours_matieres", + through="PetitCoursAbility") class Meta: verbose_name = "Matière de petits cours" @@ -30,11 +30,11 @@ class PetitCoursSubject(models.Model): class PetitCoursAbility(models.Model): user = models.ForeignKey(User) - matiere = models.ForeignKey(PetitCoursSubject, verbose_name = _(u"Matière")) + matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_(u"Matière")) niveau = models.CharField (_(u"Niveau"), - choices = LEVELS_CHOICES, - max_length = choices_length (LEVELS_CHOICES)) - agrege = models.BooleanField(_(u"Agrégé"), default = False) + choices=LEVELS_CHOICES, + max_length=choices_length (LEVELS_CHOICES)) + agrege = models.BooleanField(_(u"Agrégé"), default=False) class Meta: verbose_name = "Compétence petits cours" @@ -44,27 +44,40 @@ class PetitCoursAbility(models.Model): return u"%s - %s - %s" % (self.user.username, self.matiere, self.niveau) class PetitCoursDemande(models.Model): - name = models.CharField(_(u"Nom/prénom"), max_length = 200) - email = models.CharField(_(u"Adresse email"), max_length = 300) - phone = models.CharField(_(u"Téléphone (facultatif)"), max_length = 20, blank = True) - quand = models.CharField(_(u"Quand ?"), help_text = _(u"Indiquez ici la période désirée pour les petits cours (vacances scolaires, semaine, week-end)."), max_length = 300, blank = True) - freq = models.CharField(_(u"Fréquence"), help_text = _(u"Indiquez ici la fréquence envisagée (hebdomadaire, 2 fois par semaine, ...)"), max_length = 300, blank = True) - lieu = models.CharField(_(u"Lieu (si préférence)"), help_text = _(u"Si vous avez avez une préférence sur le lieu."), max_length = 300, blank = True) + name = models.CharField(_(u"Nom/prénom"), max_length=200) + email = models.CharField(_(u"Adresse email"), max_length=300) + phone = models.CharField(_(u"Téléphone (facultatif)"), + max_length=20, blank=True) + quand = models.CharField( + _(u"Quand ?"), + help_text=_(u"Indiquez ici la période désirée pour les petits" \ + + "cours (vacances scolaires, semaine, week-end)."), + max_length=300, blank=True) + freq = models.CharField( + _(u"Fréquence"), + help_text=_(u"Indiquez ici la fréquence envisagée " \ + + "(hebdomadaire, 2 fois par semaine, ...)"), + max_length=300, blank=True) + lieu = models.CharField( + _(u"Lieu (si préférence)"), + help_text=_(u"Si vous avez avez une préférence sur le lieu."), + max_length=300, blank=True) - matieres = models.ManyToManyField(PetitCoursSubject, verbose_name = _(u"Matières"), - related_name = "demandes") - agrege_requis = models.BooleanField(_(u"Agrégé requis"), default = False) + matieres = models.ManyToManyField( + PetitCoursSubject, verbose_name=_(u"Matières"), + related_name="demandes") + agrege_requis = models.BooleanField(_(u"Agrégé requis"), default=False) niveau = models.CharField (_(u"Niveau"), - default = "", - choices = LEVELS_CHOICES, - max_length = choices_length (LEVELS_CHOICES)) + default="", + choices=LEVELS_CHOICES, + max_length=choices_length (LEVELS_CHOICES)) - remarques = models.TextField(_(u"Remarques et précisions"), blank = True) + remarques = models.TextField(_(u"Remarques et précisions"), blank=True) - traitee = models.BooleanField(_(u"Traitée"), default = False) - traitee_par = models.ForeignKey(User, blank = True, null = True) - processed = models.DateTimeField(_(u"Date de traitement"), blank = True) - created = models.DateTimeField(_(u"Date de création"), auto_now_add = True) + traitee = models.BooleanField(_(u"Traitée"), default=False) + traitee_par = models.ForeignKey(User, blank=True, null=True) + processed = models.DateTimeField(_(u"Date de traitement"), blank=True) + created = models.DateTimeField(_(u"Date de création"), auto_now_add=True) class Meta: verbose_name = "Demande de petits cours" @@ -75,27 +88,31 @@ class PetitCoursDemande(models.Model): class PetitCoursAttribution(models.Model): user = models.ForeignKey(User) - demande = models.ForeignKey(PetitCoursDemande, verbose_name = _("Demande")) - matiere = models.ForeignKey(PetitCoursSubject, verbose_name = _(u"Matière")) - date = models.DateTimeField(_(u"Date d'attribution"), auto_now_add = True) + demande = models.ForeignKey(PetitCoursDemande, verbose_name=_("Demande")) + matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_(u"Matière")) + date = models.DateTimeField(_(u"Date d'attribution"), auto_now_add=True) rank = models.IntegerField("Rang dans l'email") - selected = models.BooleanField(_(u"Sélectionné par le demandeur"), default = False) + selected = models.BooleanField(_(u"Sélectionné par le demandeur"), + default=False) class Meta: verbose_name = "Attribution de petits cours" verbose_name_plural = "Attributions de petits cours" def __unicode__(self): - return u"Attribution de la demande %d à %s pour %s" % (self.demande.id, self.user.username, self.matiere) + return u"Attribution de la demande %d à %s pour %s" \ + % (self.demande.id, self.user.username, self.matiere) class PetitCoursAttributionCounter(models.Model): user = models.ForeignKey(User) - matiere = models.ForeignKey(PetitCoursSubject, verbose_name = _("Matiere")) - count = models.IntegerField("Nombre d'envois", default = 0) + matiere = models.ForeignKey(PetitCoursSubject, verbose_name=_("Matiere")) + count = models.IntegerField("Nombre d'envois", default=0) class Meta: verbose_name = "Compteur d'attribution de petits cours" verbose_name_plural = "Compteurs d'attributions de petits cours" def __unicode__(self): - return u"%d demandes envoyées à %s pour %s" % (self.count, self.user.username, self.matiere) + return u"%d demandes envoyées à %s pour %s" \ + % (self.count, self.user.username, self.matiere) +