backoffice: display agenda datasources (#48282)

This commit is contained in:
Lauréline Guérin 2021-02-16 14:15:41 +01:00
parent 300b597d7e
commit caa0994caa
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
4 changed files with 98 additions and 10 deletions

View File

@ -98,6 +98,54 @@ def test_data_sources_from_carddefs(pub):
)
def test_data_sources_agenda_without_chrono(pub):
create_superuser(pub)
NamedDataSource.wipe()
data_source = NamedDataSource(name='foobar')
data_source.data_source = {'type': 'json', 'value': 'http://some.url'}
data_source.external = 'agenda'
data_source.store()
app = login(get_app(pub))
resp = app.get('/backoffice/settings/data-sources/')
assert 'Agendas' not in resp.text
assert 'There are no data sources from agendas.' not in resp.text
def test_data_sources_agenda(pub, chrono_url):
create_superuser(pub)
NamedDataSource.wipe()
app = login(get_app(pub))
resp = app.get('/backoffice/settings/data-sources/')
assert 'Agendas' in resp.text
assert 'There are no agendas.' in resp.text
data_source = NamedDataSource(name='foobar')
data_source.data_source = {'type': 'json', 'value': 'http://some.url'}
data_source.store()
resp = app.get('/backoffice/settings/data-sources/')
assert 'Agendas' in resp.text
assert 'There are no agendas.' in resp.text
data_source.external = 'agenda'
data_source.store()
resp = app.get('/backoffice/settings/data-sources/')
assert 'Agendas' in resp.text
assert 'There are no agendas.' not in resp.text
assert '<li><a href="%s/">foobar (foobar)</a></li>' % data_source.id in resp.text
data_source.external_status = 'not-found'
data_source.store()
resp = app.get('/backoffice/settings/data-sources/')
assert (
'<li><a href="%s/">foobar (foobar) - <span class="extra-info">not found</span></a></li>'
% data_source.id
in resp.text
)
def test_data_sources_new(pub):
create_superuser(pub)
NamedDataSource.wipe()

View File

@ -32,7 +32,7 @@ from wcs.qommon.form import get_session
from wcs.qommon import misc
from wcs.qommon.backoffice.menu import html_top
from wcs.carddef import CardDef
from wcs.data_sources import NamedDataSource, DataSourceSelectionWidget, get_structured_items
from wcs.data_sources import NamedDataSource, DataSourceSelectionWidget, get_structured_items, has_chrono
from wcs.formdef import FormDef, get_formdefs_of_all_kinds
from wcs.backoffice.snapshots import SnapshotsDirectory
@ -369,12 +369,21 @@ class NamedDataSourcesDirectory(Directory):
def _q_index(self):
html_top('datasources', title=_('Data Sources'))
data_sources = []
agenda_data_sources = []
for ds in NamedDataSource.select(order_by='name'):
if ds.external == 'agenda':
agenda_data_sources.append(ds)
else:
data_sources.append(ds)
generated_data_sources = list(CardDef.get_carddefs_as_data_source())
generated_data_sources.sort(key=lambda x: misc.simplify(x[1]))
return template.QommonTemplateResponse(
templates=['wcs/backoffice/data-sources.html'],
context={
'data_sources': NamedDataSource.select(order_by='name'),
'data_sources': data_sources,
'has_chrono': has_chrono(get_publisher()),
'agenda_data_sources': agenda_data_sources,
'generated_data_sources': generated_data_sources,
},
)

View File

@ -72,15 +72,29 @@ class DataSourceSelectionWidget(CompositeWidget):
options.append(OptGroup(_('Cards')))
options.extend(cards_options)
nds_options = [
(
x.slug,
x.name,
x.slug,
{'data-type': x.type, 'data-maybe-datetimes': 'true' if x.maybe_datetimes() else 'false'},
nds_options = []
nds_agenda_options = []
for ds in NamedDataSource.select():
option = (
ds.slug,
ds.name,
ds.slug,
{
'data-type': ds.type,
'data-maybe-datetimes': 'true' if ds.maybe_datetimes() else 'false',
},
)
for x in NamedDataSource.select()
]
if ds.external == 'agenda':
nds_agenda_options.append(option)
else:
nds_options.append(option)
nds_agenda_options.sort(key=lambda x: misc.simplify(x[1]))
if nds_agenda_options:
options.append(OptGroup(_('Agendas')))
options.extend(nds_agenda_options)
nds_options.sort(key=lambda x: misc.simplify(x[1]))
if nds_options:
options.append(OptGroup(_('Manually Configured Data Sources')))

View File

@ -24,6 +24,23 @@
{% endif %}
</div>
{% if has_chrono %}
<div class="section">
<h2>{% trans "Agendas" %}</h2>
{% if agenda_data_sources %}
<ul class="objects-list single-links">
{% for data_source in agenda_data_sources %}
<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>
{% endfor %}
</ul>
{% else %}
<div>
{% trans "There are no agendas." %}
</div>
{% endif %}
</div>
{% endif %}
<div class="section">
<h2>{% trans "Manually Configured Data Sources" %}</h2>
{% if data_sources %}