mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Move user account view into core
This commit is contained in:
90
core/templates/core/user_account.jinja
Normal file
90
core/templates/core/user_account.jinja
Normal file
@ -0,0 +1,90 @@
|
||||
{% extends "core/user_base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans user_name=profile.get_display_name() %}{{ user_name }}'s account{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block infos %}
|
||||
{% if customer %}
|
||||
<h3>{% trans %}User account{% endtrans %}</h3>
|
||||
<p>{% trans %}Amount: {% endtrans %}{{ customer.amount }} €</p>
|
||||
{% if customer.refillings.exists() %}
|
||||
<h4>{% trans %}Refillings{% endtrans %}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Date{% endtrans %}</td>
|
||||
<td>{% trans %}Barman{% endtrans %}</td>
|
||||
<td>{% trans %}Amount{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for i in customer.refillings.all() %}
|
||||
<tr>
|
||||
<td>{{ i.date|localtime|date(DATETIME_FORMAT) }} - {{ i.date|localtime|time(DATETIME_FORMAT) }}</td>
|
||||
<td>{{ i.operator }}</td>
|
||||
<td>{{ i.amount }} €</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% if customer.buyings.exists() %}
|
||||
<h4>{% trans %}Buyings{% endtrans %}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Date{% endtrans %}</td>
|
||||
<td>{% trans %}Barman{% endtrans %}</td>
|
||||
<td>{% trans %}Label{% endtrans %}</td>
|
||||
<td>{% trans %}Quantity{% endtrans %}</td>
|
||||
<td>{% trans %}Total{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for i in customer.buyings.all() %}
|
||||
<tr>
|
||||
<td>{{ i.date|localtime|date(DATETIME_FORMAT) }} - {{ i.date|localtime|time(DATETIME_FORMAT) }}</td>
|
||||
<td>{{ i.seller }}</td>
|
||||
<td>{{ i.label }}</td>
|
||||
<td>{{ i.quantity }}</td>
|
||||
<td>{{ i.quantity * i.unit_price }} €</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% if customer.user.invoices.exists() %}
|
||||
<h4>{% trans %}Invoices{% endtrans %}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{% trans %}Date{% endtrans %}</td>
|
||||
<td>{% trans %}Items{% endtrans %}</td>
|
||||
<td>{% trans %}Amount{% endtrans %}</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for i in customer.user.invoices.all() %}
|
||||
<tr>
|
||||
<td>{{ i.date|localtime|date(DATETIME_FORMAT) }} - {{ i.date|localtime|time(DATETIME_FORMAT) }}</td>
|
||||
<td>
|
||||
<ul>
|
||||
{% for it in i.items.all() %}
|
||||
<li>{{ it.product_name }} - {{ it.product_unit_price }} €</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td>{{ i.get_total() }} €</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p>{% trans %}User has no account{% endtrans %}</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -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'),
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user