diff --git a/cms/forms.py b/cms/forms.py index eb3403a..09168d0 100644 --- a/cms/forms.py +++ b/cms/forms.py @@ -2,6 +2,7 @@ import swapper from django import forms from django.contrib.contenttypes.models import ContentType from django.core.mail import EmailMessage +from django.forms import inlineformset_factory from django.utils.translation import gettext_lazy as _ Page = swapper.load_model('cms', 'Page') @@ -42,8 +43,13 @@ class SectionForm(forms.ModelForm): # Repopulate the 'choices' attribute of the type field from # the child model. self.fields['type'].choices = self._meta.model.TYPES + self.fields['type'].initial = self._meta.model.TYPES[0][0] - def save(self): + def delete(self): + instance = super().save() + instance.delete() + + def save(self, commit=True): section = super().save() # Explanation: get the content type of the model that the user @@ -56,7 +62,8 @@ class SectionForm(forms.ModelForm): model=section.type.lower(), ) - section.save() + if commit: + section.save() return section class Meta: @@ -69,3 +76,5 @@ class SectionForm(forms.ModelForm): # There is definitely a bug in Django, since the above 'field_classes' gets # ignored entirely. Workaround to force a ChoiceField anyway: type = forms.ChoiceField() + +SectionFormSet = inlineformset_factory(Page, Section, form=SectionForm, extra=1) diff --git a/cms/static/cms/cms.scss b/cms/static/cms/cms.scss index 195acb5..ca55dfe 100644 --- a/cms/static/cms/cms.scss +++ b/cms/static/cms/cms.scss @@ -289,12 +289,12 @@ form.cms { clear: both; box-sizing: border-box; - type, number { + &.type, &.number { width: 75%; clear: none; float: left; } - number { + &.number { width: 20%; float: right; } diff --git a/cms/static/cms/cms.scss.css b/cms/static/cms/cms.scss.css index a4e7b3f..1bafd6b 100644 --- a/cms/static/cms/cms.scss.css +++ b/cms/static/cms/cms.scss.css @@ -206,11 +206,11 @@ form.cms div.formfield { padding: 10px 0; clear: both; box-sizing: border-box; } - form.cms div.formfield#type, form.cms div.formfield#number { + form.cms div.formfield.type, form.cms div.formfield.number { width: 75%; clear: none; float: left; } - form.cms div.formfield#number { + form.cms div.formfield.number { width: 20%; float: right; } diff --git a/cms/templates/cms/confirm.html b/cms/templates/cms/confirm.html new file mode 100644 index 0000000..b1e0e0c --- /dev/null +++ b/cms/templates/cms/confirm.html @@ -0,0 +1,39 @@ +{% extends 'base.html' %} +{% load i18n %} + +{% block content %} +
+{% endblock %} diff --git a/cms/templates/cms/edit.html b/cms/templates/cms/edit.html index 2cd8337..4411dfd 100644 --- a/cms/templates/cms/edit.html +++ b/cms/templates/cms/edit.html @@ -5,6 +5,9 @@ {% endblock %} @@ -61,7 +67,6 @@ {% endblock %} diff --git a/cms/templates/cms/formfield.html b/cms/templates/cms/formfield.html index a0f7965..bfbcb5e 100644 --- a/cms/templates/cms/formfield.html +++ b/cms/templates/cms/formfield.html @@ -1,4 +1,4 @@ -