wcs: adjust labels of cards to display selection (#68517)

This commit is contained in:
Frédéric Péters 2022-08-29 15:11:51 +02:00
parent 48aeff3105
commit 2d0508e8b9
2 changed files with 40 additions and 38 deletions

View File

@ -78,15 +78,17 @@ class WcsCardCellForm(forms.ModelForm):
with_sub_slug = any(p.sub_slug for p in self.instance.page.get_parents_and_self())
if with_sub_slug:
self.fields['related_card_path'].choices += [
('--', _('Identifier from page URL')),
('--', _('According to page URL')),
]
self.fields['related_card_path'].initial = '--'
if not self.instance.card_ids and not self.instance.related_card_path:
self.initial['related_card_path'] = '--'
self.fields['related_card_path'].choices += [
('__all__', _('All cards')),
('', _('Other Card Identifiers')),
('', _('Others:')),
] + self.instance.get_related_card_paths()
self.fields['card_ids'].label = ''
self.fields['card_ids'].help_text = _('Card identifiers, separated by commas.')
def save(self, *args, **kwargs):
super().save(*args, **kwargs)

View File

@ -394,9 +394,9 @@ def test_manager_card_cell(mock_send, app, admin_user):
resp = app.get('/manage/pages/%s/' % page.pk)
# but only one cell on the page, no relations to follow
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
]
# all cards
@ -404,9 +404,9 @@ def test_manager_card_cell(mock_send, app, admin_user):
cell.save()
resp = app.get('/manage/pages/%s/' % page.pk)
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', False, 'Identifier from page URL'),
('--', False, 'According to page URL'),
('__all__', True, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
]
# 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)
# still no relation to follow
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
]
# no cell with id and slug
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
]
# set a slug on first cell
@ -435,15 +435,15 @@ def test_manager_card_cell(mock_send, app, admin_user):
resp = app.get('/manage/pages/%s/' % page.pk)
# still no relation to follow
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
]
# multiple relations to follow
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('sluga/cardb', False, 'sluga/cardb'),
('sluga/cardsb', False, 'sluga/cardsb'),
('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
@ -458,15 +458,15 @@ def test_manager_card_cell(mock_send, app, admin_user):
resp = app.get('/manage/pages/%s/' % page.pk)
# still no relation to follow
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', False, 'Identifier from page URL'),
('--', False, 'According to page URL'),
('__all__', False, 'All cards'),
('', True, 'Other Card Identifiers'),
('', True, 'Others:'),
]
# can not user cell with multiple ids as reference
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
]
# define a slug on second cell
@ -477,18 +477,18 @@ def test_manager_card_cell(mock_send, app, admin_user):
resp = app.get('/manage/pages/%s/' % page.pk)
# multiple relations to follow
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('slugb/reverse:cardb', False, 'slugb/cardb (reverse)'),
('slugb/reverse:cardsb', False, 'slugb/cardsb (reverse)'),
('slugb/reverse:blockb_cardb', False, 'slugb/blockb_cardb (reverse)'),
]
# still multiple relations to follow
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('sluga/cardb', False, 'sluga/cardb'),
('sluga/cardsb', False, 'sluga/cardsb'),
('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
@ -507,15 +507,15 @@ def test_manager_card_cell(mock_send, app, admin_user):
resp = app.get('/manage/pages/%s/' % page.pk)
# no more relation to follow
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
]
# still multiple relations to follow
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
('--', False, 'Identifier from page URL'),
('--', False, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('sluga/cardb', True, 'sluga/cardb'),
('sluga/cardsb', False, 'sluga/cardsb'),
('sluga/blockb_cardb', False, 'sluga/blockb_cardb'),
@ -538,16 +538,16 @@ def test_manager_card_cell(mock_send, app, admin_user):
cell2.save()
resp = app.get('/manage/pages/%s/' % page.pk)
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('slugd/cardd-foo/carde-foo', False, 'slugd/cardd-foo/carde-foo'),
('slugd/carde-foo', False, 'slugd/carde-foo'),
]
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('sluge/cardd-bar', False, 'sluge/cardd-bar'),
('sluge/reverse:carde-foo', False, 'sluge/carde-foo (reverse)'),
]
@ -561,18 +561,18 @@ def test_manager_card_cell(mock_send, app, admin_user):
cell2.save()
resp = app.get('/manage/pages/%s/' % page.pk)
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('slugd-bis/cardd-foo', False, 'slugd-bis/cardd-foo'),
('slugd-bis/reverse:cardd-foo', False, 'slugd-bis/cardd-foo (reverse)'),
('slugd-bis/carde-foo/cardd-bar', False, 'slugd-bis/carde-foo/cardd-bar'),
('slugd-bis/carde-foo/reverse:carde-foo', False, 'slugd-bis/carde-foo/carde-foo (reverse)'),
]
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('slugd/cardd-foo', False, 'slugd/cardd-foo'),
('slugd/reverse:cardd-foo', False, 'slugd/cardd-foo (reverse)'),
('slugd/carde-foo/cardd-bar', False, 'slugd/carde-foo/cardd-bar'),
@ -588,15 +588,15 @@ def test_manager_card_cell(mock_send, app, admin_user):
cell2.save()
resp = app.get('/manage/pages/%s/' % page.pk)
assert resp.forms[0]['c%s-related_card_path' % cell.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('sluge-bis/cardd-bar/carde-foo', False, 'sluge-bis/cardd-bar/carde-foo'),
]
assert resp.forms[1]['c%s-related_card_path' % cell2.get_reference()].options == [
('--', True, 'Identifier from page URL'),
('--', True, 'According to page URL'),
('__all__', False, 'All cards'),
('', False, 'Other Card Identifiers'),
('', False, 'Others:'),
('sluge/cardd-bar/carde-foo', False, 'sluge/cardd-bar/carde-foo'),
]