Projet

Général

Profil

0002-backoffice-display-agenda-datasources-48282.patch

Lauréline Guérin, 16 février 2021 16:00

Télécharger (6,71 ko)

Voir les différences:

Subject: [PATCH 2/5] backoffice: display agenda datasources (#48282)

 tests/admin_pages/test_datasource.py          | 48 +++++++++++++++++++
 wcs/admin/data_sources.py                     | 13 ++++-
 wcs/data_sources.py                           | 30 ++++++++----
 .../wcs/backoffice/data-sources.html          | 17 +++++++
 4 files changed, 98 insertions(+), 10 deletions(-)
tests/admin_pages/test_datasource.py
98 98
    )
99 99

  
100 100

  
101
def test_data_sources_agenda_without_chrono(pub):
102
    create_superuser(pub)
103
    NamedDataSource.wipe()
104

  
105
    data_source = NamedDataSource(name='foobar')
106
    data_source.data_source = {'type': 'json', 'value': 'http://some.url'}
107
    data_source.external = 'agenda'
108
    data_source.store()
109

  
110
    app = login(get_app(pub))
111
    resp = app.get('/backoffice/settings/data-sources/')
112
    assert 'Agendas' not in resp.text
113
    assert 'There are no data sources from agendas.' not in resp.text
114

  
115

  
116
def test_data_sources_agenda(pub, chrono_url):
117
    create_superuser(pub)
118
    NamedDataSource.wipe()
119

  
120
    app = login(get_app(pub))
121
    resp = app.get('/backoffice/settings/data-sources/')
122
    assert 'Agendas' in resp.text
123
    assert 'There are no agendas.' in resp.text
124

  
125
    data_source = NamedDataSource(name='foobar')
126
    data_source.data_source = {'type': 'json', 'value': 'http://some.url'}
127
    data_source.store()
128
    resp = app.get('/backoffice/settings/data-sources/')
129
    assert 'Agendas' in resp.text
130
    assert 'There are no agendas.' in resp.text
131

  
132
    data_source.external = 'agenda'
133
    data_source.store()
134
    resp = app.get('/backoffice/settings/data-sources/')
135
    assert 'Agendas' in resp.text
136
    assert 'There are no agendas.' not in resp.text
137
    assert '<li><a href="%s/">foobar (foobar)</a></li>' % data_source.id in resp.text
138

  
139
    data_source.external_status = 'not-found'
140
    data_source.store()
141
    resp = app.get('/backoffice/settings/data-sources/')
142
    assert (
143
        '<li><a href="%s/">foobar (foobar) - <span class="extra-info">not found</span></a></li>'
144
        % data_source.id
145
        in resp.text
146
    )
147

  
148

  
101 149
def test_data_sources_new(pub):
102 150
    create_superuser(pub)
103 151
    NamedDataSource.wipe()
wcs/admin/data_sources.py
32 32
from wcs.qommon import misc
33 33
from wcs.qommon.backoffice.menu import html_top
34 34
from wcs.carddef import CardDef
35
from wcs.data_sources import NamedDataSource, DataSourceSelectionWidget, get_structured_items
35
from wcs.data_sources import NamedDataSource, DataSourceSelectionWidget, get_structured_items, has_chrono
36 36
from wcs.formdef import FormDef, get_formdefs_of_all_kinds
37 37
from wcs.backoffice.snapshots import SnapshotsDirectory
38 38

  
......
369 369

  
370 370
    def _q_index(self):
371 371
        html_top('datasources', title=_('Data Sources'))
372
        data_sources = []
373
        agenda_data_sources = []
374
        for ds in NamedDataSource.select(order_by='name'):
375
            if ds.external == 'agenda':
376
                agenda_data_sources.append(ds)
377
            else:
378
                data_sources.append(ds)
372 379
        generated_data_sources = list(CardDef.get_carddefs_as_data_source())
373 380
        generated_data_sources.sort(key=lambda x: misc.simplify(x[1]))
374 381
        return template.QommonTemplateResponse(
375 382
            templates=['wcs/backoffice/data-sources.html'],
376 383
            context={
377
                'data_sources': NamedDataSource.select(order_by='name'),
384
                'data_sources': data_sources,
385
                'has_chrono': has_chrono(get_publisher()),
386
                'agenda_data_sources': agenda_data_sources,
378 387
                'generated_data_sources': generated_data_sources,
379 388
            },
380 389
        )
wcs/data_sources.py
72 72
                options.append(OptGroup(_('Cards')))
73 73
                options.extend(cards_options)
74 74

  
75
            nds_options = [
76
                (
77
                    x.slug,
78
                    x.name,
79
                    x.slug,
80
                    {'data-type': x.type, 'data-maybe-datetimes': 'true' if x.maybe_datetimes() else 'false'},
75
            nds_options = []
76
            nds_agenda_options = []
77

  
78
            for ds in NamedDataSource.select():
79
                option = (
80
                    ds.slug,
81
                    ds.name,
82
                    ds.slug,
83
                    {
84
                        'data-type': ds.type,
85
                        'data-maybe-datetimes': 'true' if ds.maybe_datetimes() else 'false',
86
                    },
81 87
                )
82
                for x in NamedDataSource.select()
83
            ]
88
                if ds.external == 'agenda':
89
                    nds_agenda_options.append(option)
90
                else:
91
                    nds_options.append(option)
92

  
93
            nds_agenda_options.sort(key=lambda x: misc.simplify(x[1]))
94
            if nds_agenda_options:
95
                options.append(OptGroup(_('Agendas')))
96
                options.extend(nds_agenda_options)
97

  
84 98
            nds_options.sort(key=lambda x: misc.simplify(x[1]))
85 99
            if nds_options:
86 100
                options.append(OptGroup(_('Manually Configured Data Sources')))
wcs/templates/wcs/backoffice/data-sources.html
24 24
{% endif %}
25 25
</div>
26 26

  
27
{% if has_chrono %}
28
<div class="section">
29
<h2>{% trans "Agendas" %}</h2>
30
{% if agenda_data_sources %}
31
<ul class="objects-list single-links">
32
  {% for data_source in agenda_data_sources %}
33
  <li><a href="{{ data_source.id }}/">{{ data_source.name }} ({{ data_source.slug }}){% if data_source.external_status == 'not-found' %} - <span class="extra-info">{% trans "not found" %}</span>{% endif %}</a></li>
34
  {% endfor %}
35
</ul>
36
{% else %}
37
<div>
38
{% trans "There are no agendas." %}
39
</div>
40
{% endif %}
41
</div>
42
{% endif %}
43

  
27 44
<div class="section">
28 45
<h2>{% trans "Manually Configured Data Sources" %}</h2>
29 46
{% if data_sources %}
30
-