Skip to content

Commit

Permalink
Added streak calculation to BartenderShift model and update barplan t…
Browse files Browse the repository at this point in the history
…emplate for display
  • Loading branch information
AndersSeverinsen committed Dec 22, 2024
1 parent f8c1cd8 commit 5e5318e
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 90 deletions.
26 changes: 26 additions & 0 deletions bartenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,32 @@ def compare_to_current_week(self):
else:
return 1

def streak(self):
streak = 0
date = self.start_datetime + datetime.timedelta(days=2)
previous_bartendershifts = BartenderShift.objects.all().filter(
start_datetime__lte=date
)
found_shift = False
while previous_bartendershifts:
for previous_shift in previous_bartendershifts.reverse():
if (
previous_shift.start_datetime.date() <= date.date()
and previous_shift.end_datetime.date()
>= date.date() - datetime.timedelta(days=5)
):
streak += 1
found_shift = True
break
if not found_shift:
break
found_shift = False
date -= datetime.timedelta(days=7)
previous_bartendershifts = BartenderShift.objects.all().filter(
start_datetime__lte=date
)
return streak

def replace(self, b1, b2):
if self.responsible == b1:
self.responsible = b2
Expand Down
2 changes: 1 addition & 1 deletion bartenders/templates/barplan.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h2 id="barplan">{% translate "Barplan" %}</h2>
<tbody>
{% for shift in bartendershifts %}
<tr style="{% if shift|is_with_user:user %}background-color: skyblue;{% endif %}{% if shift|compare_to_current_week == -1 %}color:gray;{% endif %}">
<td class="col-md-2">{% if shift|compare_to_current_week == 0 %}<b alt="{% translate "This weeks friday" %}">{{ shift.display_str }}{% if show_all_bartendershifts %}, {{ shift.start_datetime.year }}{% endif %}{% else %} {{ shift.display_str }}{% if show_all_bartendershifts %}, {{ shift.start_datetime.year }}{% endif %}{% endif %}</td>
<td class="col-md-2">{% if shift|compare_to_current_week == 0 %}<b alt="{% translate "This weeks friday" %}">{{ shift.display_str }}{% if show_all_bartendershifts %}, {{ shift.start_datetime.year }}{% endif %}{% else %} {{ shift.display_str }}{% if show_all_bartendershifts %}, {{ shift.start_datetime.year }}{% endif %}{% endif %} {% if shift|compare_to_current_week == 0 %}</b> &nbsp; <b alt="{% translate "Baren har været åben" %} {{ shift.streak }} {% blocktranslate count c=shift.streak %}uge{% plural %}uger{% endblocktranslate %} {% translate "i træk" %}"><i>{{ shift.streak }}{% bs_icon 'fire' size='0.8em' %}</i></b>{% endif %}</td>
<td class="col-md-3">{{ shift.responsible.name }}</td>
<td class="col-md-7">
{% for bartender in shift.other_bartenders.all %}
Expand Down
Binary file modified locale/da/LC_MESSAGES/django.mo
Binary file not shown.
76 changes: 53 additions & 23 deletions locale/da/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-15 15:21+0100\n"
"PO-Revision-Date: 2024-12-13 20:28+0050\n"
"POT-Creation-Date: 2024-12-22 22:44+0100\n"
"PO-Revision-Date: 2024-12-22 22:43+0050\n"
"Last-Translator: <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
Expand Down Expand Up @@ -71,7 +71,7 @@ msgstr "Saldo"
msgid "Total forbrug"
msgstr "Total forbrug"

#: bartab/templates/bartab.html:19 bartenders/templates/barplan.html:24
#: bartab/templates/bartab.html:19 bartenders/templates/barplan.html:31
#: gallery/models.py:101
msgid "Dato"
msgstr "Dato"
Expand Down Expand Up @@ -161,54 +161,77 @@ msgstr "Gem"
msgid "Barplan"
msgstr "Barplan"

#: bartenders/templates/barplan.html:12
#: bartenders/templates/barplan.html:13 bartenders/templates/barplan.html:99
msgid "Vis kun nuværende"
msgstr "Vis kun nuværende"

#: bartenders/templates/barplan.html:15 bartenders/templates/barplan.html:101
#: events/templates/events.html:14
msgid "Vis også tidligere"
msgstr "Vis også tidligere"

