backoffice: display related form/card origin in inspect page (#46849)
This commit is contained in:
parent
6e1a519e0f
commit
eb16118351
|
@ -5542,25 +5542,32 @@ def test_inspect_page_with_related_objects(pub):
|
|||
resp = app.get('/backoffice/management/external-action-form/1/inspect')
|
||||
assert 'Related Forms/Cards' in resp.text
|
||||
# related form and card
|
||||
assert '<li><a href="http://example.net/backoffice/management/external-form/1/">External Form #1-1</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/data/external-card/1/">External Card #1-1</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/management/external-form/1/">External Form #1-1 (Evolution)</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/data/external-card/1/">External Card #1-1 (Evolution)</a></li>' in resp.text
|
||||
# check related form
|
||||
resp = app.get('/backoffice/management/external-form/1/')
|
||||
assert '<h3>Original form</h3><p><a href="http://example.net/backoffice/management/external-action-form/1/">External action form #2-1</a></p>' in resp.text
|
||||
resp = app.get('/backoffice/management/external-form/1/inspect')
|
||||
# parent
|
||||
assert '<li><a href="http://example.net/backoffice/management/external-action-form/1/">External action form #2-1</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/management/external-action-form/1/">External action form #2-1 (Parent)</a></li>' in resp.text
|
||||
# check related card
|
||||
resp = app.get('/backoffice/data/external-card/1/')
|
||||
assert '<h3>Original form</h3><p><a href="http://example.net/backoffice/management/external-action-form/1/">External action form #2-1</a></p>' in resp.text
|
||||
resp = app.get('/backoffice/data/external-card/1/inspect')
|
||||
# parent
|
||||
assert '<li><a href="http://example.net/backoffice/management/external-action-form/1/">External action form #2-1</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/management/external-action-form/1/">External action form #2-1 (Parent)</a></li>' in resp.text
|
||||
|
||||
external_formdef.data_class().wipe()
|
||||
external_carddef.data_class().wipe()
|
||||
|
||||
# missing form/card data
|
||||
resp = app.get('/backoffice/management/external-action-form/1/inspect')
|
||||
assert 'Related Forms/Cards' in resp.text
|
||||
assert '<li><a href="">Linked "External Form" object by id 1 (Evolution - not found)</a></li>' in resp.text
|
||||
assert '<li><a href="">Linked "External Card" object by id 1 (Evolution - not found)</a></li>' in resp.text
|
||||
|
||||
formdef.data_class().wipe()
|
||||
carddef.data_class().wipe()
|
||||
external_formdef.data_class().wipe()
|
||||
external_carddef.data_class().wipe()
|
||||
|
||||
carddata = carddef.data_class()()
|
||||
carddata.data = {'0': 'test card'}
|
||||
|
@ -5578,20 +5585,20 @@ def test_inspect_page_with_related_objects(pub):
|
|||
resp = app.get('/backoffice/data/external-action-card/1/inspect')
|
||||
assert 'Related Forms/Cards' in resp.text
|
||||
# related form and card
|
||||
assert '<li><a href="http://example.net/backoffice/management/external-form/2/">External Form #1-2</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/data/external-card/2/">External Card #1-2</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/management/external-form/2/">External Form #1-2 (Evolution)</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/data/external-card/2/">External Card #1-2 (Evolution)</a></li>' in resp.text
|
||||
# check related form
|
||||
resp = app.get('/backoffice/management/external-form/2/')
|
||||
assert '<h3>Original card</h3><p><a href="http://example.net/backoffice/data/external-action-card/1/">External action card #2-1</a></p>' in resp.text
|
||||
resp = app.get('/backoffice/management/external-form/2/inspect')
|
||||
# parent
|
||||
assert '<li><a href="http://example.net/backoffice/data/external-action-card/1/">External action card #2-1</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/data/external-action-card/1/">External action card #2-1 (Parent)</a></li>' in resp.text
|
||||
# check related card
|
||||
resp = app.get('/backoffice/data/external-card/2/')
|
||||
assert '<h3>Original card</h3><p><a href="http://example.net/backoffice/data/external-action-card/1/">External action card #2-1</a></p>' in resp.text
|
||||
resp = app.get('/backoffice/data/external-card/2/inspect')
|
||||
# parent
|
||||
assert '<li><a href="http://example.net/backoffice/data/external-action-card/1/">External action card #2-1</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/data/external-action-card/1/">External action card #2-1 (Parent)</a></li>' in resp.text
|
||||
|
||||
FormDef.wipe()
|
||||
CardDef.wipe()
|
||||
|
@ -5642,7 +5649,19 @@ def test_inspect_page_with_related_objects(pub):
|
|||
resp = app.get('/backoffice/management/form-a/1/inspect')
|
||||
assert 'Related Forms/Cards' in resp.text
|
||||
# related card
|
||||
assert '<li><a href="http://example.net/backoffice/data/card-a/1/">CARD A #1-1</a></li>' in resp.text
|
||||
assert '<li><a href="http://example.net/backoffice/data/card-a/1/">CARD A #1-1 (Data Source - varname "card")</a></li>' in resp.text
|
||||
|
||||
# missing carddata
|
||||
carddef.data_class().wipe()
|
||||
resp = app.get('/backoffice/management/form-a/1/inspect')
|
||||
assert 'Related Forms/Cards' in resp.text
|
||||
assert '<li><a href="">Linked "CARD A" object by id 1 (Data Source - varname "card" - not found)</a></li>' in resp.text
|
||||
|
||||
# missing carddef
|
||||
CardDef.wipe()
|
||||
resp = app.get('/backoffice/management/form-a/1/inspect')
|
||||
assert 'Related Forms/Cards' in resp.text
|
||||
assert '<li><a href="">Linked object def by id card-a (Data Source - varname "card" - not found)</a></li>' in resp.text
|
||||
|
||||
|
||||
def test_workflow_jump_previous(pub):
|
||||
|
|
|
@ -3176,9 +3176,12 @@ class FormBackOfficeStatusPage(FormStatusPage):
|
|||
r += htmltext('<div id="inspect-related" class="section">')
|
||||
r += htmltext('<h2>%s</h2>') % _('Related Forms/Cards')
|
||||
r += htmltext('<ul class="form-inspector biglist">')
|
||||
for child in children:
|
||||
r += htmltext('<li><a href="%s">%s</a></li>') % (
|
||||
child.get_url(backoffice=True), child.get_display_name())
|
||||
for child, origin in children:
|
||||
if isinstance(child, str):
|
||||
r += htmltext('<li><a href="">%s (%s)</a></li>') % (child, origin)
|
||||
else:
|
||||
r += htmltext('<li><a href="%s">%s (%s)</a></li>') % (
|
||||
child.get_url(backoffice=True), child.get_display_name(), origin)
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
|
|
|
@ -1210,7 +1210,7 @@ class FormData(StorableObject):
|
|||
yield parent
|
||||
elif parent:
|
||||
# looking for any parent (inspect page)
|
||||
yield parent
|
||||
yield (parent, _('Parent'))
|
||||
|
||||
data_ids = []
|
||||
# search linked objects in data sources
|
||||
|
@ -1219,13 +1219,18 @@ class FormData(StorableObject):
|
|||
if not linked_id:
|
||||
continue
|
||||
data_source = getattr(field, 'data_source', None)
|
||||
if data_source and object_type:
|
||||
if not data_source:
|
||||
continue
|
||||
origin = _('Data Source')
|
||||
if field.varname:
|
||||
origin = '%s - varname "%s"' % (origin, field.varname)
|
||||
if object_type:
|
||||
# looking for a data_source of a specific type (workflow action)
|
||||
if data_source['type'] == object_type:
|
||||
data_ids.append((data_source['type'], linked_id))
|
||||
elif data_source:
|
||||
data_ids.append((data_source['type'], linked_id, origin))
|
||||
else:
|
||||
# looking for any data_source (inspect page)
|
||||
data_ids.append((data_source['type'], linked_id))
|
||||
data_ids.append((data_source['type'], linked_id, origin))
|
||||
|
||||
# search in evolution
|
||||
for part in self.iter_evolution_parts():
|
||||
|
@ -1235,12 +1240,12 @@ class FormData(StorableObject):
|
|||
if object_type:
|
||||
# looking for an object of a specific type (workflow action)
|
||||
if part_identifier == object_type:
|
||||
data_ids.append((part_identifier, part.formdata_id))
|
||||
data_ids.append((part_identifier, part.formdata_id, _('Evolution')))
|
||||
else:
|
||||
# looking for any object (inspect page)
|
||||
data_ids.append((part_identifier, part.formdata_id))
|
||||
data_ids.append((part_identifier, part.formdata_id, _('Evolution')))
|
||||
|
||||
for (slug, target_id) in data_ids:
|
||||
for (slug, target_id, origin) in data_ids:
|
||||
if object_type:
|
||||
# workflow action
|
||||
try:
|
||||
|
@ -1258,11 +1263,23 @@ class FormData(StorableObject):
|
|||
obj_class = FormDef
|
||||
elif obj_type == 'carddef':
|
||||
obj_class = CardDef
|
||||
yield obj_class.get_by_urlname(slug).data_class().get(target_id)
|
||||
try:
|
||||
_objectdef = obj_class.get_by_urlname(slug)
|
||||
except KeyError:
|
||||
yield (
|
||||
_('Linked object def by id %(object_id)s') % {'object_id': slug},
|
||||
_('%s - not found') % origin
|
||||
)
|
||||
else:
|
||||
yield (_objectdef.data_class().get(target_id), origin)
|
||||
except ValueError:
|
||||
pass
|
||||
except KeyError:
|
||||
pass
|
||||
yield (
|
||||
_('Linked "%(object_name)s" object by id %(object_id)s') % {
|
||||
'object_name': _objectdef.name, 'object_id': target_id},
|
||||
_('%s - not found') % origin
|
||||
)
|
||||
|
||||
def __getattr__(self, attr):
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue