Commit c870f687 authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Renomme la fonction can_delete_set

parent e905fa9a
...@@ -123,7 +123,7 @@ def can_delete(model): ...@@ -123,7 +123,7 @@ def can_delete(model):
return decorator return decorator
def all_can_delete(model): def can_delete_set(model):
"""Decorator which returns a list of detable models by request user. """Decorator which returns a list of detable models by request user.
If none of them, return an error""" If none of them, return an error"""
def decorator(view): def decorator(view):
......
...@@ -479,24 +479,35 @@ class NewListRightForm(ListRightForm): ...@@ -479,24 +479,35 @@ class NewListRightForm(ListRightForm):
class DelListRightForm(Form): class DelListRightForm(Form):
"""Suppression d'un ou plusieurs groupes""" """Suppression d'un ou plusieurs groupes"""
listrights = forms.ModelMultipleChoiceField( listrights = forms.ModelMultipleChoiceField(
queryset=ListRight.objects.all(), queryset=ListRight.objects.none(),
label="Droits actuels", label="Droits actuels",
widget=forms.CheckboxSelectMultiple 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): class DelSchoolForm(Form):
"""Suppression d'une ou plusieurs écoles""" """Suppression d'une ou plusieurs écoles"""
schools = forms.ModelMultipleChoiceField( schools = forms.ModelMultipleChoiceField(
queryset=School.objects.all(), queryset=School.objects.none(),
label="Etablissements actuels", label="Etablissements actuels",
widget=forms.CheckboxSelectMultiple widget=forms.CheckboxSelectMultiple
) )
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances') instances = kwargs.pop('instances', None)
super(DelSchoolForm, self).__init__(*args, **kwargs) 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): class RightForm(ModelForm):
......
...@@ -93,7 +93,7 @@ from preferences.models import OptionalUser, GeneralOption ...@@ -93,7 +93,7 @@ from preferences.models import OptionalUser, GeneralOption
from re2o.views import form from re2o.views import form
from re2o.utils import ( 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): def password_change_action(u_form, user, request, req=False):
...@@ -500,7 +500,7 @@ def edit_school(request, school_instance, schoolid): ...@@ -500,7 +500,7 @@ def edit_school(request, school_instance, schoolid):
@login_required @login_required
@all_can_delete(School) @can_delete_set(School)
def del_school(request, instances): def del_school(request, instances):
""" Supprimer un établissement d'enseignement à la base de donnée, """ Supprimer un établissement d'enseignement à la base de donnée,
need cableur need cableur
...@@ -562,11 +562,11 @@ def edit_listright(request, listright_instance, listrightid): ...@@ -562,11 +562,11 @@ def edit_listright(request, listright_instance, listrightid):
@login_required @login_required
@permission_required('bureau') @can_delete_set(ListRight)
def del_listright(request): def del_listright(request):
""" Supprimer un ou plusieurs groupe, possible si il est vide, need droit """ Supprimer un ou plusieurs groupe, possible si il est vide, need droit
bureau """ bureau """
listright = DelListRightForm(request.POST or None) listright = DelListRightForm(request.POST or None, instances=instances)
if listright.is_valid(): if listright.is_valid():
listright_dels = listright.cleaned_data['listrights'] listright_dels = listright.cleaned_data['listrights']
for listright_del in listright_dels: for listright_del in listright_dels:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment