forked from DGNum/gestioCOF
Merge branch 'Kerl/prevent_err_500_admin' into 'master'
Kerl/prevent err 500 admin Autorise les demandes de petits cours à avoir une date de traitement nulle. Cela évite des erreurs 500 désagréables lorsqu'on veut en créer à la main (ne devrait avoir lieu qu'en débug). Related to #31 Un peu de nettoyage de code au passage. Il faut appliquer les migrations (`python manage.py migrate`) pour appliquer ce patch. See merge request !41
This commit is contained in:
commit
e637a6c301
3 changed files with 93 additions and 46 deletions
|
@ -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 <wink>)
|
||||
|
||||
return self # hack required to make Django validate (if obj is
|
||||
# None, then we're a class, and classes are callable
|
||||
# <wink>)
|
||||
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,7 +162,8 @@ 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')
|
||||
actions = ['reset',]
|
||||
actions_on_bottom = True
|
||||
|
||||
|
@ -161,9 +171,9 @@ class PetitCoursAttributionCounterAdmin(admin.ModelAdmin):
|
|||
queryset.update(count=0)
|
||||
reset.short_description = u"Remise à zéro du compteur"
|
||||
|
||||
|
||||
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)
|
||||
|
|
19
gestioncof/migrations/0002_enable_unprocessed_demandes.py
Normal file
19
gestioncof/migrations/0002_enable_unprocessed_demandes.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('gestioncof', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='petitcoursdemande',
|
||||
name='processed',
|
||||
field=models.DateTimeField(null=True, verbose_name='Date de traitement', blank=True),
|
||||
),
|
||||
]
|
|
@ -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,41 @@ 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, null=True)
|
||||
created = models.DateTimeField(_(u"Date de création"), auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Demande de petits cours"
|
||||
|
@ -75,27 +89,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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue