diff --git a/bartenders/models.py b/bartenders/models.py index 23917c4..14a4863 100644 --- a/bartenders/models.py +++ b/bartenders/models.py @@ -446,10 +446,16 @@ def display_str(self): def is_with_bartender(self, bartender): return bartender in self.all_bartenders() - def is_current_week(self): - return self.start_datetime >= timezone.now() - datetime.timedelta( - days=2 - ) and self.end_datetime <= timezone.now() + datetime.timedelta(days=5) + def compare_to_current_week(self): + date = timezone.now().date() + less_than_week = self.start_datetime.date() < date + datetime.timedelta(5) + greater_than_week = self.end_datetime.date() > date - datetime.timedelta(2) + if less_than_week and greater_than_week: + return 0 + elif less_than_week: + return -1 + else: + return 1 def replace(self, b1, b2): if self.responsible == b1: @@ -500,11 +506,16 @@ def with_bartender(cls, bartender): def is_with_bartender(self, bartender): return bartender in self.responsibles.all() - def is_current_week(self): - return ( - timezone.now().date() >= self.start_date - and timezone.now().date() <= self.end_date - ) + def compare_to_current_week(self): + date = timezone.now().date() + less_than_week = self.start_date < date + greater_than_week = self.end_date > date + if less_than_week and greater_than_week: + return 0 + elif less_than_week: + return -1 + else: + return 1 def __str__(self): return ( diff --git a/bartenders/templates/barplan.html b/bartenders/templates/barplan.html index 81aa9c7..4040a1d 100644 --- a/bartenders/templates/barplan.html +++ b/bartenders/templates/barplan.html @@ -4,7 +4,7 @@ {% load i18n %} {% load static %} {% load bootstrap5 bootstrap_icons %} -{% load is_with_user is_current_week %} +{% load is_with_user compare_to_current_week %}

{% translate "Barplan" %}

@@ -22,15 +22,15 @@

{% translate "Barplan" %}

{% for shift in bartendershifts %} - {{ shift.display_str }} {% if show_all %} {{ shift.start_datetime.year }}{% endif %} - {{ shift.responsible.name }} - + {{ shift.display_str }} {% if show_all %} {{ shift.start_datetime.year }}{% endif %} + {{ shift.responsible.name }} + {% for bartender in shift.other_bartenders.all %} {% if bartender.first_bartender_shift == shift %}{{ bartender.name }}{% else %}{{ bartender.name }}{% endif %}{% if not forloop.last %},{% endif %} {% endfor %} {% if user.is_staff %} - {% translate "Edit" %} + {% translate "Edit" %} {% endif %} {% endfor %} @@ -89,7 +89,7 @@

{% translate "Pantvagter" %}

{% for shift in boardmemberdepositshifts %} - + {{ shift.start_date | date:"d M" }}{% if show_all %} {{ shift.start_date.year }}{% endif %} - {{ shift.end_date | date:"d M" }}{% if show_all %} {{ shift.end_date.year }}{% endif %} {% for responsible in shift.responsibles.all %} diff --git a/bartenders/views.py b/bartenders/views.py index c929e5e..77c9e35 100644 --- a/bartenders/views.py +++ b/bartenders/views.py @@ -122,16 +122,14 @@ def get_context_data(self, **kwargs): def current_week_page_number(self, paginator): for i in range(1, paginator.num_pages + 1): page = paginator.get_page(i) - if any(shift.is_current_week for shift in page): - print(i) + if any(shift.compare_to_current_week() == 0 for shift in page): return i - print("None") return None def current_deposit_week_page_number(self, paginator): for i in range(1, paginator.num_pages + 1): page = paginator.get_page(i) - if any(shift.is_current_week for shift in page): + if any(shift.compare_to_current_week() == 0 for shift in page): return i return None diff --git a/web/templatetags/is_current_week.py b/web/templatetags/compare_to_current_week.py similarity index 57% rename from web/templatetags/is_current_week.py rename to web/templatetags/compare_to_current_week.py index 405345b..6c5be6f 100644 --- a/web/templatetags/is_current_week.py +++ b/web/templatetags/compare_to_current_week.py @@ -5,9 +5,9 @@ register = template.Library() -@register.filter(name="is_current_week") -def is_current_week(shift): +@register.filter(name="compare_to_current_week") +def compare_to_current_week(shift): try: - return shift.is_current_week() + return shift.compare_to_current_week() except BartenderShift.DoesNotExist: return False