#: bartenders/templates/barplan.html:18
msgid "Vagter per side"
msgstr ""

#: bartenders/templates/barplan.html:25
#: bartenders/templates/barplan.html:32
msgid "Ansvarlig"
msgstr "Ansvarlig"

#: bartenders/templates/barplan.html:26 bartenders/templates/bartenders.html:6
#: bartenders/templates/barplan.html:33 bartenders/templates/bartenders.html:6
#: web/templates/base.html:76
msgid "Bartendere"
msgstr "Bartendere"

#: bartenders/templates/barplan.html:35
#: bartenders/templates/barplan.html:42
msgid "This weeks friday"
msgstr "Denne uges fredag"

#: bartenders/templates/barplan.html:39
#: bartenders/templates/barplan.html:42
msgid "Baren har været åben"
msgstr ""

#: bartenders/templates/barplan.html:42
msgid "uge"
msgid_plural "uger"
msgstr[0] ""
msgstr[1] ""

#: bartenders/templates/barplan.html:42
msgid "i træk"
msgstr ""

#: bartenders/templates/barplan.html:46
msgid "Bartender's first shift"
msgstr "Bartenderens første vagt"

#: bartenders/templates/barplan.html:43 bartenders/templates/barplan.html:120
#: bartenders/templates/barplan.html:50 bartenders/templates/barplan.html:134
#: bartenders/templates/board.html:34 gallery/templates/gallery.html:24
#: items/templates/items.html:79
msgid "Edit"
msgstr "Rediger"

#: bartenders/templates/barplan.html:88 bartenders/views.py:201
#: bartenders/templates/barplan.html:95 bartenders/views.py:217
msgid "Pantvagter"
msgstr ""

#: bartenders/templates/barplan.html:91
#: bartenders/templates/barplan.html:104
msgid "Pantvagter per side"
msgstr ""

#: bartenders/templates/barplan.html:103
#: bartenders/templates/barplan.html:117
msgid "Uge"
msgstr ""

#: bartenders/templates/barplan.html:104 udlejning/models.py:107
#: bartenders/templates/barplan.html:118 udlejning/models.py:107
msgid "Ansvarlige"
msgstr ""

#: bartenders/templates/barplan.html:113
#: bartenders/templates/barplan.html:127
msgid "Current week"
msgstr "Nuværende uge"

#: bartenders/templates/barplan.html:116
#: bartenders/templates/barplan.html:130
msgid "Bartender's first deposit shift"
msgstr "Bartenderens første pantvagt"

Expand Down Expand Up @@ -353,19 +376,19 @@ msgstr ""
msgid "Din ansøgning er blevet indsendt."
msgstr ""

#: bartenders/views.py:162
#: bartenders/views.py:178
msgid "Barvagter"
msgstr ""

#: bartenders/views.py:185 bartenders/views.py:224
#: bartenders/views.py:201 bartenders/views.py:240
msgid "Responsible"
msgstr "Ansvarlig"

#: bartenders/views.py:186
#: bartenders/views.py:202
msgid "Other bartenders"
msgstr "Andre bartendere"

#: bartenders/views.py:333
#: bartenders/views.py:349
msgid "Profil opdateret"
msgstr ""

Expand Down Expand Up @@ -407,10 +430,6 @@ msgstr ""
msgid "Vis nuværende"
msgstr "Vis nuværende"

#: events/templates/events.html:14
msgid "Vis også tidligere"
msgstr "Vis også tidligere"

#: events/templates/events.html:18
msgid "Tilføj til kalender"
msgstr ""
Expand Down Expand Up @@ -1391,6 +1410,17 @@ msgstr "Fraværende i miljøet"
msgid "Login mail sendt: Tryk på linket i din modtagede mail for at logge ind."
msgstr ""

#~ msgid "Bar open"
#~ msgstr "Bar åben"

#~ msgid "week"
#~ msgid_plural "weeks"
#~ msgstr[0] "uge"
#~ msgstr[1] "uger"

#~ msgid "in a row"
#~ msgstr "i træk"

#~ msgid "Eventuelle ekstra info til bestyrelsen skrives her"
#~ msgstr "Eventuelle ekstra info til bestyrelsen skrives her"

Expand Down
Binary file modified locale/en/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 5e5318e

Please sign in to comment.