diff --git a/bartenders/migrations/0007_auto_20241214_0030.py b/bartenders/migrations/0007_auto_20241214_0030.py new file mode 100644 index 0000000..299c79e --- /dev/null +++ b/bartenders/migrations/0007_auto_20241214_0030.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.4 on 2024-12-13 23:30 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bartenders", "0006_alter_boardmemberdepositshift_options"), + ] + + operations = [ + migrations.AlterModelOptions( + name="bartendershift", + options={"ordering": ("start_datetime",)}, + ), + migrations.AlterModelOptions( + name="boardmemberdepositshift", + options={"ordering": ("start_date",)}, + ), + ] diff --git a/bartenders/models.py b/bartenders/models.py index ef4566b..23917c4 100644 --- a/bartenders/models.py +++ b/bartenders/models.py @@ -103,14 +103,14 @@ def symbol(self): @property def first_bartender_shift(self): - return BartenderShift.with_bartender(self).last() + return BartenderShift.with_bartender(self).first() @property def last_bartender_shift(self): - return BartenderShift.with_bartender(self).first() + return BartenderShift.with_bartender(self).last() @property - def first_deposit_shift(self): + def last_deposit_shift(self): return BoardMemberDepositShift.with_bartender(self).last() MAILMAN_ALL = ( @@ -403,7 +403,7 @@ class BartenderShift(models.Model): ) class Meta: - ordering = ("-start_datetime",) + ordering = ("start_datetime",) def save(self, *args, **kwargs): if not self.end_datetime: @@ -448,8 +448,8 @@ def is_with_bartender(self, bartender): def is_current_week(self): return self.start_datetime >= timezone.now() - datetime.timedelta( - days=7 - ) and self.end_datetime <= timezone.now() + datetime.timedelta(days=7) + days=2 + ) and self.end_datetime <= timezone.now() + datetime.timedelta(days=5) def replace(self, b1, b2): if self.responsible == b1: @@ -485,7 +485,7 @@ class BoardMemberDepositShift(models.Model): ) class Meta: - ordering = ("-start_date",) + ordering = ("start_date",) def save(self, *args, **kwargs): if not self.end_date: diff --git a/bartenders/views.py b/bartenders/views.py index df8f899..c929e5e 100644 --- a/bartenders/views.py +++ b/bartenders/views.py @@ -88,15 +88,27 @@ def get_context_data(self, **kwargs): bartendershifts = BartenderShift.objects.all() depositshifts = BoardMemberDepositShift.objects.all() - paginator_bartendershifts = Paginator(bartendershifts, 10) - paginator_depositshifts = Paginator(depositshifts, 10) + paginator_bartendershifts = Paginator(bartendershifts, 15) + paginator_depositshifts = Paginator(depositshifts, 15) bartendershifts_page_number = self.request.GET.get("shifts_page") + if not bartendershifts_page_number: + bartendershifts_page_number = self.current_week_page_number( + paginator_bartendershifts + ) + if not bartendershifts_page_number: + bartendershifts_page_number = paginator_bartendershifts.num_pages bartendershifts_page_obj = paginator_bartendershifts.get_page( bartendershifts_page_number ) depositshifts_page_number = self.request.GET.get("deposit_page") + if not depositshifts_page_number: + depositshifts_page_number = self.current_deposit_week_page_number( + paginator_depositshifts + ) + if not depositshifts_page_number: + depositshifts_page_number = paginator_depositshifts.num_pages depositshifts_page_obj = paginator_depositshifts.get_page( depositshifts_page_number ) @@ -107,6 +119,22 @@ def get_context_data(self, **kwargs): return context + 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) + 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): + return i + return None + class UserBarplan(ICalFeed): product_id = "-//fredagscafeen.dk//UserBarplan//EN"