Add rights to Product and Product Type views

This commit is contained in:
Skia 2016-07-28 16:11:18 +02:00
parent 3c4a9a89a8
commit 4c62816816
2 changed files with 11 additions and 8 deletions

View File

@ -14,7 +14,7 @@ from django.db import DataError, transaction
import re import re
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
from subscription.models import Subscriber from subscription.models import Subscriber
from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType
@ -352,14 +352,14 @@ class CounterDeleteView(CanEditMixin, DeleteView):
# Product management # Product management
class ProductTypeListView(ListView): class ProductTypeListView(CanViewMixin, ListView):
""" """
A list view for the admins A list view for the admins
""" """
model = ProductType model = ProductType
template_name = 'counter/producttype_list.jinja' template_name = 'counter/producttype_list.jinja'
class ProductTypeCreateView(CreateView): class ProductTypeCreateView(CanCreateMixin, CreateView):
""" """
A create view for the admins A create view for the admins
""" """
@ -367,7 +367,7 @@ class ProductTypeCreateView(CreateView):
fields = ['name', 'description', 'icon'] fields = ['name', 'description', 'icon']
template_name = 'core/create.jinja' template_name = 'core/create.jinja'
class ProductTypeEditView(UpdateView): class ProductTypeEditView(CanEditPropMixin, UpdateView):
""" """
An edit view for the admins An edit view for the admins
""" """
@ -376,14 +376,14 @@ class ProductTypeEditView(UpdateView):
fields = ['name', 'description', 'icon'] fields = ['name', 'description', 'icon']
pk_url_kwarg = "type_id" pk_url_kwarg = "type_id"
class ProductListView(ListView): class ProductListView(CanViewMixin, ListView):
""" """
A list view for the admins A list view for the admins
""" """
model = Product model = Product
template_name = 'counter/product_list.jinja' template_name = 'counter/product_list.jinja'
class ProductCreateView(CreateView): class ProductCreateView(CanCreateMixin, CreateView):
""" """
A create view for the admins A create view for the admins
""" """
@ -392,7 +392,7 @@ class ProductCreateView(CreateView):
'selling_price', 'special_selling_price', 'icon', 'club'] 'selling_price', 'special_selling_price', 'icon', 'club']
template_name = 'core/create.jinja' template_name = 'core/create.jinja'
class ProductEditView(UpdateView): class ProductEditView(CanEditPropMixin, UpdateView):
""" """
An edit view for the admins An edit view for the admins
""" """
@ -413,7 +413,7 @@ class UserAccountView(DetailView):
pk_url_kwarg = "user_id" pk_url_kwarg = "user_id"
template_name = "counter/user_account.jinja" template_name = "counter/user_account.jinja"
def dispatch(self, request, *arg, **kwargs): def dispatch(self, request, *arg, **kwargs): # Manually validates the rights
res = super(UserAccountView, self).dispatch(request, *arg, **kwargs) res = super(UserAccountView, self).dispatch(request, *arg, **kwargs)
if (self.object.user == request.user if (self.object.user == request.user
or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name'])

View File

@ -31,6 +31,8 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
SITE_ID = 1
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
@ -38,6 +40,7 @@ INSTALLED_APPS = (
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.sites',
'django_jinja', 'django_jinja',
'core', 'core',
'club', 'club',