From 478d1ed876ab5d4837bfb7a0480f39cccf212f2f Mon Sep 17 00:00:00 2001 From: Skia Date: Fri, 15 Apr 2016 11:50:31 +0200 Subject: [PATCH] Continue the counter views --- counter/templates/counter/counter_click.jinja | 20 +++++++++ ...ounter_detail.jinja => counter_main.jinja} | 20 ++++++--- counter/urls.py | 3 +- counter/views.py | 45 ++++++++++++++----- 4 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 counter/templates/counter/counter_click.jinja rename counter/templates/counter/{counter_detail.jinja => counter_main.jinja} (84%) diff --git a/counter/templates/counter/counter_click.jinja b/counter/templates/counter/counter_click.jinja new file mode 100644 index 00000000..8c072c62 --- /dev/null +++ b/counter/templates/counter/counter_click.jinja @@ -0,0 +1,20 @@ +{% extends "core/base.jinja" %} + +{% macro barman_logout_link(user) %} +
+ {% csrf_token %} + + +
+{% endmacro %} + +{% block content %} +

Counter

+

{{ counter }}

+

Club: {{ counter.club }}

+

Products: {{ counter.products.all() }}

+ +{% endblock %} + + + diff --git a/counter/templates/counter/counter_detail.jinja b/counter/templates/counter/counter_main.jinja similarity index 84% rename from counter/templates/counter/counter_detail.jinja rename to counter/templates/counter/counter_main.jinja index f7abe160..c26932bf 100644 --- a/counter/templates/counter/counter_detail.jinja +++ b/counter/templates/counter/counter_main.jinja @@ -14,6 +14,19 @@

Club: {{ counter.club }}

Products: {{ counter.products.all() }}

+ +
+ {% if barmen %} +

Enter client code:

+
+ {% csrf_token %} + {{ form.as_p() }} + +
+ {% else %} +

Please, login

+ {% endif %} +

Barman:

-
- {% if barmen %} -

Enter client code:

- {% else %} -

Please, login

- {% endif %} -
{% endblock %} diff --git a/counter/urls.py b/counter/urls.py index 915acf3a..920f246f 100644 --- a/counter/urls.py +++ b/counter/urls.py @@ -3,7 +3,8 @@ from django.conf.urls import url, include from counter.views import * urlpatterns = [ - url(r'^(?P[0-9]+)$', CounterDetail.as_view(), name='details'), + url(r'^(?P[0-9]+)$', CounterMain.as_view(), name='details'), + url(r'^(?P[0-9]+)/click$', CounterClick.as_view(), name='click'), url(r'^(?P[0-9]+)/login$', CounterLogin.as_view(), name='login'), url(r'^(?P[0-9]+)/logout$', CounterLogout.as_view(), name='logout'), url(r'^admin/(?P[0-9]+)$', CounterEditView.as_view(), name='admin'), diff --git a/counter/views.py b/counter/views.py index c45df0e2..5992312c 100644 --- a/counter/views.py +++ b/counter/views.py @@ -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): """