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
|
@ -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,8 +81,9 @@ 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)
|
||||
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -46,12 +46,25 @@ class PetitCoursAbility(models.Model):
|
|||
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)
|
||||
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"),
|
||||
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"),
|
||||
|
@ -63,7 +76,8 @@ class PetitCoursDemande(models.Model):
|
|||
|
||||
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)
|
||||
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:
|
||||
|
@ -79,14 +93,16 @@ class PetitCoursAttribution(models.Model):
|
|||
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)
|
||||
|
@ -98,4 +114,6 @@ class PetitCoursAttributionCounter(models.Model):
|
|||
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