Skip to content

Commit

Permalink
🗃️(dashboard) refactor DeliveryPoint and Entity models
Browse files Browse the repository at this point in the history
- Replaced `entities` ManyToMany relationship with a ForeignKey in DeliveryPoint.
- Introduced slug field for Entity.
- Added `proxy_for` ManyToManyField in Entity on itself.
- Enhanced model tests for new relationships and integrity checks.
- Reset Entity and DeliveryPoint migrations
- update pipenv
  • Loading branch information
ssorin committed Nov 26, 2024
1 parent b26402b commit 1246eba
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 128 deletions.
2 changes: 1 addition & 1 deletion src/dashboard/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ name = "pypi"
Django = "==5.1.3"
django-dsfr = "==1.4.3"
django-environ = "==0.11.2"
django-extensions = "==3.2.3"
gunicorn = "==23.0.0"
psycopg = {extras = ["pool", "binary"], version = "==3.2.3"}
whitenoise = "==6.8.2"

[dev-packages]
black = "==24.10.0"
django-extensions = "==3.2.3"
django-stubs = {extras = ["compatible-mypy"], version = "==5.1.1"}
djlint = "==1.36.1"
factory-boy = "==3.3.1"
Expand Down
152 changes: 76 additions & 76 deletions src/dashboard/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/dashboard/apps/consent/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.1.3 on 2024-11-21 11:26
# Generated by Django 5.1.3 on 2024-11-26 14:18

import django.db.models.deletion
import django.utils.timezone
Expand Down
22 changes: 11 additions & 11 deletions src/dashboard/apps/core/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ def users(self, create, extracted, **kwargs):
# Add the iterable of groups using bulk addition
self.users.add(*extracted)

@factory.post_generation
def proxy_for(self, create, extracted, **kwargs):
"""Method to add `proxy_for` after the entity is created."""
if not create or not extracted:
# Simple build, or nothing to add, do nothing.
return

self.proxy_for.add(*extracted)


class DeliveryPointFactory(factory.django.DjangoModelFactory):
"""Factory class for creating instances of the DeliveryPoint model."""

class Meta: # noqa: D106
model = DeliveryPoint

provider_id = factory.Sequence(lambda n: "provider_%d" % n)

@factory.post_generation
def entities(self, create, extracted, **kwargs):
"""Method to add entities after the delivery point is created."""
if not create or not extracted:
# Simple build, or nothing to add, do nothing.
return

# Add the iterable of groups using bulk addition
self.entities.add(*extracted)
delivery_point_id = factory.Sequence(lambda n: "dp_%d" % n)
entity = factory.SubFactory(EntityFactory)
42 changes: 31 additions & 11 deletions src/dashboard/apps/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by Django 5.1.3 on 2024-11-21 11:26
# Generated by Django 5.1.3 on 2024-11-26 14:18

import django.db.models.deletion
import django.utils.timezone
import django_extensions.db.fields
import uuid
from django.conf import settings
from django.db import migrations, models
Expand Down Expand Up @@ -41,10 +43,26 @@ class Migration(migrations.Migration):
blank=True, null=True, verbose_name="updated at"
),
),
(
"slug",
django_extensions.db.fields.AutoSlugField(
blank=True,
editable=False,
populate_from="name",
unique=True,
verbose_name="slug",
),
),
(
"name",
models.CharField(max_length=64, unique=True, verbose_name="name"),
),
(
"proxy_for",
models.ManyToManyField(
blank=True, to="qcd_core.entity", verbose_name="proxy for"
),
),
(
"users",
models.ManyToManyField(
Expand All @@ -53,8 +71,8 @@ class Migration(migrations.Migration):
),
],
options={
"verbose_name": "Entity",
"verbose_name_plural": "Entities",
"verbose_name": "entity",
"verbose_name_plural": "entities",
"ordering": ["name"],
},
),
Expand Down Expand Up @@ -85,24 +103,26 @@ class Migration(migrations.Migration):
),
),
(
"provider_id",
models.CharField(max_length=64, verbose_name="provider id"),
"delivery_point_id",
models.CharField(max_length=64, verbose_name="delivery point id"),
),
(
"is_active",
models.BooleanField(default=True, verbose_name="is active"),
),
(
"entities",
models.ManyToManyField(
to="qcd_core.entity", verbose_name="entities"
"entity",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="qcd_core.entity",
verbose_name="entity",
),
),
],
options={
"verbose_name": "Delivery point",
"verbose_name_plural": "Delivery points",
"ordering": ["provider_id"],
"verbose_name": "delivery point",
"verbose_name_plural": "delivery points",
"ordering": ["delivery_point_id"],
},
),
]
Loading

0 comments on commit 1246eba

Please sign in to comment.