From 63f10c13d47c9d89e4efca060289630efca90bff Mon Sep 17 00:00:00 2001 From: guillaume-renaud Date: Sun, 16 Oct 2016 18:52:04 +0200 Subject: [PATCH] Add inactive state for counters --- core/templates/core/base.jinja | 4 +++- counter/models.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index 64cd1854..e47262c6 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -26,7 +26,9 @@ {% for bar in Counter.objects.filter(type="BAR").all() %}
  • - {% if bar.is_open() %} + {% if bar.is_inactive(): %} + ? + {% elif bar.is_open(): %} {% else %} diff --git a/counter/models.py b/counter/models.py index cd2e5a84..7ec0c573 100644 --- a/counter/models.py +++ b/counter/models.py @@ -11,6 +11,7 @@ import random import string import os import base64 +import datetime from club.models import Club from accounting.models import CurrencyField @@ -220,6 +221,15 @@ class Counter(models.Model): def is_open(self): return len(self.get_barmen_list()) > 0 + def is_inactive(self): + """ + Returns True if the counter self is inactive from 5 minutes, else False + """ + if (self.is_open()): + return ((timezone.now() - self.permanencies.model.objects.order_by('-activity').first().activity) > datetime.timedelta(minutes=5)) + else: + return False + def barman_list(self): """ Returns the barman id list