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
6cacfb8d
Commit
6cacfb8d
authored
Sep 12, 2016
by
Skia
🤘
Browse files
Add counter activity
parent
c748bb84
Pipeline
#215
failed with stage
in 20 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
core/templates/core/base.jinja
View file @
6cacfb8d
...
...
@@ -25,12 +25,14 @@
<ul>
{%
for
bar
in
Counter.objects.
filter
(
type
=
"BAR"
)
.
all
()
%}
<li>
<a
href=
"
{{
url
(
'counter:activity'
,
counter_id
=
bar.id
)
}}
"
style=
"padding: 0px"
>
{%
if
bar.is_open
()
%}
<span
style=
"color: green"
>
✓
</span>
{%
else
%}
<span
style=
"color: red"
>
✗
</span>
{%
endif
%}
{{
bar
}}
</a>
</li>
{%
endfor
%}
</ul>
...
...
counter/models.py
View file @
6cacfb8d
...
...
@@ -173,7 +173,6 @@ class Counter(models.Model):
bl
=
[]
for
p
in
pl
:
if
timezone
.
now
()
-
p
.
activity
<
timedelta
(
minutes
=
settings
.
SITH_BARMAN_TIMEOUT
):
p
.
save
()
# Update activity
bl
.
append
(
p
.
user
)
else
:
p
.
end
=
p
.
activity
...
...
@@ -181,13 +180,26 @@ class Counter(models.Model):
return
bl
def
get_random_barman
(
self
):
"""
Return a random user being currently a barman
"""
bl
=
self
.
get_barmen_list
()
return
bl
[
random
.
randrange
(
0
,
len
(
bl
))]
def
update_activity
(
self
):
"""
Update the barman activity to prevent timeout
"""
for
p
in
Permanency
.
objects
.
filter
(
counter
=
self
,
end
=
None
).
all
():
p
.
save
()
# Update activity
def
is_open
(
self
):
return
len
(
self
.
get_barmen_list
())
>
0
def
barman_list
(
self
):
"""
Returns the barman id list
"""
return
[
b
.
id
for
b
in
self
.
get_barmen_list
()]
class
Refilling
(
models
.
Model
):
...
...
@@ -315,8 +327,11 @@ class Permanency(models.Model):
verbose_name
=
_
(
"permanency"
)
def
__str__
(
self
):
return
"%s in %s from %s"
%
(
self
.
user
,
self
.
counter
,
self
.
start
.
strftime
(
"%Y-%m-%d %H:%M:%S"
))
return
"%s in %s from %s (last activity: %s) to %s"
%
(
self
.
user
,
self
.
counter
,
self
.
start
.
strftime
(
"%Y-%m-%d %H:%M:%S"
),
self
.
activity
.
strftime
(
"%Y-%m-%d %H:%M:%S"
),
self
.
end
.
strftime
(
"%Y-%m-%d %H:%M:%S"
)
if
self
.
end
else
""
,
)
class
CashRegisterSummary
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
related_name
=
"cash_summaries"
,
verbose_name
=
_
(
"user"
))
...
...
counter/templates/counter/activity.jinja
0 → 100644
View file @
6cacfb8d
{%
extends
"core/base.jinja"
%}
{%
from
'core/macros.jinja'
import
user_profile_link
%}
{%
block
title
%}
{%
trans
counter_name
=
counter
%}{{
counter_name
}}
activity
{%
endtrans
%}
{%
endblock
%}
{%
block
content
%}
<h3>
{%
trans
counter_name
=
counter
%}{{
counter_name
}}
activity
{%
endtrans
%}
</h3>
{%
if
counter.type
==
'BAR'
%}
<h4>
{%
trans
%}
Barman list
{%
endtrans
%}
</h4>
<ul>
{%
for
b
in
counter.get_barmen_list
()
%}
<li>
{{
user_profile_link
(
b
)
}}
</li>
{%
endfor
%}
</ul>
{%
endif
%}
{%
endblock
%}
counter/urls.py
View file @
6cacfb8d
...
...
@@ -6,6 +6,7 @@ urlpatterns = [
url
(
r
'^(?P<counter_id>[0-9]+)$'
,
CounterMain
.
as_view
(),
name
=
'details'
),
url
(
r
'^(?P<counter_id>[0-9]+)/click/(?P<user_id>[0-9]+)$'
,
CounterClick
.
as_view
(),
name
=
'click'
),
url
(
r
'^(?P<counter_id>[0-9]+)/cash_summary$'
,
CounterCashSummaryView
.
as_view
(),
name
=
'cash_summary'
),
url
(
r
'^(?P<counter_id>[0-9]+)/activity$'
,
CounterActivityView
.
as_view
(),
name
=
'activity'
),
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 @
6cacfb8d
...
...
@@ -75,6 +75,7 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
"""
if
self
.
request
.
method
==
'POST'
:
self
.
object
=
self
.
get_object
()
self
.
object
.
update_activity
()
kwargs
=
super
(
CounterMain
,
self
).
get_context_data
(
**
kwargs
)
kwargs
[
'login_form'
]
=
LoginForm
()
kwargs
[
'login_form'
].
fields
[
'username'
].
widget
.
attrs
[
'autofocus'
]
=
True
...
...
@@ -677,3 +678,12 @@ class CounterCashSummaryView(CanViewMixin, DetailView):
kwargs
=
super
(
CounterCashSummaryView
,
self
).
get_context_data
(
**
kwargs
)
kwargs
[
'form'
]
=
self
.
form
return
kwargs
class
CounterActivityView
(
DetailView
):
"""
Show the bar activity
"""
model
=
Counter
pk_url_kwarg
=
"counter_id"
template_name
=
'counter/activity.jinja'
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