wcs: fix custom_title update (#68063)

This commit is contained in:
Lauréline Guérin 2022-08-11 21:28:06 +02:00
parent 7716113a51
commit 5a1f1a9a51
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
4 changed files with 26 additions and 2 deletions

View File

@ -132,6 +132,15 @@ class WcsCardInfoCellForm(forms.ModelForm):
return cleaned_data
class WcsCardInfoCellAppearanceBaseForm(forms.ModelForm):
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
if self.instance.title_type != 'manual':
self.instance.custom_title = ''
self.instance.save()
return self.instance
class WcsCardInfoCellDisplayForm(forms.ModelForm):
customize_display = forms.BooleanField(label=_('Customize display'), required=False)

View File

@ -1565,6 +1565,11 @@ class WcsCardInfosCell(CardMixin, CellBase):
def get_appearance_fields(self):
return ['title_type', 'custom_title']
def get_appearance_form_class(self):
from .forms import WcsCardInfoCellAppearanceBaseForm
return super().get_appearance_form_class(base_options_form_class=WcsCardInfoCellAppearanceBaseForm)
def get_manager_tabs(self):
from .forms import WcsCardInfoCellDisplayForm

View File

@ -1187,7 +1187,7 @@ class CellBase(models.Model, metaclass=CellMeta):
def get_appearance_fields(self):
return ['title', 'custom_title']
def get_appearance_form_class(self):
def get_appearance_form_class(self, base_options_form_class=None):
model_fields = {field.name for field in self._meta.local_concrete_fields}
fields = [field for field in self.get_appearance_fields() if field in model_fields] + [
'slug',
@ -1205,7 +1205,7 @@ class CellBase(models.Model, metaclass=CellMeta):
page = self.page
cell = self
class OptionsForm(model_forms.ModelForm):
class OptionsForm(base_options_form_class or model_forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if page.placeholder_options.get(cell.placeholder, {}).get('fx_grid_layout'):

View File

@ -176,6 +176,16 @@ def test_card_cell_setup(mock_send, app, admin_user):
resp = resp.forms[0].submit()
assert resp.context['form'].errors == {'card_ids': ['This field is required.']}
# check custom_title
for title_type in ['auto', 'empty']:
cell.custom_title = 'foo bar'
cell.save()
resp = app.get('/manage/pages/%s/' % page.pk)
resp.forms[0]['c%s-title_type' % cell.get_reference()].value = title_type
resp = resp.forms[0].submit()
cell.refresh_from_db()
assert cell.custom_title == ''
def test_card_cell_custom_schema_migration():
cell = WcsCardInfosCell()