8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Can_delete_set sur preferences et cotisations

This commit is contained in:
Gabriel Detraz 2017-12-13 18:56:16 +01:00 committed by root
parent c870f6871c
commit f9a7270c27
4 changed files with 57 additions and 18 deletions

View file

@ -180,11 +180,19 @@ class DelArticleForm(Form):
"""Suppression d'un ou plusieurs articles en vente. Choix
parmis les modèles"""
articles = forms.ModelMultipleChoiceField(
queryset=Article.objects.all(),
queryset=Article.objects.none(),
label="Articles actuels",
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelArticleForm, self).__init__(*args, **kwargs)
if instances:
self.fields['articles'].queryset = instances
else:
self.fields['articles'].queryset = Article.objects.all()
class PaiementForm(ModelForm):
"""Creation d'un moyen de paiement, champ text moyen et type
@ -204,11 +212,19 @@ class DelPaiementForm(Form):
"""Suppression d'un ou plusieurs moyens de paiements, selection
parmis les models"""
paiements = forms.ModelMultipleChoiceField(
queryset=Paiement.objects.all(),
queryset=Paiement.objects.none(),
label="Moyens de paiement actuels",
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelPaiementForm, self).__init__(*args, **kwargs)
if instances:
self.fields['paiements'].queryset = instances
else:
self.fields['paiements'].queryset = Paiement.objects.all()
class BanqueForm(ModelForm):
"""Creation d'une banque, field name"""
@ -225,7 +241,15 @@ class BanqueForm(ModelForm):
class DelBanqueForm(Form):
"""Selection d'une ou plusieurs banques, pour suppression"""
banques = forms.ModelMultipleChoiceField(
queryset=Banque.objects.all(),
queryset=Banque.objects.none(),
label="Banques actuelles",
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelBanqueForm, self).__init__(*args, **kwargs)
if instances:
self.fields['banques'].queryset = instances
else:
self.fields['banques'].queryset = Banque.objects.all()

View file

@ -43,7 +43,14 @@ from users.models import User
from re2o.settings import LOGO_PATH
from re2o import settings
from re2o.views import form
from re2o.utils import SortTable, can_create, can_edit, can_delete, can_view
from re2o.utils import (
SortTable,
can_create,
can_edit,
can_delete,
can_view,
can_delete_set
)
from preferences.models import OptionalUser, AssoOption, GeneralOption
from .models import Facture, Article, Vente, Paiement, Banque
from .forms import (
@ -374,10 +381,10 @@ def edit_article(request, article_instance, articleid):
@login_required
@permission_required('tresorier')
def del_article(request):
@can_delete_set(Article)
def del_article(request, instances):
"""Suppression d'un article en vente"""
article = DelArticleForm(request.POST or None)
article = DelArticleForm(request.POST or None, instances=instances)
if article.is_valid():
article_del = article.cleaned_data['articles']
with transaction.atomic(), reversion.create_revision():
@ -424,10 +431,10 @@ def edit_paiement(request, paiement_instance, paiementid):
@login_required
@permission_required('tresorier')
def del_paiement(request):
@can_delete_set(Paiement)
def del_paiement(request, instances):
"""Suppression d'un moyen de paiement"""
paiement = DelPaiementForm(request.POST or None)
paiement = DelPaiementForm(request.POST or None, instances=instances)
if paiement.is_valid():
paiement_dels = paiement.cleaned_data['paiements']
for paiement_del in paiement_dels:
@ -485,10 +492,10 @@ def edit_banque(request, banque_instance, banqueid):
@login_required
@permission_required('tresorier')
def del_banque(request):
@can_delete_set(Banque)
def del_banque(request, instances):
"""Supprime une banque"""
banque = DelBanqueForm(request.POST or None)
banque = DelBanqueForm(request.POST or None, instances=instances)
if banque.is_valid():
banque_dels = banque.cleaned_data['banques']
for banque_del in banque_dels:

View file

@ -173,7 +173,15 @@ class ServiceForm(ModelForm):
class DelServiceForm(Form):
"""Suppression de services sur la page d'accueil"""
services = forms.ModelMultipleChoiceField(
queryset=Service.objects.all(),
queryset=Service.objects.none(),
label="Enregistrements service actuels",
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelServiceForm, self).__init__(*args, **kwargs)
if instances:
self.fields['services'].queryset = instances
else:
self.fields['services'].queryset = Service.objects.all()

View file

@ -42,7 +42,7 @@ from reversion.models import Version
from reversion import revisions as reversion
from re2o.views import form
from re2o.utils import can_create, can_edit
from re2o.utils import can_create, can_edit, can_delete_set
from .forms import ServiceForm, DelServiceForm
from .models import Service, OptionalUser, OptionalMachine, AssoOption
from .models import MailMessageOption, GeneralOption, OptionalTopologie
@ -149,10 +149,10 @@ def edit_service(request, service_instance, serviceid):
@login_required
@permission_required('admin')
def del_services(request):
@can_delete_set(Service)
def del_services(request, instances):
"""Suppression d'un service de la page d'accueil"""
services = DelServiceForm(request.POST or None)
services = DelServiceForm(request.POST or None, instances=instances)
if services.is_valid():
services_dels = services.cleaned_data['services']
for services_del in services_dels: