admin: ellipsize long form name in test pages breadcrumb (#87110) #1182
|
@ -95,6 +95,25 @@ def test_tests_page(pub):
|
|||
app.get('/backoffice/forms/1/tests/results/run').follow()
|
||||
|
||||
|
||||
def test_tests_page_breadcrumb(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'Short title'
|
||||
formdef.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
|
||||
resp = app.get(formdef.get_admin_url() + 'tests/')
|
||||
assert 'Short title' in resp.text
|
||||
|
||||
formdef.name = 'This is a long title'
|
||||
formdef.store()
|
||||
|
||||
resp = app.get(formdef.get_admin_url() + 'tests/')
|
||||
assert 'This is a long…' in resp.text
|
||||
|
||||
|
||||
def test_tests_page_creation_from_formdata(pub):
|
||||
user = create_superuser(pub)
|
||||
|
||||
|
|
|
@ -301,6 +301,10 @@ class TestsDirectory(Directory):
|
|||
self.results = TestResultsDirectory(objectdef)
|
||||
|
||||
def _q_traverse(self, path):
|
||||
last_page_path, last_page_label = get_response().breadcrumb.pop()
|
||||
last_page_label = misc.ellipsize(last_page_label, 15, '…')
|
||||
get_response().breadcrumb.append((last_page_path, last_page_label))
|
||||
|
||||
get_response().breadcrumb.append(('tests/', _('Tests')))
|
||||
return super()._q_traverse(path)
|
||||
|
||||
|
|
|
@ -275,11 +275,11 @@ def site_encode(s):
|
|||
return force_str(s)
|
||||
|
||||
|
||||
def ellipsize(s, length=30):
|
||||
def ellipsize(s, length=30, truncate='(…)'):
|
||||
s = force_str(s)
|
||||
if s and len(s) > length:
|
||||
if length > 3:
|
||||
s = Truncator(s).chars(length, truncate='(…)')
|
||||
s = Truncator(s).chars(length, truncate=truncate)
|
||||
else:
|
||||
s = s[:length]
|
||||
return force_str(s)
|
||||
|
|
Loading…
Reference in New Issue