Projet

Général

Profil

0001-wcs-custom-title-for-forms-in-your-care-cell-61589.patch

Lauréline Guérin, 04 juillet 2022 15:46

Télécharger (6,65 ko)

Voir les différences:

Subject: [PATCH] wcs: custom title for forms in your care cell (#61589)

 .../wcs/migrations/0047_careforms_title.py    | 16 ++++++
 combo/apps/wcs/models.py                      |  1 +
 .../wcs/templates/combo/wcs/care_forms.html   |  2 +-
 tests/test_wcs.py                             | 57 +++++++++++--------
 4 files changed, 51 insertions(+), 25 deletions(-)
 create mode 100644 combo/apps/wcs/migrations/0047_careforms_title.py
combo/apps/wcs/migrations/0047_careforms_title.py
1
from django.db import migrations, models
2

  
3

  
4
class Migration(migrations.Migration):
5

  
6
    dependencies = [
7
        ('wcs', '0046_display_condition'),
8
    ]
9

  
10
    operations = [
11
        migrations.AddField(
12
            model_name='wcscareformscell',
13
            name='custom_title',
14
            field=models.CharField(blank=True, max_length=150, verbose_name='Custom Title'),
15
        ),
16
    ]
combo/apps/wcs/models.py
723 723
@register_cell_class
724 724
class WcsCareFormsCell(CategoriesAndWcsSiteValidityMixin, CategoriesFilteringMixin, WcsDataBaseCell):
725 725
    categories = JSONField(_('Categories'), blank=True, default=dict)
726
    custom_title = models.CharField(_('Custom Title'), max_length=150, blank=True)
726 727

  
727 728
    api_url = '/api/forms/?limit=10'
728 729
    variable_name = 'care_forms'
combo/apps/wcs/templates/combo/wcs/care_forms.html
1 1
{% load i18n combo %}
2 2
{% block cell-content %}
3 3
{% for slug, forms in care_forms.items %}
4
  <h2>{% trans "Forms to process" %} - {{ forms.title }}</h2>
4
  <h2>{% if cell.custom_title %}{{ cell.custom_title }}{% else %}{% trans "Forms to process" %} - {{ forms.title }}{% endif %}</h2>
5 5
  {% if forms.data %}
6 6
  <table id="listing" class="main clickable-rows">
7 7
    <thead>
tests/test_wcs.py
1009 1009
    assert cell.get_additional_label() == 'test'
1010 1010

  
1011 1011

  
1012
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
1013
def test_manager_care_forms_cell(mock_send, app, admin_user):
1014
    page = Page(title='One', slug='one', template_name='standard')
1015
    page.save()
1016
    app = login(app)
1017
    resp = app.get('/manage/pages/%s/' % page.id)
1018
    resp = app.get(
1019
        resp.html.find('option', **{'data-add-url': re.compile('wcscareformscell')})['data-add-url']
1020
    )
1021

  
1022
    cells = Page.objects.get(id=page.id).get_cells()
1023
    assert len(cells) == 1
1024
    assert isinstance(cells[0], WcsCareFormsCell)
1025

  
1026
    resp = app.get('/manage/pages/%s/' % page.id)
1027
    assert not resp.pyquery('[data-tab-slug="general"] input[name$="custom_title"]')
1028
    assert resp.pyquery('[data-tab-slug="appearance"] input[name$="custom_title"]')
1029
    assert (
1030
        resp.pyquery.find('div.cell [data-tab-slug="advanced"] input[name$="cache_duration"]').val() == '120'
1031
    )
1032
    resp.forms[0]['c%s-cache_duration' % cells[0].get_reference()] = '10'
1033
    manager_submit_cell(resp.forms[0])
1034
    cells[0].refresh_from_db()
1035
    assert cells[0].cache_duration == 10
1036

  
1037

  
1012 1038
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
1013 1039
def test_care_forms_cell_render(mock_send, context):
1014 1040
    page = Page(title='xxx', slug='test_care_forms_cell_render', template_name='standard')
......
1029 1055
        is_portal_agent.return_value = True
1030 1056
        result = cell.render(context)
1031 1057

  
1058
    assert 'Forms to process - test' in result
1032 1059
    assert 'http://127.0.0.1:8999/backoffice/management/foobar/1' in result
1033 1060
    assert 'http://127.0.0.1:8999/backoffice/management/foobar/2' in result
1034 1061
    assert '"http://127.0.0.1:8999/backoffice/management/listing"' in result
1062
    assert 'Forms to process - test2' in result
1035 1063
    assert 'http://127.0.0.2:8999/backoffice/management/foobar/1' in result
1036 1064
    assert 'http://127.0.0.2:8999/backoffice/management/foobar/2' in result
1037 1065
    assert '"http://127.0.0.2:8999/backoffice/management/listing"' in result
1038 1066

  
1067
    cell.custom_title = 'Foo Bar'
1039 1068
    with mock.patch('combo.apps.wcs.models.is_portal_agent') as is_portal_agent:
1040 1069
        is_portal_agent.return_value = False
1041 1070
        result = cell.render(context)
1042 1071

  
1072
    assert 'Forms to process - test' not in result
1073
    assert 'Foo Bar' in result
1043 1074
    assert 'http://127.0.0.1:8999/foobar/1' in result
1044 1075
    assert 'http://127.0.0.1:8999/foobar/2' in result
1076
    assert 'Forms to process - test2' not in result
1077
    assert 'Foo Bar' in result
1045 1078
    assert 'http://127.0.0.2:8999/foobar/1' in result
1046 1079
    assert 'http://127.0.0.2:8999/foobar/2' in result
1047 1080
    assert '/listing' not in result
......
1621 1654
    assert resp.pyquery('[data-tab-slug="appearance"] input[name$="custom_title"]')
1622 1655

  
1623 1656

  
1624
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
1625
def test_manager_forms_in_your_care_cell(mock_send, app, admin_user):
1626
    page = Page(title='One', slug='one', template_name='standard')
1627
    page.save()
1628
    app = login(app)
1629
    resp = app.get('/manage/pages/%s/' % page.id)
1630
    resp = app.get(
1631
        resp.html.find('option', **{'data-add-url': re.compile('wcscareformscell')})['data-add-url']
1632
    )
1633

  
1634
    cells = Page.objects.get(id=page.id).get_cells()
1635
    assert len(cells) == 1
1636
    assert isinstance(cells[0], WcsCareFormsCell)
1637

  
1638
    resp = app.get('/manage/pages/%s/' % page.id)
1639
    assert (
1640
        resp.pyquery.find('div.cell [data-tab-slug="advanced"] input[name$="cache_duration"]').val() == '120'
1641
    )
1642
    resp.forms[0]['c%s-cache_duration' % cells[0].get_reference()] = '10'
1643
    manager_submit_cell(resp.forms[0])
1644
    cells[0].refresh_from_db()
1645
    assert cells[0].cache_duration == 10
1646

  
1647

  
1648 1657
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
1649 1658
def test_manager_cards_cell(mock_send, app, admin_user):
1650 1659
    page = Page.objects.create(title='xxx', slug='test_cards_cell_save_cache', template_name='standard')
1651
-