From 31ecb50c1ddcb379b05ac2957c1460e3a2ed7648 Mon Sep 17 00:00:00 2001 From: Skia Date: Fri, 5 Aug 2016 09:52:19 +0200 Subject: [PATCH] Move user account view into core --- .../templates/core}/user_account.jinja | 4 +++ core/urls.py | 1 - core/views/user.py | 29 +++++++++++++++++++ counter/views.py | 25 ---------------- 4 files changed, 33 insertions(+), 26 deletions(-) rename {counter/templates/counter => core/templates/core}/user_account.jinja (96%) diff --git a/counter/templates/counter/user_account.jinja b/core/templates/core/user_account.jinja similarity index 96% rename from counter/templates/counter/user_account.jinja rename to core/templates/core/user_account.jinja index b3098c09..c36440fb 100644 --- a/counter/templates/counter/user_account.jinja +++ b/core/templates/core/user_account.jinja @@ -5,6 +5,7 @@ {% endblock %} {% block infos %} +{% if customer %}

{% trans %}User account{% endtrans %}

{% trans %}Amount: {% endtrans %}{{ customer.amount }} €

{% if customer.refillings.exists() %} @@ -80,6 +81,9 @@ {% endif %} +{% else %} +

{% trans %}User has no account{% endtrans %}

+{% endif %} {% endblock %} diff --git a/core/urls.py b/core/urls.py index 3510443a..d7b2ff99 100644 --- a/core/urls.py +++ b/core/urls.py @@ -1,7 +1,6 @@ from django.conf.urls import url, include from core.views import * -from counter.views import UserAccountView urlpatterns = [ url(r'^$', index, name='index'), diff --git a/core/views/user.py b/core/views/user.py index 3249af0b..76d98e55 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -7,6 +7,7 @@ from django.views.generic.edit import UpdateView from django.views.generic import ListView, DetailView, TemplateView from django.forms.models import modelform_factory from django.forms import CheckboxSelectMultiple +from django.conf import settings import logging from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin @@ -132,3 +133,31 @@ class UserToolsView(TemplateView): Displays the logged user's tools """ template_name = "core/user_tools.jinja" + +class UserAccountView(DetailView): + """ + Display a user's account + """ + model = User + pk_url_kwarg = "user_id" + template_name = "core/user_account.jinja" + + def dispatch(self, request, *arg, **kwargs): # Manually validates the rights + res = super(UserAccountView, self).dispatch(request, *arg, **kwargs) + if (self.object == request.user + or request.user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) + or request.user.is_in_group(settings.SITH_GROUPS['root']['name'])): + return res + raise PermissionDenied + + def get_context_data(self, **kwargs): + kwargs = super(UserAccountView, self).get_context_data(**kwargs) + kwargs['profile'] = self.object + try: + kwargs['customer'] = self.object.customer + except: + pass + # TODO: add list of month where account has activity + return kwargs + + diff --git a/counter/views.py b/counter/views.py index c1f4fd3c..27884458 100644 --- a/counter/views.py +++ b/counter/views.py @@ -409,28 +409,3 @@ class ProductEditView(CanEditPropMixin, UpdateView): template_name = 'core/edit.jinja' # TODO: add management of the 'counters' ForeignKey -# User accounting infos - -class UserAccountView(DetailView): - """ - Display a user's account - """ - model = Customer - pk_url_kwarg = "user_id" - template_name = "counter/user_account.jinja" - - def dispatch(self, request, *arg, **kwargs): # Manually validates the rights - res = super(UserAccountView, self).dispatch(request, *arg, **kwargs) - 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['root']['name'])): - return res - raise PermissionDenied - - def get_context_data(self, **kwargs): - kwargs = super(UserAccountView, self).get_context_data(**kwargs) - kwargs['profile'] = self.object.user - # TODO: add list of month where account has activity - return kwargs - -