wcs: adjust labels in card ids selection for card cell (#68531)
This commit is contained in:
parent
6df8c9512a
commit
3e53c6a1f0
|
@ -74,19 +74,20 @@ class WcsCardCellForm(forms.ModelForm):
|
||||||
card_models = get_wcs_options('/api/cards/@list', include_custom_views=True)
|
card_models = get_wcs_options('/api/cards/@list', include_custom_views=True)
|
||||||
self.fields['carddef_reference'].widget = forms.Select(choices=card_models)
|
self.fields['carddef_reference'].widget = forms.Select(choices=card_models)
|
||||||
|
|
||||||
self.fields['related_card_path'].choices = []
|
self.fields['related_card_path'].choices = [
|
||||||
|
('__all__', _('All cards')),
|
||||||
|
]
|
||||||
with_sub_slug = any(p.sub_slug for p in self.instance.page.get_parents_and_self())
|
with_sub_slug = any(p.sub_slug for p in self.instance.page.get_parents_and_self())
|
||||||
if with_sub_slug:
|
if with_sub_slug:
|
||||||
self.fields['related_card_path'].choices += [
|
self.fields['related_card_path'].choices += [
|
||||||
('--', _('According to page URL')),
|
('--', _('Card whose identifier is in the URL')),
|
||||||
]
|
]
|
||||||
self.fields['related_card_path'].initial = '--'
|
self.fields['related_card_path'].initial = '--'
|
||||||
if not self.instance.card_ids and not self.instance.related_card_path:
|
if not self.instance.card_ids and not self.instance.related_card_path:
|
||||||
self.initial['related_card_path'] = '--'
|
self.initial['related_card_path'] = '--'
|
||||||
self.fields['related_card_path'].choices += [
|
self.fields['related_card_path'].choices += self.instance.get_related_card_paths() + [
|
||||||
('__all__', _('All cards')),
|
('', _('Template')),
|
||||||
('', _('Others:')),
|
]
|
||||||
] + self.instance.get_related_card_paths()
|
|
||||||
self.fields['card_ids'].label = ''
|
self.fields['card_ids'].label = ''
|
||||||
self.fields['card_ids'].help_text = _('Card identifiers, separated by commas.')
|
self.fields['card_ids'].help_text = _('Card identifiers, separated by commas.')
|
||||||
|
|
||||||
|
|
|
@ -1086,11 +1086,12 @@ class WcsCardCell(CardMixin, CellBase):
|
||||||
'reverse:' if relation['reverse'] else '',
|
'reverse:' if relation['reverse'] else '',
|
||||||
relation['varname'],
|
relation['varname'],
|
||||||
)
|
)
|
||||||
new_label = '%s/%s%s' % (
|
_new_label = '%s/%s%s' % (
|
||||||
label,
|
label,
|
||||||
relation['varname'],
|
relation['varname'],
|
||||||
' (reverse)' if relation['reverse'] else '',
|
' (reverse)' if relation['reverse'] else '',
|
||||||
)
|
)
|
||||||
|
new_label = _('Linked card: %s') % _new_label
|
||||||
if relation['obj'] == 'carddef:%s' % self.card_slug:
|
if relation['obj'] == 'carddef:%s' % self.card_slug:
|
||||||
# target carddef found
|
# target carddef found
|
||||||
yield (new_path, new_label)
|
yield (new_path, new_label)
|
||||||
|
@ -1103,7 +1104,7 @@ class WcsCardCell(CardMixin, CellBase):
|
||||||
yield from iter_relations(
|
yield from iter_relations(
|
||||||
relations=new_card_schema.get('relations') or [],
|
relations=new_card_schema.get('relations') or [],
|
||||||
path=new_path,
|
path=new_path,
|
||||||
label=new_label,
|
label=_new_label,
|
||||||
carddefs_already_seen=carddefs_already_seen,
|
carddefs_already_seen=carddefs_already_seen,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -394,9 +394,9 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
# but only one cell on the page, no relations to follow
|
# but only one cell on the page, no relations to follow
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# all cards
|
# all cards
|
||||||
|
@ -404,9 +404,9 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
cell.save()
|
cell.save()
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', False, 'According to page URL'),
|
|
||||||
('__all__', True, 'All cards'),
|
('__all__', True, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', False, 'Card whose identifier is in the URL'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# add a second cell, related to the first card model
|
# add a second cell, related to the first card model
|
||||||
|
@ -418,15 +418,15 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
# still no relation to follow
|
# still no relation to follow
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
# no cell with id and slug
|
# no cell with id and slug
|
||||||
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# set a slug on first cell
|
# set a slug on first cell
|
||||||
|
@ -435,21 +435,21 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
# still no relation to follow
|
# still no relation to follow
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
# multiple relations to follow
|
# multiple relations to follow
|
||||||
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
('sluga/cardb', False, 'sluga/cardb'),
|
('sluga/cardb', False, 'Linked card: sluga/cardb'),
|
||||||
('sluga/cardsb', False, 'sluga/cardsb'),
|
('sluga/cardsb', False, 'Linked card: sluga/cardsb'),
|
||||||
('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
|
('sluga/blockb_cardb', False, 'Linked card: sluga/blockb_cardb'),
|
||||||
('sluga/cardc/cardb', False, 'sluga/cardc/cardb'),
|
('sluga/cardc/cardb', False, 'Linked card: sluga/cardc/cardb'),
|
||||||
('sluga/cardc/cardsb', False, 'sluga/cardc/cardsb'),
|
('sluga/cardc/cardsb', False, 'Linked card: sluga/cardc/cardsb'),
|
||||||
('sluga/cardc/blockb_cardb', False, 'sluga/cardc/blockb_cardb'),
|
('sluga/cardc/blockb_cardb', False, 'Linked card: sluga/cardc/blockb_cardb'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# set a list of ids on first cell
|
# set a list of ids on first cell
|
||||||
|
@ -458,15 +458,15 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
# still no relation to follow
|
# still no relation to follow
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', False, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', True, 'Others:'),
|
('--', False, 'Card whose identifier is in the URL'),
|
||||||
|
('', True, 'Template'),
|
||||||
]
|
]
|
||||||
# can not user cell with multiple ids as reference
|
# can not user cell with multiple ids as reference
|
||||||
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# define a slug on second cell
|
# define a slug on second cell
|
||||||
|
@ -477,24 +477,24 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
# multiple relations to follow
|
# multiple relations to follow
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
('slugb/reverse:cardb', False, 'slugb/cardb (reverse)'),
|
('slugb/reverse:cardb', False, 'Linked card: slugb/cardb (reverse)'),
|
||||||
('slugb/reverse:cardsb', False, 'slugb/cardsb (reverse)'),
|
('slugb/reverse:cardsb', False, 'Linked card: slugb/cardsb (reverse)'),
|
||||||
('slugb/reverse:blockb_cardb', False, 'slugb/blockb_cardb (reverse)'),
|
('slugb/reverse:blockb_cardb', False, 'Linked card: slugb/blockb_cardb (reverse)'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
# still multiple relations to follow
|
# still multiple relations to follow
|
||||||
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
('sluga/cardb', False, 'sluga/cardb'),
|
('sluga/cardb', False, 'Linked card: sluga/cardb'),
|
||||||
('sluga/cardsb', False, 'sluga/cardsb'),
|
('sluga/cardsb', False, 'Linked card: sluga/cardsb'),
|
||||||
('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
|
('sluga/blockb_cardb', False, 'Linked card: sluga/blockb_cardb'),
|
||||||
('sluga/cardc/cardb', False, 'sluga/cardc/cardb'),
|
('sluga/cardc/cardb', False, 'Linked card: sluga/cardc/cardb'),
|
||||||
('sluga/cardc/cardsb', False, 'sluga/cardc/cardsb'),
|
('sluga/cardc/cardsb', False, 'Linked card: sluga/cardc/cardsb'),
|
||||||
('sluga/cardc/blockb_cardb', False, 'sluga/cardc/blockb_cardb'),
|
('sluga/cardc/blockb_cardb', False, 'Linked card: sluga/cardc/blockb_cardb'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# set a related_path on cell2
|
# set a related_path on cell2
|
||||||
|
@ -507,21 +507,21 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
# no more relation to follow
|
# no more relation to follow
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
# still multiple relations to follow
|
# still multiple relations to follow
|
||||||
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
||||||
('--', False, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', False, 'Card whose identifier is in the URL'),
|
||||||
('sluga/cardb', True, 'sluga/cardb'),
|
('sluga/cardb', True, 'Linked card: sluga/cardb'),
|
||||||
('sluga/cardsb', False, 'sluga/cardsb'),
|
('sluga/cardsb', False, 'Linked card: sluga/cardsb'),
|
||||||
('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
|
('sluga/blockb_cardb', False, 'Linked card: sluga/blockb_cardb'),
|
||||||
('sluga/cardc/cardb', False, 'sluga/cardc/cardb'),
|
('sluga/cardc/cardb', False, 'Linked card: sluga/cardc/cardb'),
|
||||||
('sluga/cardc/cardsb', False, 'sluga/cardc/cardsb'),
|
('sluga/cardc/cardsb', False, 'Linked card: sluga/cardc/cardsb'),
|
||||||
('sluga/cardc/blockb_cardb', False, 'sluga/cardc/blockb_cardb'),
|
('sluga/cardc/blockb_cardb', False, 'Linked card: sluga/cardc/blockb_cardb'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
resp.forms[1].submit()
|
resp.forms[1].submit()
|
||||||
cell2.refresh_from_db()
|
cell2.refresh_from_db()
|
||||||
|
@ -538,18 +538,18 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
cell2.save()
|
cell2.save()
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
('slugd/cardd-foo/carde-foo', False, 'slugd/cardd-foo/carde-foo'),
|
('slugd/cardd-foo/carde-foo', False, 'Linked card: slugd/cardd-foo/carde-foo'),
|
||||||
('slugd/carde-foo', False, 'slugd/carde-foo'),
|
('slugd/carde-foo', False, 'Linked card: slugd/carde-foo'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
('sluge/cardd-bar', False, 'sluge/cardd-bar'),
|
('sluge/cardd-bar', False, 'Linked card: sluge/cardd-bar'),
|
||||||
('sluge/reverse:carde-foo', False, 'sluge/carde-foo (reverse)'),
|
('sluge/reverse:carde-foo', False, 'Linked card: sluge/carde-foo (reverse)'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
cell.slug = 'slugd'
|
cell.slug = 'slugd'
|
||||||
|
@ -561,22 +561,26 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
cell2.save()
|
cell2.save()
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
('slugd-bis/cardd-foo', False, 'slugd-bis/cardd-foo'),
|
('slugd-bis/cardd-foo', False, 'Linked card: slugd-bis/cardd-foo'),
|
||||||
('slugd-bis/reverse:cardd-foo', False, 'slugd-bis/cardd-foo (reverse)'),
|
('slugd-bis/reverse:cardd-foo', False, 'Linked card: slugd-bis/cardd-foo (reverse)'),
|
||||||
('slugd-bis/carde-foo/cardd-bar', False, 'slugd-bis/carde-foo/cardd-bar'),
|
('slugd-bis/carde-foo/cardd-bar', False, 'Linked card: slugd-bis/carde-foo/cardd-bar'),
|
||||||
('slugd-bis/carde-foo/reverse:carde-foo', False, 'slugd-bis/carde-foo/carde-foo (reverse)'),
|
(
|
||||||
|
'slugd-bis/carde-foo/reverse:carde-foo',
|
||||||
|
False,
|
||||||
|
'Linked card: slugd-bis/carde-foo/carde-foo (reverse)',
|
||||||
|
),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
('slugd/cardd-foo', False, 'slugd/cardd-foo'),
|
('slugd/cardd-foo', False, 'Linked card: slugd/cardd-foo'),
|
||||||
('slugd/reverse:cardd-foo', False, 'slugd/cardd-foo (reverse)'),
|
('slugd/reverse:cardd-foo', False, 'Linked card: slugd/cardd-foo (reverse)'),
|
||||||
('slugd/carde-foo/cardd-bar', False, 'slugd/carde-foo/cardd-bar'),
|
('slugd/carde-foo/cardd-bar', False, 'Linked card: slugd/carde-foo/cardd-bar'),
|
||||||
('slugd/carde-foo/reverse:carde-foo', False, 'slugd/carde-foo/carde-foo (reverse)'),
|
('slugd/carde-foo/reverse:carde-foo', False, 'Linked card: slugd/carde-foo/carde-foo (reverse)'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
cell.slug = 'sluge'
|
cell.slug = 'sluge'
|
||||||
|
@ -588,16 +592,16 @@ def test_manager_card_cell(mock_send, app, admin_user):
|
||||||
cell2.save()
|
cell2.save()
|
||||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||||
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
('sluge-bis/cardd-bar/carde-foo', False, 'sluge-bis/cardd-bar/carde-foo'),
|
('sluge-bis/cardd-bar/carde-foo', False, 'Linked card: sluge-bis/cardd-bar/carde-foo'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
|
||||||
('--', True, 'According to page URL'),
|
|
||||||
('__all__', False, 'All cards'),
|
('__all__', False, 'All cards'),
|
||||||
('', False, 'Others:'),
|
('--', True, 'Card whose identifier is in the URL'),
|
||||||
('sluge/cardd-bar/carde-foo', False, 'sluge/cardd-bar/carde-foo'),
|
('sluge/cardd-bar/carde-foo', False, 'Linked card: sluge/cardd-bar/carde-foo'),
|
||||||
|
('', False, 'Template'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue