mirror of
https://github.com/ae-utbm/sith.git
synced 2024-10-31 19:38:04 +00:00
Add counter activity
This commit is contained in:
parent
c748bb8450
commit
6cacfb8d8d
@ -25,12 +25,14 @@
|
|||||||
<ul>
|
<ul>
|
||||||
{% for bar in Counter.objects.filter(type="BAR").all() %}
|
{% for bar in Counter.objects.filter(type="BAR").all() %}
|
||||||
<li>
|
<li>
|
||||||
|
<a href="{{ url('counter:activity', counter_id=bar.id) }}" style="padding: 0px">
|
||||||
{% if bar.is_open() %}
|
{% if bar.is_open() %}
|
||||||
<span style="color: green">✓</span>
|
<span style="color: green">✓</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span style="color: red">✗</span>
|
<span style="color: red">✗</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ bar }}
|
{{ bar }}
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -173,7 +173,6 @@ class Counter(models.Model):
|
|||||||
bl = []
|
bl = []
|
||||||
for p in pl:
|
for p in pl:
|
||||||
if timezone.now() - p.activity < timedelta(minutes=settings.SITH_BARMAN_TIMEOUT):
|
if timezone.now() - p.activity < timedelta(minutes=settings.SITH_BARMAN_TIMEOUT):
|
||||||
p.save() # Update activity
|
|
||||||
bl.append(p.user)
|
bl.append(p.user)
|
||||||
else:
|
else:
|
||||||
p.end = p.activity
|
p.end = p.activity
|
||||||
@ -181,13 +180,26 @@ class Counter(models.Model):
|
|||||||
return bl
|
return bl
|
||||||
|
|
||||||
def get_random_barman(self):
|
def get_random_barman(self):
|
||||||
|
"""
|
||||||
|
Return a random user being currently a barman
|
||||||
|
"""
|
||||||
bl = self.get_barmen_list()
|
bl = self.get_barmen_list()
|
||||||
return bl[random.randrange(0, len(bl))]
|
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):
|
def is_open(self):
|
||||||
return len(self.get_barmen_list()) > 0
|
return len(self.get_barmen_list()) > 0
|
||||||
|
|
||||||
def barman_list(self):
|
def barman_list(self):
|
||||||
|
"""
|
||||||
|
Returns the barman id list
|
||||||
|
"""
|
||||||
return [b.id for b in self.get_barmen_list()]
|
return [b.id for b in self.get_barmen_list()]
|
||||||
|
|
||||||
class Refilling(models.Model):
|
class Refilling(models.Model):
|
||||||
@ -315,8 +327,11 @@ class Permanency(models.Model):
|
|||||||
verbose_name = _("permanency")
|
verbose_name = _("permanency")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s in %s from %s" % (self.user, self.counter,
|
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.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):
|
class CashRegisterSummary(models.Model):
|
||||||
user = models.ForeignKey(User, related_name="cash_summaries", verbose_name=_("user"))
|
user = models.ForeignKey(User, related_name="cash_summaries", verbose_name=_("user"))
|
||||||
|
21
counter/templates/counter/activity.jinja
Normal file
21
counter/templates/counter/activity.jinja
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{% 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 %}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -6,6 +6,7 @@ urlpatterns = [
|
|||||||
url(r'^(?P<counter_id>[0-9]+)$', CounterMain.as_view(), name='details'),
|
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]+)/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]+)/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]+)/login$', CounterLogin.as_view(), name='login'),
|
||||||
url(r'^(?P<counter_id>[0-9]+)/logout$', CounterLogout.as_view(), name='logout'),
|
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'),
|
url(r'^admin/(?P<counter_id>[0-9]+)$', CounterEditView.as_view(), name='admin'),
|
||||||
|
@ -75,6 +75,7 @@ class CounterMain(DetailView, ProcessFormView, FormMixin):
|
|||||||
"""
|
"""
|
||||||
if self.request.method == 'POST':
|
if self.request.method == 'POST':
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
self.object.update_activity()
|
||||||
kwargs = super(CounterMain, self).get_context_data(**kwargs)
|
kwargs = super(CounterMain, self).get_context_data(**kwargs)
|
||||||
kwargs['login_form'] = LoginForm()
|
kwargs['login_form'] = LoginForm()
|
||||||
kwargs['login_form'].fields['username'].widget.attrs['autofocus'] = True
|
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 = super(CounterCashSummaryView, self).get_context_data(**kwargs)
|
||||||
kwargs['form'] = self.form
|
kwargs['form'] = self.form
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
class CounterActivityView(DetailView):
|
||||||
|
"""
|
||||||
|
Show the bar activity
|
||||||
|
"""
|
||||||
|
model = Counter
|
||||||
|
pk_url_kwarg = "counter_id"
|
||||||
|
template_name = 'counter/activity.jinja'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user