diff --git a/kfet/forms.py b/kfet/forms.py index 17add53b..2127e05b 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -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): diff --git a/kfet/templates/kfet/checkout.html b/kfet/templates/kfet/checkout.html index 43d19950..55db6136 100644 --- a/kfet/templates/kfet/checkout.html +++ b/kfet/templates/kfet/checkout.html @@ -12,7 +12,7 @@
{{ checkouts|length }} caisses
- Créer un compte + Créer une caisse
diff --git a/kfet/templates/kfet/checkout_create.html b/kfet/templates/kfet/checkout_create.html index 0e283825..0f254f65 100644 --- a/kfet/templates/kfet/checkout_create.html +++ b/kfet/templates/kfet/checkout_create.html @@ -6,8 +6,10 @@ {% block content %} +{% include 'kfet/base_messages.html' %}
{% csrf_token %} + {{ form.non_field_errors}} {% for field in form %} {{ field.errors }} {{ field.label_tag }} diff --git a/kfet/templates/kfet/checkout_update.html b/kfet/templates/kfet/checkout_update.html index 2b3d9183..0a4be1ac 100644 --- a/kfet/templates/kfet/checkout_update.html +++ b/kfet/templates/kfet/checkout_update.html @@ -13,11 +13,12 @@
- {% include "kfet/base_messages.html" %} + {% include 'kfet/base_messages.html' %}
{% csrf_token %} + {{ form.non_field_errors }} {% for field in form %} {{ field.errors }} {{ field.label_tag }} diff --git a/kfet/views.py b/kfet/views.py index 3a0f6b1d..f6f88ebb 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -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)