-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [#4789] Add identifier field to ZGWAPIGroupConfig
to make sure there is a unique field that can be used to refer to the groups and identify them when they are loaded using setup-configuration
- Loading branch information
Showing
6 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/openforms/registrations/contrib/zgw_apis/migrations/0016_zgwapigroupconfig_identifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 4.2.16 on 2024-12-02 10:30 | ||
|
||
from django.db import migrations, models | ||
from django.utils.text import slugify | ||
|
||
|
||
def set_zgw_api_group_config_identifier_from_name(apps, schema_editor): | ||
ZGWApiGroupConfig = apps.get_model("zgw_apis", "ZGWApiGroupConfig") | ||
|
||
def generate_unique_identifier(original_identifier, count=0): | ||
identifier = original_identifier + ("-" + str(count) if count else "") | ||
if not ZGWApiGroupConfig.objects.filter(identifier=identifier).exists(): | ||
return identifier | ||
|
||
return generate_unique_identifier(original_identifier, count + 1) | ||
|
||
for row in ZGWApiGroupConfig.objects.all(): | ||
candidate_slug = slugify(row.name) | ||
row.identifier = generate_unique_identifier(candidate_slug) | ||
row.save(update_fields=["identifier"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zgw_apis", "0015_explicit_objects_api_groups"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="zgwapigroupconfig", | ||
name="identifier", | ||
field=models.SlugField( | ||
blank=True, | ||
help_text="A unique, human-friendly identifier to identify this group.", | ||
verbose_name="identifier", | ||
), | ||
), | ||
migrations.RunPython( | ||
set_zgw_api_group_config_identifier_from_name, | ||
reverse_code=migrations.RunPython.noop, | ||
), | ||
] |
22 changes: 22 additions & 0 deletions
22
...orms/registrations/contrib/zgw_apis/migrations/0017_alter_zgwapigroupconfig_identifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 4.2.16 on 2024-12-02 10:31 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("zgw_apis", "0016_zgwapigroupconfig_identifier"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="zgwapigroupconfig", | ||
name="identifier", | ||
field=models.SlugField( | ||
help_text="A unique, human-friendly identifier to identify this group.", | ||
unique=True, | ||
verbose_name="identifier", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters