mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Renomme la fonction can_delete_set
This commit is contained in:
parent
e905fa9aef
commit
c870f6871c
3 changed files with 20 additions and 9 deletions
|
@ -123,7 +123,7 @@ def can_delete(model):
|
|||
return decorator
|
||||
|
||||
|
||||
def all_can_delete(model):
|
||||
def can_delete_set(model):
|
||||
"""Decorator which returns a list of detable models by request user.
|
||||
If none of them, return an error"""
|
||||
def decorator(view):
|
||||
|
|
|
@ -479,24 +479,35 @@ class NewListRightForm(ListRightForm):
|
|||
class DelListRightForm(Form):
|
||||
"""Suppression d'un ou plusieurs groupes"""
|
||||
listrights = forms.ModelMultipleChoiceField(
|
||||
queryset=ListRight.objects.all(),
|
||||
queryset=ListRight.objects.none(),
|
||||
label="Droits actuels",
|
||||
widget=forms.CheckboxSelectMultiple
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
instances = kwargs.pop('instances', None)
|
||||
super(DelListRightForm, self).__init__(*args, **kwargs)
|
||||
if instances:
|
||||
self.fields['listrights'].queryset = instances
|
||||
else:
|
||||
self.fields['listrights'].queryset = ListRight.objects.all()
|
||||
|
||||
|
||||
class DelSchoolForm(Form):
|
||||
"""Suppression d'une ou plusieurs écoles"""
|
||||
schools = forms.ModelMultipleChoiceField(
|
||||
queryset=School.objects.all(),
|
||||
queryset=School.objects.none(),
|
||||
label="Etablissements actuels",
|
||||
widget=forms.CheckboxSelectMultiple
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
instances = kwargs.pop('instances')
|
||||
instances = kwargs.pop('instances', None)
|
||||
super(DelSchoolForm, self).__init__(*args, **kwargs)
|
||||
self.fields['schools'].queryset = instances
|
||||
if instances:
|
||||
self.fields['schools'].queryset = instances
|
||||
else:
|
||||
self.fields['schools'].queryset = School.objects.all()
|
||||
|
||||
|
||||
class RightForm(ModelForm):
|
||||
|
|
|
@ -93,7 +93,7 @@ from preferences.models import OptionalUser, GeneralOption
|
|||
|
||||
from re2o.views import form
|
||||
from re2o.utils import (
|
||||
all_has_access, SortTable, can_create, can_edit, all_can_delete, can_delete, can_view
|
||||
all_has_access, SortTable, can_create, can_edit, can_delete_set, can_delete, can_view
|
||||
)
|
||||
|
||||
def password_change_action(u_form, user, request, req=False):
|
||||
|
@ -500,7 +500,7 @@ def edit_school(request, school_instance, schoolid):
|
|||
|
||||
|
||||
@login_required
|
||||
@all_can_delete(School)
|
||||
@can_delete_set(School)
|
||||
def del_school(request, instances):
|
||||
""" Supprimer un établissement d'enseignement à la base de donnée,
|
||||
need cableur
|
||||
|
@ -562,11 +562,11 @@ def edit_listright(request, listright_instance, listrightid):
|
|||
|
||||
|
||||
@login_required
|
||||
@permission_required('bureau')
|
||||
@can_delete_set(ListRight)
|
||||
def del_listright(request):
|
||||
""" Supprimer un ou plusieurs groupe, possible si il est vide, need droit
|
||||
bureau """
|
||||
listright = DelListRightForm(request.POST or None)
|
||||
listright = DelListRightForm(request.POST or None, instances=instances)
|
||||
if listright.is_valid():
|
||||
listright_dels = listright.cleaned_data['listrights']
|
||||
for listright_del in listright_dels:
|
||||
|
|
Loading…
Reference in a new issue