Split backend in applications
This commit is contained in:
parent
a0d0b5d594
commit
b05c3e6760
47 changed files with 1463 additions and 866 deletions
0
nummi/account/__init__.py
Normal file
0
nummi/account/__init__.py
Normal file
6
nummi/account/apps.py
Normal file
6
nummi/account/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AccountConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "account"
|
13
nummi/account/forms.py
Normal file
13
nummi/account/forms.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from main.forms import NummiForm
|
||||
|
||||
from .models import Account
|
||||
|
||||
|
||||
class AccountForm(NummiForm):
|
||||
class Meta:
|
||||
model = Account
|
||||
fields = [
|
||||
"name",
|
||||
"icon",
|
||||
"default",
|
||||
]
|
65
nummi/account/migrations/0001_initial.py
Normal file
65
nummi/account/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
# Generated by Django 4.1.4 on 2023-04-22 09:01
|
||||
|
||||
import uuid
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("main", "0002_segmentation"),
|
||||
]
|
||||
|
||||
state_operations = [
|
||||
migrations.CreateModel(
|
||||
name="Account",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.UUIDField(
|
||||
default=uuid.uuid4,
|
||||
editable=False,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
),
|
||||
),
|
||||
(
|
||||
"name",
|
||||
models.CharField(
|
||||
default="Account", max_length=64, verbose_name="Name"
|
||||
),
|
||||
),
|
||||
(
|
||||
"icon",
|
||||
models.SlugField(
|
||||
default="bank", max_length=24, verbose_name="Icon"
|
||||
),
|
||||
),
|
||||
("default", models.BooleanField(default=False, verbose_name="Default")),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
editable=False,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
verbose_name="User",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "Account",
|
||||
"verbose_name_plural": "Accounts",
|
||||
"ordering": ["-default", "name"],
|
||||
"db_table": "account_account",
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.SeparateDatabaseAndState(state_operations=state_operations)
|
||||
]
|
0
nummi/account/migrations/__init__.py
Normal file
0
nummi/account/migrations/__init__.py
Normal file
49
nummi/account/models.py
Normal file
49
nummi/account/models.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
from uuid import uuid4
|
||||
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from main.models import UserModel
|
||||
|
||||
|
||||
class Account(UserModel):
|
||||
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
name = models.CharField(max_length=64, default=_("Account"), verbose_name=_("Name"))
|
||||
icon = models.SlugField(
|
||||
max_length=24,
|
||||
default="bank",
|
||||
verbose_name=_("Icon"),
|
||||
)
|
||||
default = models.BooleanField(default=False, verbose_name=_("Default"))
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.default:
|
||||
for ac in Account.objects.filter(user=self.user, default=True):
|
||||
ac.default = False
|
||||
ac.save()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("account", kwargs={"pk": self.pk})
|
||||
|
||||
def get_delete_url(self):
|
||||
return reverse("del_account", kwargs={"pk": self.pk})
|
||||
|
||||
class Meta:
|
||||
ordering = ["-default", "name"]
|
||||
verbose_name = _("Account")
|
||||
verbose_name_plural = _("Accounts")
|
||||
|
||||
|
||||
class AccountModel(UserModel):
|
||||
account = models.ForeignKey(
|
||||
Account,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_("Account"),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
33
nummi/account/urls.py
Normal file
33
nummi/account/urls.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("account", views.AccountCreateView.as_view(), name="new_account"),
|
||||
path("account/<pk>", views.AccountUpdateView.as_view(), name="account"),
|
||||
path(
|
||||
"account/<pk>/transactions",
|
||||
views.AccountTListView.as_view(),
|
||||
name="account_transactions",
|
||||
),
|
||||
path(
|
||||
"account/<pk>/statements",
|
||||
views.AccountSListView.as_view(),
|
||||
name="account_statements",
|
||||
),
|
||||
path(
|
||||
"account/<account>/statement",
|
||||
views.StatementCreateView.as_view(),
|
||||
name="new_statement",
|
||||
),
|
||||
path(
|
||||
"account/<pk>/delete",
|
||||
views.AccountDeleteView.as_view(),
|
||||
name="del_account",
|
||||
),
|
||||
path(
|
||||
"account/<account>/history/<int:year>/<int:month>",
|
||||
views.TransactionMonthView.as_view(),
|
||||
name="transaction_month",
|
||||
),
|
||||
]
|
68
nummi/account/views.py
Normal file
68
nummi/account/views.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
from django.urls import reverse_lazy
|
||||
from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView
|
||||
from snapshot.views import SnapshotListView
|
||||
from transaction.utils import history
|
||||
from transaction.views import TransactionListView
|
||||
|
||||
from .forms import AccountForm
|
||||
from .models import Account
|
||||
|
||||
|
||||
class AccountCreateView(NummiCreateView):
|
||||
model = Account
|
||||
form_class = AccountForm
|
||||
template_name = "main/form/account.html"
|
||||
|
||||
|
||||
class AccountUpdateView(NummiUpdateView):
|
||||
model = Account
|
||||
form_class = AccountForm
|
||||
template_name = "main/form/account.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
_max = 8
|
||||
data = super().get_context_data(**kwargs)
|
||||
account = data["form"].instance
|
||||
|
||||
_transactions = account.transaction_set.all()
|
||||
if _transactions.count() > _max:
|
||||
data["transactions_url"] = reverse_lazy(
|
||||
"account_transactions", args=(account.pk,)
|
||||
)
|
||||
_snapshots = account.snapshot_set.all()
|
||||
if _snapshots.count() > _max:
|
||||
data["snapshots_url"] = reverse_lazy(
|
||||
"account_snapshots", args=(account.pk,)
|
||||
)
|
||||
|
||||
return data | {
|
||||
"transactions": _transactions[:8],
|
||||
"new_snapshot_url": reverse_lazy(
|
||||
"new_snapshot", kwargs={"account": account.pk}
|
||||
),
|
||||
"snapshots": _snapshots[:8],
|
||||
"history": history(account.transaction_set),
|
||||
}
|
||||
|
||||
|
||||
class AccountDeleteView(NummiDeleteView):
|
||||
model = Account
|
||||
|
||||
|
||||
class AccountMixin:
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(account=self.kwargs.get("pk"))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(**kwargs) | {
|
||||
"object": Account.objects.get(pk=self.kwargs.get("pk")),
|
||||
"account": True,
|
||||
}
|
||||
|
||||
|
||||
class AccountTListView(AccountMixin, TransactionListView):
|
||||
pass
|
||||
|
||||
|
||||
class AccountSListView(AccountMixin, SnapshotListView):
|
||||
pass
|
Loading…
Add table
Add a link
Reference in a new issue