Compare commits

...

3 commits

Author SHA1 Message Date
e438cfd78a
Import sorting 2022-12-29 22:18:14 +01:00
0d9ff3b771
Migration 2022-12-29 22:18:03 +01:00
fd15e60085
Validate icon slugs 2022-12-29 22:17:55 +01:00
4 changed files with 155 additions and 24 deletions

View file

@ -1,12 +1,6 @@
from django.forms import ModelForm
from .models import (
Account,
Category,
Invoice,
Snapshot,
Transaction,
)
from .models import Account, Category, Invoice, Snapshot, Transaction
class NummiForm(ModelForm):

View file

@ -0,0 +1,141 @@
# Generated by Django 4.1.4 on 2022-12-29 21:15
import datetime
import re
import django.core.validators
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("main", "0019_snapshot_sum"),
]
operations = [
migrations.AlterModelOptions(
name="account",
options={
"ordering": ["name"],
"verbose_name": "Compte",
"verbose_name_plural": "Comptes",
},
),
migrations.AlterModelOptions(
name="snapshot",
options={
"ordering": ["-date"],
"verbose_name": "Relevé",
"verbose_name_plural": "Relevés",
},
),
migrations.AlterField(
model_name="account",
name="icon",
field=models.CharField(
default="building-columns",
max_length=64,
validators=[
django.core.validators.RegexValidator(
re.compile("^[-a-zA-Z0-9_]+\\Z"),
"Enter a valid “slug” consisting of letters, numbers, underscores or hyphens.",
"invalid",
)
],
verbose_name="Icône",
),
),
migrations.AlterField(
model_name="account",
name="name",
field=models.CharField(default="Compte", max_length=64, verbose_name="Nom"),
),
migrations.AlterField(
model_name="category",
name="icon",
field=models.CharField(
default="folder",
max_length=64,
validators=[
django.core.validators.RegexValidator(
re.compile("^[-a-zA-Z0-9_]+\\Z"),
"Enter a valid “slug” consisting of letters, numbers, underscores or hyphens.",
"invalid",
)
],
verbose_name="Icône",
),
),
migrations.AlterField(
model_name="snapshot",
name="account",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="main.account",
verbose_name="Compte",
),
),
migrations.AlterField(
model_name="snapshot",
name="date",
field=models.DateField(
default=datetime.date.today, verbose_name="Date de fin"
),
),
migrations.AlterField(
model_name="snapshot",
name="start_date",
field=models.DateField(
default=datetime.date.today, verbose_name="Date de début"
),
),
migrations.AlterField(
model_name="snapshot",
name="start_value",
field=models.DecimalField(
decimal_places=2,
default=0,
max_digits=12,
verbose_name="Valeur de début",
),
),
migrations.AlterField(
model_name="snapshot",
name="sum",
field=models.DecimalField(
decimal_places=2,
default=0,
editable=False,
max_digits=12,
verbose_name="Différence des transactions",
),
),
migrations.AlterField(
model_name="snapshot",
name="value",
field=models.DecimalField(
decimal_places=2, default=0, max_digits=12, verbose_name="Valeur de fin"
),
),
migrations.AlterField(
model_name="transaction",
name="account",
field=models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
to="main.account",
verbose_name="Compte",
),
),
migrations.AlterField(
model_name="transaction",
name="snapshot",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="main.snapshot",
verbose_name="Relevé",
),
),
]

View file

@ -3,7 +3,7 @@ import pathlib
import uuid
from django.conf import settings
from django.core.validators import FileExtensionValidator
from django.core.validators import FileExtensionValidator, validate_slug
from django.db import models, transaction
from django.urls import reverse
from django.utils.translation import gettext as _
@ -34,7 +34,10 @@ class Account(CustomModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=64, default=_("Account"), verbose_name=_("Name"))
icon = models.CharField(
max_length=64, default="building-columns", verbose_name=_("Icon")
max_length=64,
default="building-columns",
verbose_name=_("Icon"),
validators=[validate_slug],
)
def __str__(self):
@ -76,7 +79,12 @@ class Category(CustomModel):
name = models.CharField(
max_length=64, default=_("Category"), verbose_name=_("Name")
)
icon = models.CharField(max_length=64, default="folder", verbose_name=_("Icon"))
icon = models.CharField(
max_length=64,
default="folder",
verbose_name=_("Icon"),
validators=[validate_slug],
)
budget = models.BooleanField(default=True, verbose_name=_("Budget"))
def __str__(self):

View file

@ -18,20 +18,8 @@ from django.views.generic import (
)
from django.views.generic.edit import ProcessFormView
from .models import (
Account,
Category,
Invoice,
Snapshot,
Transaction,
)
from .forms import (
AccountForm,
CategoryForm,
InvoiceForm,
SnapshotForm,
TransactionForm,
)
from .forms import AccountForm, CategoryForm, InvoiceForm, SnapshotForm, TransactionForm
from .models import Account, Category, Invoice, Snapshot, Transaction
class IndexView(LoginRequiredMixin, TemplateView):