Compare commits
No commits in common. "d595d734173f6b74dc2db74dc5b00f0d2cebc673" and "51d57564c43ab9e0e0dc80803fdfe878f27fd1b9" have entirely different histories.
d595d73417
...
51d57564c4
3 changed files with 4 additions and 22 deletions
|
@ -53,12 +53,9 @@ class TransactionForm(NummiForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
_user = kwargs.get("user")
|
_user = kwargs.get("user")
|
||||||
_disable_snapshot = kwargs.pop("disable_snapshot", False)
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields["category"].queryset = Category.objects.filter(user=_user)
|
self.fields["category"].queryset = Category.objects.filter(user=_user)
|
||||||
self.fields["snapshot"].queryset = Snapshot.objects.filter(user=_user)
|
self.fields["snapshot"].queryset = Snapshot.objects.filter(user=_user)
|
||||||
if _disable_snapshot:
|
|
||||||
self.fields["snapshot"].disabled = True
|
|
||||||
|
|
||||||
|
|
||||||
class InvoiceForm(NummiForm):
|
class InvoiceForm(NummiForm):
|
||||||
|
@ -85,7 +82,6 @@ class SnapshotForm(NummiForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
_user = kwargs.get("user")
|
_user = kwargs.get("user")
|
||||||
_disable_account = kwargs.pop("disable_account", False)
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields["account"].queryset = Account.objects.filter(user=_user)
|
self.fields["account"].queryset = Account.objects.filter(user=_user)
|
||||||
self.fields["transactions"] = forms.MultipleChoiceField(
|
self.fields["transactions"] = forms.MultipleChoiceField(
|
||||||
|
@ -96,8 +92,6 @@ class SnapshotForm(NummiForm):
|
||||||
label=_("Add transactions"),
|
label=_("Add transactions"),
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
if _disable_account:
|
|
||||||
self.fields["account"].disabled = True
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
instance = super().save(*args, **kwargs)
|
instance = super().save(*args, **kwargs)
|
||||||
|
|
|
@ -116,10 +116,6 @@ nav .skip-link {
|
||||||
nav .skip-link:active,
|
nav .skip-link:active,
|
||||||
nav .skip-link:focus {
|
nav .skip-link:focus {
|
||||||
opacity: initial;
|
opacity: initial;
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
nav a {
|
|
||||||
display: block;
|
|
||||||
}
|
}
|
||||||
nav a.cur {
|
nav a.cur {
|
||||||
font-weight: 550;
|
font-weight: 550;
|
||||||
|
|
|
@ -62,13 +62,15 @@ class UserMixin(LoginRequiredMixin):
|
||||||
def get_queryset(self, **kwargs):
|
def get_queryset(self, **kwargs):
|
||||||
return super().get_queryset().filter(user=self.request.user)
|
return super().get_queryset().filter(user=self.request.user)
|
||||||
|
|
||||||
|
|
||||||
|
class UserFormMixin:
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
return super().get_form_kwargs() | {
|
return super().get_form_kwargs() | {
|
||||||
"user": self.request.user,
|
"user": self.request.user,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class NummiCreateView(UserMixin, CreateView):
|
class NummiCreateView(UserMixin, UserFormMixin, CreateView):
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.user = self.request.user
|
form.instance.user = self.request.user
|
||||||
self.next = form.data.get("next", None)
|
self.next = form.data.get("next", None)
|
||||||
|
@ -78,7 +80,7 @@ class NummiCreateView(UserMixin, CreateView):
|
||||||
return self.next or super().get_success_url()
|
return self.next or super().get_success_url()
|
||||||
|
|
||||||
|
|
||||||
class NummiUpdateView(UserMixin, UpdateView):
|
class NummiUpdateView(UserMixin, UserFormMixin, UpdateView):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,11 +117,6 @@ class TransactionCreateView(NummiCreateView):
|
||||||
self.snapshot = _queryset.first()
|
self.snapshot = _queryset.first()
|
||||||
return {"snapshot": self.snapshot}
|
return {"snapshot": self.snapshot}
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
|
||||||
if "snapshot" in self.kwargs:
|
|
||||||
return super().get_form_kwargs() | {"disable_snapshot": True}
|
|
||||||
return super().get_form_kwargs()
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
if "snapshot" in self.kwargs:
|
if "snapshot" in self.kwargs:
|
||||||
return super().get_context_data(**kwargs) | {"snapshot": self.snapshot}
|
return super().get_context_data(**kwargs) | {"snapshot": self.snapshot}
|
||||||
|
@ -161,11 +158,6 @@ class SnapshotCreateView(NummiCreateView):
|
||||||
self.account = _queryset.first()
|
self.account = _queryset.first()
|
||||||
return {"account": self.account}
|
return {"account": self.account}
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
|
||||||
if "account" in self.kwargs:
|
|
||||||
return super().get_form_kwargs() | {"disable_account": True}
|
|
||||||
return super().get_form_kwargs()
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
if "account" in self.kwargs:
|
if "account" in self.kwargs:
|
||||||
return super().get_context_data(**kwargs) | {"account": self.account}
|
return super().get_context_data(**kwargs) | {"account": self.account}
|
||||||
|
|
Loading…
Reference in a new issue