forked from DGNum/gestioCOF
Auth et affichage caisses
This commit is contained in:
parent
90e8ece783
commit
b628808493
5 changed files with 16 additions and 6 deletions
|
@ -4,6 +4,7 @@ from django.contrib.auth.models import User, Group, Permission
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.admin.widgets import FilteredSelectMultiple
|
from django.contrib.admin.widgets import FilteredSelectMultiple
|
||||||
from django.forms import modelformset_factory
|
from django.forms import modelformset_factory
|
||||||
|
from django.utils import timezone
|
||||||
from kfet.models import (Account, Checkout, Article, OperationGroup, Operation,
|
from kfet.models import (Account, Checkout, Article, OperationGroup, Operation,
|
||||||
CheckoutStatement, ArticleCategory)
|
CheckoutStatement, ArticleCategory)
|
||||||
from gestioncof.models import CofProfile
|
from gestioncof.models import CofProfile
|
||||||
|
@ -161,7 +162,9 @@ class ArticleRestrictForm(ArticleForm):
|
||||||
|
|
||||||
class KPsulOperationGroupForm(forms.ModelForm):
|
class KPsulOperationGroupForm(forms.ModelForm):
|
||||||
checkout = forms.ModelChoiceField(
|
checkout = forms.ModelChoiceField(
|
||||||
queryset = Checkout.objects.filter(is_protected=False),
|
queryset = Checkout.objects.filter(
|
||||||
|
is_protected=False, valid_from__lte=timezone.now(),
|
||||||
|
valid_to__gte=timezone.now()),
|
||||||
widget = forms.HiddenInput())
|
widget = forms.HiddenInput())
|
||||||
class Meta:
|
class Meta:
|
||||||
model = OperationGroup
|
model = OperationGroup
|
||||||
|
@ -184,7 +187,9 @@ class KPsulAccountForm(forms.ModelForm):
|
||||||
|
|
||||||
class KPsulCheckoutForm(forms.Form):
|
class KPsulCheckoutForm(forms.Form):
|
||||||
checkout = forms.ModelChoiceField(
|
checkout = forms.ModelChoiceField(
|
||||||
queryset=Checkout.objects.filter(is_protected=False),
|
queryset=Checkout.objects.filter(
|
||||||
|
is_protected=False, valid_from__lte=timezone.now(),
|
||||||
|
valid_to__gte=timezone.now()),
|
||||||
widget=forms.Select(attrs={'id':'id_checkout_select'}))
|
widget=forms.Select(attrs={'id':'id_checkout_select'}))
|
||||||
|
|
||||||
class KPsulOperationForm(forms.ModelForm):
|
class KPsulOperationForm(forms.ModelForm):
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<div class="line">{{ checkouts|length }} caisses</div>
|
<div class="line">{{ checkouts|length }} caisses</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a class="btn btn-primary btn-lg" href="{% url 'kfet.checkout.create' %}">Créer un compte</a>
|
<a class="btn btn-primary btn-lg" href="{% url 'kfet.checkout.create' %}">Créer une caisse</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
{% include 'kfet/base_messages.html' %}
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
{{ form.non_field_errors}}
|
||||||
{% for field in form %}
|
{% for field in form %}
|
||||||
{{ field.errors }}
|
{{ field.errors }}
|
||||||
{{ field.label_tag }}
|
{{ field.label_tag }}
|
||||||
|
|
|
@ -13,11 +13,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8 col-md-9 col-content-right">
|
<div class="col-sm-8 col-md-9 col-content-right">
|
||||||
{% include "kfet/base_messages.html" %}
|
{% include 'kfet/base_messages.html' %}
|
||||||
<div class="content-right">
|
<div class="content-right">
|
||||||
<div class="content-right-block">
|
<div class="content-right-block">
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
{{ form.non_field_errors }}
|
||||||
{% for field in form %}
|
{% for field in form %}
|
||||||
{{ field.errors }}
|
{{ field.errors }}
|
||||||
{{ field.label_tag }}
|
{{ field.label_tag }}
|
||||||
|
|
|
@ -337,7 +337,8 @@ class CheckoutCreate(SuccessMessageMixin, CreateView):
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
# Checking permission
|
# Checking permission
|
||||||
if not self.request.user.has_perm('kfet.add_checkout'):
|
if not self.request.user.has_perm('kfet.add_checkout'):
|
||||||
raise PermissionDenied
|
form.add_error(None, 'Permission refusée')
|
||||||
|
return self.form_invalid(form)
|
||||||
# Creating
|
# Creating
|
||||||
form.instance.created_by = self.request.user.profile.account_kfet
|
form.instance.created_by = self.request.user.profile.account_kfet
|
||||||
return super(CheckoutCreate, self).form_valid(form)
|
return super(CheckoutCreate, self).form_valid(form)
|
||||||
|
@ -361,7 +362,8 @@ class CheckoutUpdate(SuccessMessageMixin, UpdateView):
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
# Checking permission
|
# Checking permission
|
||||||
if not self.request.user.has_perm('kfet.change_checkout'):
|
if not self.request.user.has_perm('kfet.change_checkout'):
|
||||||
raise PermissionDenied
|
form.add_error(None, 'Permission refusée')
|
||||||
|
return self.form_invalid(form)
|
||||||
# Updating
|
# Updating
|
||||||
return super(CheckoutUpdate, self).form_valid(form)
|
return super(CheckoutUpdate, self).form_valid(form)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue