backoffice: fix fields page when a field label is None (#51728)

This commit is contained in:
Lauréline Guérin 2021-03-11 09:23:23 +01:00
parent 4c6ec73981
commit c72cc12a6e
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 15 additions and 2 deletions

View File

@ -1169,6 +1169,19 @@ def test_form_new_field(pub):
assert '<h3 data-field-id="1">baz</h3>' in resp.text
def test_form_field_without_label(pub):
create_superuser(pub)
FormDef.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = [fields.CommentField(id='1', label=None, type='comment')]
formdef.store()
app = login(get_app(pub))
app.get('/backoffice/forms/1/fields/', status=200) # ok, no error
def test_form_delete_field(pub):
create_superuser(pub)
create_role()

View File

@ -282,7 +282,7 @@ def test_comment():
form = Form(use_tokens=False)
field.add_to_form(form)
assert re.match( # regex to handle different beautifulsoup behaviours
'<div class="comment-field\s?">\n<p>Foo</p>\n<p>Bar</p>\n<p>Baz</p>\n</div>',
r'<div class="comment-field\s?">\n<p>Foo</p>\n<p>Bar</p>\n<p>Baz</p>\n</div>',
str(BeautifulSoup(str(form.render())).find('div')),
)

View File

@ -253,7 +253,7 @@ class Field(object):
@property
def unhtmled_label(self):
return force_str(html.unescape(force_text(re.sub('<.*?>', ' ', self.label))).strip())
return force_str(html.unescape(force_text(re.sub('<.*?>', ' ', self.label or ''))).strip())
def get_admin_attributes(self):
return ['label', 'type', 'condition']