Projet

Général

Profil

0001-family-agenda_references_template-field-57927.patch

Lauréline Guérin, 21 octobre 2021 14:39

Télécharger (5,97 ko)

Voir les différences:

Subject: [PATCH] family: agenda_references_template field (#57927)

 .../0008_agenda_references_template.py        | 23 +++++++++++++++++++
 .../0009_agenda_references_template.py        | 16 +++++++++++++
 combo/apps/family/models.py                   | 10 +++++---
 tests/test_family.py                          | 22 +++++++++++++++---
 4 files changed, 65 insertions(+), 6 deletions(-)
 create mode 100644 combo/apps/family/migrations/0008_agenda_references_template.py
 create mode 100644 combo/apps/family/migrations/0009_agenda_references_template.py
combo/apps/family/migrations/0008_agenda_references_template.py
1
from django.db import migrations, models
2

  
3

  
4
class Migration(migrations.Migration):
5

  
6
    dependencies = [
7
        ('family', '0007_weekly_agenda_user_template'),
8
    ]
9

  
10
    operations = [
11
        migrations.RenameField(
12
            model_name='weeklyagendacell',
13
            old_name='agenda_reference',
14
            new_name='agenda_references_template',
15
        ),
16
        migrations.AlterField(
17
            model_name='weeklyagendacell',
18
            name='user_external_template',
19
            field=models.CharField(
20
                blank=True, max_length=255, verbose_name='User external reference template'
21
            ),
22
        ),
23
    ]
combo/apps/family/migrations/0009_agenda_references_template.py
1
from django.db import migrations, models
2

  
3

  
4
class Migration(migrations.Migration):
5

  
6
    dependencies = [
7
        ('family', '0008_agenda_references_template'),
8
    ]
9

  
10
    operations = [
11
        migrations.AlterField(
12
            model_name='weeklyagendacell',
13
            name='agenda_references_template',
14
            field=models.CharField(blank=True, max_length=2000, verbose_name='Agenda references template'),
15
        ),
16
    ]
combo/apps/family/models.py
57 57
@register_cell_class
58 58
class WeeklyAgendaCell(JsonCellBase):
59 59
    title = models.CharField(_('Title'), max_length=150, blank=True)
60
    agenda_reference = models.CharField(_('Agenda'), max_length=128)
61
    user_external_template = models.CharField(max_length=255)
60
    agenda_references_template = models.CharField(
61
        _('Agenda references template'), max_length=2000, blank=True
62
    )
63
    user_external_template = models.CharField(
64
        _('User external reference template'), max_length=255, blank=True
65
    )
62 66

  
63 67
    default_template_name = 'family/weekly_agenda.html'
64 68
    force_async = True
......
82 86
            chrono_url += '/'
83 87
        return '%sapi/agendas/datetimes/?agendas=%s&user_external_id=%s&show_past_events=true' % (
84 88
            chrono_url,
85
            self.agenda_reference,
89
            self.agenda_references_template,
86 90
            self.user_external_template,
87 91
        )
88 92

  
tests/test_family.py
6 6
from django.test.client import RequestFactory
7 7

  
8 8
from combo.apps.family.models import WeeklyAgendaCell
9
from combo.apps.wcs.context_processors import Cards
9 10
from combo.data.models import Page
10 11
from combo.utils import NothingInCacheException
11 12

  
......
14 15

  
15 16
@pytest.fixture
16 17
def context():
17
    ctx = {'request': RequestFactory().get('/')}
18
    ctx = {'cards': Cards(), 'request': RequestFactory().get('/')}
18 19
    ctx['request'].user = None
19 20
    ctx['request'].session = {}
20 21
    return ctx
......
70 71
            == 'http://chrono.example.org/api/agendas/datetimes/?agendas=&user_external_id=&show_past_events=true'
71 72
        )
72 73

  
73
    cell.agenda_reference = 'some-agenda'
74
    cell.agenda_references_template = 'some-agenda,other-agenda'
74 75
    cell.save()
75 76
    context['request'].user = MockUserWithNameId()
76 77
    with mock.patch('combo.utils.requests.get') as requests_get:
......
78 79
        cell.render(context)
79 80
        assert (
80 81
            requests_get.call_args_list[0][0][0]
81
            == 'http://chrono.example.org/api/agendas/datetimes/?agendas=some-agenda&user_external_id=&show_past_events=true'
82
            == 'http://chrono.example.org/api/agendas/datetimes/?agendas=some-agenda,other-agenda&user_external_id=&show_past_events=true'
82 83
        )
83 84

  
85
    cell.agenda_references_template = (
86
        '{% load wcs %}{{ cards|objects:"foo"|get_full|first|get:"fields"|get:"bar"|default:"" }}'
87
        ',some-agenda,other-agenda,{{ user_nameid }}'
88
    )
89
    cell.save()
90
    context['request'].user = MockUserWithNameId()
91
    with mock.patch('combo.utils.requests.get') as requests_get:
92
        requests_get.return_value = MockedRequestResponse(content=json.dumps(data))
93
        cell.render(context)
94
        assert (
95
            requests_get.call_args_list[1][0][0]
96
            == 'http://chrono.example.org/api/agendas/datetimes/?agendas=,some-agenda,other-agenda,xyz&user_external_id=&show_past_events=true'
97
        )
98

  
99
    cell.agenda_references_template = 'some-agenda'
84 100
    cell.user_external_template = 'some-key:{{ user_nameid }}'
85 101
    cell.save()
86 102
    with mock.patch('combo.utils.requests.get') as requests_get:
87
-