mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-15 18:53:25 +00:00
Continue the counter views
This commit is contained in:
parent
c1a151d754
commit
478d1ed876
20
counter/templates/counter/counter_click.jinja
Normal file
20
counter/templates/counter/counter_click.jinja
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% macro barman_logout_link(user) %}
|
||||
<form method="post" action="{{ url('counter:logout', counter_id=counter.id) }}" class="inline">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="user_id" value="{{ user.id }}">
|
||||
<button type="submit" name="submit_param" value="submit_value" class="link-button">{{ user.get_display_name() }}</button>
|
||||
</form>
|
||||
{% endmacro %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Counter</h3>
|
||||
<h4>{{ counter }}</h4>
|
||||
<p><strong>Club: </strong> {{ counter.club }}</p>
|
||||
<p><strong>Products: </strong> {{ counter.products.all() }}</p>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -14,6 +14,19 @@
|
||||
<p><strong>Club: </strong> {{ counter.club }}</p>
|
||||
<p><strong>Products: </strong> {{ counter.products.all() }}</p>
|
||||
|
||||
|
||||
<div>
|
||||
{% if barmen %}
|
||||
<p>Enter client code:</p>
|
||||
<form method="post" action="{{ url('counter:click', counter_id=counter.id) }}">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p() }}
|
||||
<input type="submit" value="CLICK" />
|
||||
</form>
|
||||
{% else %}
|
||||
<p>Please, login</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
<h3>Barman: </h3>
|
||||
<ul>
|
||||
@ -27,13 +40,6 @@
|
||||
<input type="submit" value="login" />
|
||||
</form>
|
||||
</div>
|
||||
<div>
|
||||
{% if barmen %}
|
||||
<p>Enter client code:</p>
|
||||
{% else %}
|
||||
<p>Please, login</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -3,7 +3,8 @@ from django.conf.urls import url, include
|
||||
from counter.views import *
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^(?P<counter_id>[0-9]+)$', CounterDetail.as_view(), name='details'),
|
||||
url(r'^(?P<counter_id>[0-9]+)$', CounterMain.as_view(), name='details'),
|
||||
url(r'^(?P<counter_id>[0-9]+)/click$', CounterClick.as_view(), name='click'),
|
||||
url(r'^(?P<counter_id>[0-9]+)/login$', CounterLogin.as_view(), name='login'),
|
||||
url(r'^(?P<counter_id>[0-9]+)/logout$', CounterLogout.as_view(), name='logout'),
|
||||
url(r'^admin/(?P<counter_id>[0-9]+)$', CounterEditView.as_view(), name='admin'),
|
||||
|
@ -1,26 +1,32 @@
|
||||
from django.shortcuts import render
|
||||
from django.views.generic import ListView, DetailView, RedirectView
|
||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView
|
||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin
|
||||
from django.forms.models import modelform_factory
|
||||
from django.forms import CheckboxSelectMultiple
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
from django import forms
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
||||
from subscription.models import Subscriber
|
||||
from accounting.models import Customer
|
||||
from counter.models import Counter
|
||||
|
||||
class CounterDetail(DetailView):
|
||||
class GetUserForm(forms.Form):
|
||||
username = forms.CharField(label="Name", max_length=64, required=False)
|
||||
|
||||
class CounterMain(DetailView, FormMixin):
|
||||
"""
|
||||
The public (barman) view
|
||||
"""
|
||||
model = Counter
|
||||
template_name = 'counter/counter_detail.jinja'
|
||||
template_name = 'counter/counter_main.jinja'
|
||||
pk_url_kwarg = "counter_id"
|
||||
form_class = GetUserForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""
|
||||
@ -28,21 +34,38 @@ class CounterDetail(DetailView):
|
||||
|
||||
Also handle the timeout
|
||||
"""
|
||||
context = super(CounterDetail, self).get_context_data(**kwargs)
|
||||
context['login_form'] = AuthenticationForm()
|
||||
print(self.object.id)
|
||||
print(list(Counter.barmen_session.keys()))
|
||||
kwargs = super(CounterMain, self).get_context_data(**kwargs)
|
||||
kwargs['login_form'] = AuthenticationForm()
|
||||
kwargs['form'] = self.get_form()
|
||||
print(kwargs)
|
||||
if str(self.object.id) in list(Counter.barmen_session.keys()):
|
||||
if (timezone.now() - Counter.barmen_session[str(self.object.id)]['time']) < timedelta(minutes=settings.SITH_BARMAN_TIMEOUT):
|
||||
context['barmen'] = []
|
||||
kwargs['barmen'] = []
|
||||
for b in Counter.barmen_session[str(self.object.id)]['users']:
|
||||
context['barmen'].append(Subscriber.objects.filter(id=b).first())
|
||||
kwargs['barmen'].append(Subscriber.objects.filter(id=b).first())
|
||||
Counter.barmen_session[str(self.object.id)]['time'] = timezone.now()
|
||||
else:
|
||||
Counter.barmen_session[str(self.object.id)]['users'] = {}
|
||||
else:
|
||||
context['barmen'] = []
|
||||
return context
|
||||
kwargs['barmen'] = []
|
||||
return kwargs
|
||||
|
||||
class CounterClick(DetailView, ProcessFormView, FormMixin):
|
||||
"""
|
||||
The click view
|
||||
"""
|
||||
model = Counter # TODO change that to a basket class
|
||||
template_name = 'counter/counter_click.jinja'
|
||||
pk_url_kwarg = "counter_id"
|
||||
form_class = GetUserForm
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
# TODO: handle the loading of a user, to display the click view
|
||||
# TODO: Do the form and the template for the click view
|
||||
return super(CounterClick, self).post(request, *args, **kwargs)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('counter:click', args=self.args, kwargs=self.kwargs)
|
||||
|
||||
class CounterLogin(RedirectView):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user