Merge branch 'sli' into 'master'

Add ban for alcohol



See merge request !17
This commit is contained in:
Skia 2016-10-21 11:00:40 +02:00
commit 3e99f97b7a
12 changed files with 2360 additions and 1644 deletions

View File

@ -22,7 +22,7 @@
<h4>{% trans %}Accouting: {% endtrans %}</h4>
<ul>
{% for ca in object.club_account.all() %}
<li><a href="{{ url('accounting:club_details', c_account_id=ca.id) }}">{{ ca }}</a></li>
<li><a href="{{ url('accounting:club_details', c_account_id=ca.id) }}">{{ ca.get_display_name() }}</a></li>
{% endfor %}
</ul>
{% endif %}

View File

@ -241,6 +241,14 @@ class User(AbstractBaseUser):
from club.models import Club
return Club.objects.filter(unix_name=settings.SITH_LAUNDERETTE_MANAGER['unix_name']).first().get_membership_for(self)
@property
def is_banned_alcohol(self):
return self.is_in_group(settings.SITH_GROUPS['banned-alcohol']['name'])
@property
def is_banned_counter(self):
return self.is_in_group(settings.SITH_GROUPS['banned-from-counters']['name'])
def save(self, *args, **kwargs):
create = False
with transaction.atomic():
@ -431,6 +439,14 @@ class AnonymousUser(AuthAnonymousUser):
def is_launderette_manager(self):
return False
@property
def is_banned_alcohol(self):
return False
@property
def is_banned_conuter(self):
return False
def is_in_group(self, group_name):
"""
The anonymous user is only the public group

View File

@ -1,11 +1,19 @@
{% extends "core/base.jinja" %}
{% block title %}
{% if object %}
{% trans obj=object %}Edit {{ obj }}{% endtrans %}
{% else %}
{% trans %}Save{% endtrans %}
{% endif %}
{% endblock %}
{% block content %}
{% if object %}
<h2>{% trans obj=object %}Edit {{ obj }}{% endtrans %}</h2>
{% else %}
<h2>{% trans %}Save{% endtrans %}</h2>
{% endif %}
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p() }}

View File

@ -1,6 +1,7 @@
{% extends "core/base.jinja" %}
{% macro monthly(obj) %}
<div>
<table>
<thead>
<tr>
@ -11,19 +12,20 @@
</thead>
<tbody>
{% for array in obj %}
{% for tuple in array %}
{% if tuple[0] != 0 %}
{% set link=url('core:user_account_detail', user_id=profile.id, year=tuple[1].year, month=tuple[1].month) %}
{% for dict in array %}
{% if dict['sum'] != 0 %}
{% set link=url('core:user_account_detail', user_id=profile.id, year=dict['date'].year, month=dict['date'].month) %}
<tr>
<td><a href="{{ link }}">{{ tuple[1].year }}</a></td>
<td><a href="{{ link }}">{{ tuple[1]|date("E") }}</a></td>
<td><a href="{{ link }}">{{ tuple[0] }} €</a></td>
<td><a href="{{ link }}">{{ dict['date'].year }}</a></td>
<td><a href="{{ link }}">{{ dict['date']|date("E") }}</a></td>
<td><a href="{{ link }}">{{ dict['sum'] }} €</a></td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>
{% endmacro %}
{% block title %}
@ -34,30 +36,42 @@
{% if customer %}
<h3>{% trans %}User account{% endtrans %}</h3>
<p>{% trans %}Amount: {% endtrans %}{{ customer.amount }} €</p>
<div id="drop">
{% if customer.refillings.exists() %}
<h4>{% trans %}Refillings{% endtrans %}</h4>
{{ monthly(refilling_month) }}
{% endif %}
{% if customer.buyings.exists() %}
<h4>{% trans %}Account buyings{% endtrans %}</h4>
<h5>{% trans %}Account buyings{% endtrans %}</h5>
{{ monthly(buyings_month) }}
{% endif %}
<h5>{% trans %}Refillings{% endtrans %}</h5>
{{ monthly(refilling_month) }}
{% endif %}
{% if customer.user.invoices.exists() %}
<h4>{% trans %}Eboutic invoices{% endtrans %}</h4>
<h5>{% trans %}Eboutic invoices{% endtrans %}</h5>
{{ monthly(invoices_month) }}
{% endif %}
{% if etickets %}
<h4>{% trans %}Etickets{% endtrans %}</h4>
<div>
<ul>
{% for s in etickets %}
<li><a href="{{ url('counter:eticket_pdf', selling_id=s.id) }}">{{ s.quantity }} x {{ s.product.eticket }}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
{% else %}
<p>{% trans %}User has no account{% endtrans %}</p>
{% endif %}
{% endblock %}
{% block script %}
{{ super() }}
<script>
$(function(){
$("#drop").accordion();
});
</script>
{% endblock %}

View File

@ -9,35 +9,6 @@
<h3>{% trans %}User account{% endtrans %}</h3>
<p>{% trans %}Amount: {% endtrans %}{{ customer.amount }} €</p>
<p><a href="{{ url('core:user_account', user_id=profile.id) }}">{% trans %}Back{% endtrans %}</a></p>
{% if customer.refillings.exists() %}
<h4>{% trans %}Refillings{% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Date{% endtrans %}</td>
<td>{% trans %}Counter{% endtrans %}</td>
<td>{% trans %}Barman{% endtrans %}</td>
<td>{% trans %}Amount{% endtrans %}</td>
<td>{% trans %}Payment method{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for i in customer.refillings.order_by('-date').filter(
date__year=year, date__month=month) %}
<tr>
<td>{{ i.date|localtime|date(DATETIME_FORMAT) }} - {{ i.date|localtime|time(DATETIME_FORMAT) }}</td>
<td>{{ i.counter }}</td>
<td><a href="{{ i.operator.get_absolute_url() }}">{{ i.operator.get_display_name() }}</a></td>
<td>{{ i.amount }} €</td>
<td>{{ i.get_payment_method_display() }}</td>
{% if i.is_owned_by(user) %}
<td><a href="{{ url('counter:refilling_delete', refilling_id=i.id) }}">Delete</a></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% if customer.buyings.exists() %}
<h4>{% trans %}Account buyings{% endtrans %}</h4>
<table>
@ -71,6 +42,35 @@
</tbody>
</table>
{% endif %}
{% if customer.refillings.exists() %}
<h4>{% trans %}Refillings{% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Date{% endtrans %}</td>
<td>{% trans %}Counter{% endtrans %}</td>
<td>{% trans %}Barman{% endtrans %}</td>
<td>{% trans %}Amount{% endtrans %}</td>
<td>{% trans %}Payment method{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for i in customer.refillings.order_by('-date').filter(
date__year=year, date__month=month) %}
<tr>
<td>{{ i.date|localtime|date(DATETIME_FORMAT) }} - {{ i.date|localtime|time(DATETIME_FORMAT) }}</td>
<td>{{ i.counter }}</td>
<td><a href="{{ i.operator.get_absolute_url() }}">{{ i.operator.get_display_name() }}</a></td>
<td>{{ i.amount }} €</td>
<td>{{ i.get_payment_method_display() }}</td>
{% if i.is_owned_by(user) %}
<td><a href="{{ url('counter:refilling_delete', refilling_id=i.id) }}">Delete</a></td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% if customer.user.invoices.exists() %}
<h4>{% trans %}Eboutic invoices{% endtrans %}</h4>
<table>

View File

@ -16,6 +16,7 @@
{% endif %}
{% if user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user.is_root %}
<li><a href="{{ url('subscription:subscription') }}">{% trans %}Subscriptions{% endtrans %}</a></li>
<li><a href="{{ url('club:club_new') }}">{% trans %}New club{% endtrans %}</a></li>
{% endif %}
</ul>

View File

@ -319,22 +319,29 @@ class UserUpdateProfileView(UserTabsMixin, CanEditMixin, UpdateView):
form_class = UserProfileForm
current_tab = "edit"
edit_once = ['profile_pict', 'date_of_birth', 'first_name', 'last_name']
board_only = []
def remove_once_edited_fields(self, request):
def remove_restricted_fields(self, request):
"""
Removes edit_once and board_only fields
"""
for i in self.edit_once:
if getattr(self.form.instance, i) and not (request.user.is_board_member or request.user.is_root):
self.form.fields.pop(i, None)
for i in self.board_only:
if not (request.user.is_board_member or request.user.is_root):
self.form.fields.pop(i, None)
def get(self, request, *args, **kwargs):
self.object = self.get_object()
self.form = self.get_form()
self.remove_once_edited_fields(request)
self.remove_restricted_fields(request)
return self.render_to_response(self.get_context_data(form=self.form))
def post(self, request, *args, **kwargs):
self.object = self.get_object()
self.form = self.get_form()
self.remove_once_edited_fields(request)
self.remove_restricted_fields(request)
files = request.FILES.items()
self.form.process(files)
if request.user.is_authenticated() and request.user.can_edit(self.object) and self.form.is_valid():
@ -420,10 +427,10 @@ class UserAccountView(UserAccountBase):
date__year=month.year,
date__month=month.month
)
stats[i].append((
sum([calc(p) for p in q]),
month
))
stats[i].append({
'sum':sum([calc(p) for p in q]),
'date':month
})
i += 1
return stats

View File

@ -51,7 +51,7 @@
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
{% csrf_token %}
<input type="hidden" name="action" value="code">
<input type="input" name="code" value="" autofocus id="code_field"/>
<input type="input" name="code" value="" autofocus class="focus" id="code_field"/>
<input type="submit" value="{% trans %}Go{% endtrans %}" />
</form>
<p>{% trans %}Basket: {% endtrans %}</p>
@ -174,6 +174,9 @@ $( function() {
$( function() {
$("#bar_ui").accordion({
heightStyle: "content",
activate: function(event, ui){
$(".focus").focus();
}
});
$("#products").tabs();
});

View File

@ -63,6 +63,9 @@ class RefillForm(forms.ModelForm):
class Meta:
model = Refilling
fields = ['amount', 'payment_method', 'bank']
widgets = {
'amount': forms.NumberInput(attrs={'class':'focus'},)
}
class CounterTabsMixin(TabedViewMixin):
def get_tabs_title(self):
@ -278,6 +281,12 @@ class CounterClick(CounterTabsMixin, DetailView):
if product.limit_age >= 18 and not self.customer.user.date_of_birth:
request.session['no_age'] = True
return False
if product.limit_age >= 18 and self.customer.user.is_banned_alcohol:
request.session['not_allowed'] = True
return False
if self.customer.user.is_banned_counter:
request.session['not_allowed'] = True
return False
if self.customer.user.date_of_birth and self.customer.user.get_age() < product.limit_age: # Check if affordable
request.session['too_young'] = True
return False
@ -1016,7 +1025,7 @@ class EticketPDFView(CanViewMixin, DetailView):
self.object = self.get_object()
eticket = self.object.product.eticket
user = self.object.customer.user
code = "%s %s %s" % (self.object.customer.user.id, self.object.product.id, self.object.quantity)
code = "%s %s %s %s" % (self.object.customer.user.id, self.object.product.id, self.object.id, self.object.quantity)
code += " " + eticket.get_hash(code)[:8].upper()
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'filename="eticket.pdf"'

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -256,6 +256,18 @@ SITH_GROUPS = {
'id': 5,
'name': "Counter admin",
},
'banned-alcohol': {
'id': 6,
'name': "Banned from buying alcohol",
},
'banned-from-counters': {
'id': 7,
'name': "Banned from counters",
},
'banned-to-subscribe': {
'id': 8,
'name': "Banned to subscribe",
}
}
SITH_BOARD_SUFFIX="-bureau"