Compare commits

...

2 commits

Author SHA1 Message Date
57279b1cda
Simplify duplicated code (archive views) 2024-01-02 14:21:58 +01:00
47c4de8fbb
Fix calendar scroll 2024-01-02 14:18:57 +01:00
2 changed files with 33 additions and 48 deletions

View file

@ -84,6 +84,8 @@ table.full-width col.bar {
} }
.calendar { .calendar {
overflow-x: auto;
margin-top: var(--gap); margin-top: var(--gap);
font-feature-settings: var(--num); font-feature-settings: var(--num);

View file

@ -110,68 +110,51 @@ class TransactionListView(NummiListView):
context_object_name = "transactions" context_object_name = "transactions"
class TransactionMonthView(UserMixin, MonthArchiveView): class TransactionACMixin:
model = Transaction
def get_queryset(self):
if "account" in self.kwargs:
self.account = get_object_or_404(
Account.objects.filter(user=self.request.user),
pk=self.kwargs["account"],
)
return super().get_queryset().filter(account=self.account)
if "category" in self.kwargs:
self.category = get_object_or_404(
Category.objects.filter(user=self.request.user),
pk=self.kwargs["category"],
)
return super().get_queryset().filter(category=self.category)
return super().get_queryset()
def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)
if "category" in self.kwargs:
return context_data | {"category": self.category}
if "account" in self.kwargs:
return context_data | {"account": self.account}
return context_data
class TransactionMonthView(UserMixin, TransactionACMixin, MonthArchiveView):
model = Transaction model = Transaction
date_field = "date" date_field = "date"
context_object_name = "transactions" context_object_name = "transactions"
month_format = "%m" month_format = "%m"
def get_queryset(self):
if "account" in self.kwargs:
self.account = get_object_or_404(
Account.objects.filter(user=self.request.user),
pk=self.kwargs["account"],
)
return super().get_queryset().filter(account=self.account)
if "category" in self.kwargs:
self.category = get_object_or_404(
Category.objects.filter(user=self.request.user),
pk=self.kwargs["category"],
)
return super().get_queryset().filter(category=self.category)
return super().get_queryset() class TransactionYearView(UserMixin, TransactionACMixin, YearArchiveView):
def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)
if "category" in self.kwargs:
return context_data | {"category": self.category}
if "account" in self.kwargs:
return context_data | {"account": self.account}
return context_data
class TransactionYearView(UserMixin, YearArchiveView):
model = Transaction model = Transaction
date_field = "date" date_field = "date"
context_object_name = "transactions" context_object_name = "transactions"
make_object_list = True make_object_list = True
def get_queryset(self):
if "account" in self.kwargs:
self.account = get_object_or_404(
Account.objects.filter(user=self.request.user),
pk=self.kwargs["account"],
)
return super().get_queryset().filter(account=self.account)
if "category" in self.kwargs:
self.category = get_object_or_404(
Category.objects.filter(user=self.request.user),
pk=self.kwargs["category"],
)
return super().get_queryset().filter(category=self.category)
return super().get_queryset()
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs) context_data = super().get_context_data(**kwargs)
context_data |= { return context_data | {
"history": history( "history": history(
context_data["transactions"].exclude(category__budget=False) context_data["transactions"].exclude(category__budget=False)
), ),
} }
if "category" in self.kwargs:
return context_data | {"category": self.category}
if "account" in self.kwargs:
return context_data | {"account": self.account}
return context_data