Skip to content

Commit 6f94666

Browse files
author
Stefan Reinhard
committed
Populate values for ApplicationContent admin_fields from parameters
1 parent 0f51580 commit 6f94666

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

feincms/content/application/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ def __init__(self, *args, **kwargs):
281281

282282
for k, v in self.custom_fields.items():
283283
self.fields[k] = v
284+
if k in self.instance.parameters:
285+
self.fields[k].initial = self.instance.parameters[k]
284286

285287
def save(self, commit=True, *args, **kwargs):
286288
# Django ModelForms return the model instance from save. We'll

feincms/tests/test_page.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,17 @@ def test_25_applicationcontent(self):
11791179
# Ensure ApplicationContent's admin_fields support works properly
11801180
self.assertContains(self.client.get('/admin/page/page/%d/' % page.id),
11811181
'exclusive_subpages')
1182+
self.assertContains(
1183+
self.client.get('/admin/page/page/%d/' % page.id),
1184+
'custom_field'
1185+
)
1186+
1187+
# Check if admin_fields get populated correctly
1188+
app_ct = page.applicationcontent_set.all()[0]
1189+
app_ct.parameters = '{"custom_field":"val42", "exclusive_subpages": false}'
1190+
app_ct.save()
1191+
r = self.client.get('/admin/page/page/%d/' % page.id)
1192+
self.assertContains(r, 'val42')
11821193

11831194
def test_26_page_form_initial(self):
11841195
self.create_default_page_set()

tests/testapp/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def get_admin_fields(form, *args, **kwargs):
3838
label=capfirst(_('exclusive subpages')),
3939
required=False,
4040
initial=form.instance.parameters.get('exclusive_subpages', False),
41-
help_text=_('Exclude everything other than the application\'s content when rendering subpages.'),
42-
),
41+
help_text=_('Exclude everything other when rendering subpages.'),
42+
),
43+
'custom_field': forms.CharField(),
4344
}
4445

4546
Page.create_content_type(ApplicationContent, APPLICATIONS=(

0 commit comments

Comments
 (0)