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.admin.widgets import FilteredSelectMultiple
|
||||
from django.forms import modelformset_factory
|
||||
from django.utils import timezone
|
||||
from kfet.models import (Account, Checkout, Article, OperationGroup, Operation,
|
||||
CheckoutStatement, ArticleCategory)
|
||||
from gestioncof.models import CofProfile
|
||||
|
@ -161,7 +162,9 @@ class ArticleRestrictForm(ArticleForm):
|
|||
|
||||
class KPsulOperationGroupForm(forms.ModelForm):
|
||||
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())
|
||||
class Meta:
|
||||
model = OperationGroup
|
||||
|
@ -184,7 +187,9 @@ class KPsulAccountForm(forms.ModelForm):
|
|||
|
||||
class KPsulCheckoutForm(forms.Form):
|
||||
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'}))
|
||||
|
||||
class KPsulOperationForm(forms.ModelForm):
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<div class="line">{{ checkouts|length }} caisses</div>
|
||||
</div>
|
||||
<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>
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
|
||||
{% block content %}
|
||||
|
||||
{% include 'kfet/base_messages.html' %}
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors}}
|
||||
{% for field in form %}
|
||||
{{ field.errors }}
|
||||
{{ field.label_tag }}
|
||||
|
|
|
@ -13,11 +13,12 @@
|
|||
</div>
|
||||
</div>
|
||||
<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-block">
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors }}
|
||||
{% for field in form %}
|
||||
{{ field.errors }}
|
||||
{{ field.label_tag }}
|
||||
|
|
|
@ -337,7 +337,8 @@ class CheckoutCreate(SuccessMessageMixin, CreateView):
|
|||
def form_valid(self, form):
|
||||
# Checking permission
|
||||
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
|
||||
form.instance.created_by = self.request.user.profile.account_kfet
|
||||
return super(CheckoutCreate, self).form_valid(form)
|
||||
|
@ -361,7 +362,8 @@ class CheckoutUpdate(SuccessMessageMixin, UpdateView):
|
|||
def form_valid(self, form):
|
||||
# Checking permission
|
||||
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
|
||||
return super(CheckoutUpdate, self).form_valid(form)
|
||||
|
||||
|
|
Loading…
Reference in a new issue