Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
478d1ed8
Commit
478d1ed8
authored
Apr 15, 2016
by
Skia
🤘
Browse files
Continue the counter views
parent
c1a151d7
Pipeline
#9
skipped
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
counter/templates/counter/counter_click.jinja
0 → 100644
View file @
478d1ed8
{%
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
%}
counter/templates/counter/counter_
det
ai
l
.jinja
→
counter/templates/counter/counter_
m
ai
n
.jinja
View file @
478d1ed8
...
...
@@ -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
%}
...
...
counter/urls.py
View file @
478d1ed8
...
...
@@ -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'
),
...
...
counter/views.py
View file @
478d1ed8
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_
det
ai
l
.jinja'
template_name
=
'counter/counter_
m
ai
n
.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
(
Counter
Det
ai
l
,
self
).
get_context_data
(
**
kwargs
)
context
[
'login_form'
]
=
AuthenticationForm
()
print
(
self
.
object
.
id
)
print
(
list
(
Counter
.
barmen_session
.
keys
())
)
kwargs
=
super
(
Counter
M
ai
n
,
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
):
"""
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment