Projet

Général

Profil

0001-wcs-update-card-cell-model-68037.patch

Lauréline Guérin, 29 août 2022 14:35

Télécharger (3,36 ko)

Voir les différences:

Subject: [PATCH 1/5] 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
combo/apps/wcs/migrations/0048_card_pagination.py
1
from django.db import migrations, models
2

  
3

  
4
class Migration(migrations.Migration):
5

  
6
    dependencies = [
7
        ('wcs', '0047_careforms_title'),
8
    ]
9

  
10
    operations = [
11
        migrations.AddField(
12
            model_name='wcscardinfoscell',
13
            name='limit',
14
            field=models.PositiveSmallIntegerField(
15
                blank=True, null=True, verbose_name='Number of cards per page (default 10)'
16
            ),
17
        ),
18
        migrations.AddField(
19
            model_name='wcscardinfoscell',
20
            name='only_for_user',
21
            field=models.BooleanField(
22
                default=False, verbose_name='Limit to cards linked to the logged-in user'
23
            ),
24
        ),
25
    ]
combo/apps/wcs/migrations/0049_card_pagination.py
1
from django.db import migrations
2

  
3

  
4
def update_only_for_user(apps, schema_editor):
5
    WcsCardInfosCell = apps.get_model('wcs', 'WcsCardInfosCell')
6
    for cell in WcsCardInfosCell.objects.all():
7
        if not cell.carddef_reference:
8
            continue
9
        parts = cell.carddef_reference.split(':')
10
        if len(parts) <= 2:
11
            continue
12
        cell.only_for_user = True
13
        cell.save()
14

  
15

  
16
class Migration(migrations.Migration):
17

  
18
    dependencies = [
19
        ('wcs', '0048_card_pagination'),
20
    ]
21

  
22
    operations = [
23
        migrations.RunPython(update_only_for_user, migrations.RunPython.noop),
24
    ]
combo/apps/wcs/models.py
945 945
    carddef_reference = models.CharField(_('Card Model'), max_length=150)
946 946
    related_card_path = models.CharField(_('Card Identifier'), max_length=1000, blank=True)
947 947
    card_ids = models.CharField(_('Other Card Identifiers'), max_length=1000, blank=True)
948
    only_for_user = models.BooleanField(_('Limit to cards linked to the logged-in user'), default=False)
948 949
    without_user = models.BooleanField(_('Ignore the logged-in user'), default=False)
950
    limit = models.PositiveSmallIntegerField(
951
        _('Number of cards per page (default 10)'), null=True, blank=True
952
    )
949 953
    custom_schema = JSONField(blank=True, default=dict)
950 954

  
951 955
    title_type = models.CharField(
952
-