From d23bb074b6d73c121b0c8aa0f841301e2960c0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= Date: Tue, 9 Aug 2022 09:46:23 +0200 Subject: [PATCH] wcs: update card cell model (#68037) add fields only_for_user & limit --- .../wcs/migrations/0048_card_pagination.py | 25 +++++++++++++++++++ .../wcs/migrations/0049_card_pagination.py | 24 ++++++++++++++++++ combo/apps/wcs/models.py | 4 +++ 3 files changed, 53 insertions(+) create mode 100644 combo/apps/wcs/migrations/0048_card_pagination.py create mode 100644 combo/apps/wcs/migrations/0049_card_pagination.py diff --git a/combo/apps/wcs/migrations/0048_card_pagination.py b/combo/apps/wcs/migrations/0048_card_pagination.py new file mode 100644 index 00000000..239ac7fc --- /dev/null +++ b/combo/apps/wcs/migrations/0048_card_pagination.py @@ -0,0 +1,25 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wcs', '0047_careforms_title'), + ] + + operations = [ + migrations.AddField( + model_name='wcscardinfoscell', + name='limit', + field=models.PositiveSmallIntegerField( + blank=True, null=True, verbose_name='Number of cards per page (default 10)' + ), + ), + migrations.AddField( + model_name='wcscardinfoscell', + name='only_for_user', + field=models.BooleanField( + default=False, verbose_name='Limit to cards linked to the logged-in user' + ), + ), + ] diff --git a/combo/apps/wcs/migrations/0049_card_pagination.py b/combo/apps/wcs/migrations/0049_card_pagination.py new file mode 100644 index 00000000..b15f1f28 --- /dev/null +++ b/combo/apps/wcs/migrations/0049_card_pagination.py @@ -0,0 +1,24 @@ +from django.db import migrations + + +def update_only_for_user(apps, schema_editor): + WcsCardInfosCell = apps.get_model('wcs', 'WcsCardInfosCell') + for cell in WcsCardInfosCell.objects.all(): + if not cell.carddef_reference: + continue + parts = cell.carddef_reference.split(':') + if len(parts) <= 2: + continue + cell.only_for_user = True + cell.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('wcs', '0048_card_pagination'), + ] + + operations = [ + migrations.RunPython(update_only_for_user, migrations.RunPython.noop), + ] diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py index e52648f7..68448470 100644 --- a/combo/apps/wcs/models.py +++ b/combo/apps/wcs/models.py @@ -945,7 +945,11 @@ class WcsCardInfosCell(CardMixin, CellBase): carddef_reference = models.CharField(_('Card Model'), max_length=150) related_card_path = models.CharField(_('Card Identifier'), max_length=1000, blank=True) card_ids = models.CharField(_('Other Card Identifiers'), max_length=1000, blank=True) + only_for_user = models.BooleanField(_('Limit to cards linked to the logged-in user'), default=False) without_user = models.BooleanField(_('Ignore the logged-in user'), default=False) + limit = models.PositiveSmallIntegerField( + _('Number of cards per page (default 10)'), null=True, blank=True + ) custom_schema = JSONField(blank=True, default=dict) title_type = models.CharField(