Empêche d'assigner un respo non membre du club
Dans l'interface admin
This commit is contained in:
parent
559ac5a39d
commit
14c9085887
1 changed files with 21 additions and 1 deletions
|
@ -4,6 +4,7 @@ from __future__ import division
|
|||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
from gestioncof.models import SurveyQuestionAnswer, SurveyQuestion, \
|
||||
CofProfile, EventOption, EventOptionChoice, Event, Club, CustomMail, \
|
||||
|
@ -232,6 +233,25 @@ class PetitCoursDemandeAdmin(admin.ModelAdmin):
|
|||
class CustomMailAdmin(admin.ModelAdmin):
|
||||
search_fields = ('shortname', 'title')
|
||||
|
||||
|
||||
class ClubAdminForm(forms.ModelForm):
|
||||
def clean(self):
|
||||
cleaned_data = super(ClubAdminForm, self).clean()
|
||||
respos = cleaned_data.get('respos')
|
||||
members = cleaned_data.get('membres')
|
||||
for respo in respos.all():
|
||||
if respo not in members:
|
||||
raise forms.ValidationError(
|
||||
"Erreur : le respo %s n'est pas membre du club."
|
||||
% respo.get_full_name())
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class ClubAdmin(admin.ModelAdmin):
|
||||
list_display = ['name']
|
||||
form = ClubAdminForm
|
||||
|
||||
|
||||
admin.site.register(Survey, SurveyAdmin)
|
||||
admin.site.register(SurveyQuestion, SurveyQuestionAdmin)
|
||||
admin.site.register(Event, EventAdmin)
|
||||
|
@ -239,7 +259,7 @@ admin.site.register(EventOption, EventOptionAdmin)
|
|||
admin.site.unregister(User)
|
||||
admin.site.register(User, UserProfileAdmin)
|
||||
admin.site.register(CofProfile)
|
||||
admin.site.register(Club)
|
||||
admin.site.register(Club, ClubAdmin)
|
||||
admin.site.register(CustomMail)
|
||||
admin.site.register(PetitCoursSubject)
|
||||
admin.site.register(PetitCoursAbility, PetitCoursAbilityAdmin)
|
||||
|
|
Loading…
Reference in a new issue