diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja
index d9152278..fc02b256 100644
--- a/core/templates/core/base.jinja
+++ b/core/templates/core/base.jinja
@@ -25,12 +25,14 @@
diff --git a/counter/models.py b/counter/models.py
index 1c049f76..9b1aebc1 100644
--- a/counter/models.py
+++ b/counter/models.py
@@ -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"))
diff --git a/counter/templates/counter/activity.jinja b/counter/templates/counter/activity.jinja
new file mode 100644
index 00000000..d8a21aa1
--- /dev/null
+++ b/counter/templates/counter/activity.jinja
@@ -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 %}
+{% trans counter_name=counter %}{{ counter_name }} activity{% endtrans %}
+ {% if counter.type == 'BAR' %}
+ {% trans %}Barman list{% endtrans %}
+
+ {% for b in counter.get_barmen_list() %}
+ - {{ user_profile_link(b) }}
+ {% endfor %}
+
+ {% endif %}
+{% endblock %}
+
+
+
diff --git a/counter/urls.py b/counter/urls.py
index 74239fea..b5f547ad 100644
--- a/counter/urls.py
+++ b/counter/urls.py
@@ -6,6 +6,7 @@ urlpatterns = [
url(r'^(?P[0-9]+)$', CounterMain.as_view(), name='details'),
url(r'^(?P[0-9]+)/click/(?P[0-9]+)$', CounterClick.as_view(), name='click'),
url(r'^(?P[0-9]+)/cash_summary$', CounterCashSummaryView.as_view(), name='cash_summary'),
+ url(r'^(?P[0-9]+)/activity$', CounterActivityView.as_view(), name='activity'),
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 4e02bde4..96020217 100644
--- a/counter/views.py
+++ b/counter/views.py
@@ -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'
+