0007-wcs-fix-custom_title-update-68063.patch
combo/apps/wcs/forms.py | ||
---|---|---|
132 | 132 |
return cleaned_data |
133 | 133 | |
134 | 134 | |
135 |
class WcsCardInfoCellAppearanceBaseForm(forms.ModelForm): |
|
136 |
def save(self, *args, **kwargs): |
|
137 |
super().save(*args, **kwargs) |
|
138 |
if self.instance.title_type != 'manual': |
|
139 |
self.instance.custom_title = '' |
|
140 |
self.instance.save() |
|
141 |
return self.instance |
|
142 | ||
143 | ||
135 | 144 |
class WcsCardInfoCellDisplayForm(forms.ModelForm): |
136 | 145 |
customize_display = forms.BooleanField(label=_('Customize display'), required=False) |
137 | 146 |
combo/apps/wcs/models.py | ||
---|---|---|
1560 | 1560 |
def get_appearance_fields(self): |
1561 | 1561 |
return ['title_type', 'custom_title'] |
1562 | 1562 | |
1563 |
def get_appearance_form_class(self): |
|
1564 |
from .forms import WcsCardInfoCellAppearanceBaseForm |
|
1565 | ||
1566 |
return super().get_appearance_form_class(base_options_form_class=WcsCardInfoCellAppearanceBaseForm) |
|
1567 | ||
1563 | 1568 |
def get_manager_tabs(self): |
1564 | 1569 |
from .forms import WcsCardInfoCellDisplayForm |
1565 | 1570 |
combo/data/models.py | ||
---|---|---|
1187 | 1187 |
def get_appearance_fields(self): |
1188 | 1188 |
return ['title', 'custom_title'] |
1189 | 1189 | |
1190 |
def get_appearance_form_class(self): |
|
1190 |
def get_appearance_form_class(self, base_options_form_class=None):
|
|
1191 | 1191 |
model_fields = {field.name for field in self._meta.local_concrete_fields} |
1192 | 1192 |
fields = [field for field in self.get_appearance_fields() if field in model_fields] + [ |
1193 | 1193 |
'slug', |
... | ... | |
1205 | 1205 |
page = self.page |
1206 | 1206 |
cell = self |
1207 | 1207 | |
1208 |
class OptionsForm(model_forms.ModelForm): |
|
1208 |
class OptionsForm(base_options_form_class or model_forms.ModelForm):
|
|
1209 | 1209 |
def __init__(self, *args, **kwargs): |
1210 | 1210 |
super().__init__(*args, **kwargs) |
1211 | 1211 |
if page.placeholder_options.get(cell.placeholder, {}).get('fx_grid_layout'): |
tests/wcs/test_card.py | ||
---|---|---|
176 | 176 |
resp = resp.forms[0].submit() |
177 | 177 |
assert resp.context['form'].errors == {'card_ids': ['This field is required.']} |
178 | 178 | |
179 |
# check custom_title |
|
180 |
for title_type in ['auto', 'empty']: |
|
181 |
cell.custom_title = 'foo bar' |
|
182 |
cell.save() |
|
183 |
resp = app.get('/manage/pages/%s/' % page.pk) |
|
184 |
resp.forms[0]['c%s-title_type' % cell.get_reference()].value = title_type |
|
185 |
resp = resp.forms[0].submit() |
|
186 |
cell.refresh_from_db() |
|
187 |
assert cell.custom_title == '' |
|
188 | ||
179 | 189 | |
180 | 190 |
def test_card_cell_custom_schema_migration(): |
181 | 191 |
cell = WcsCardInfosCell() |
182 |
- |