Refactor page view with Django's black magic powered DetailView&co

This commit is contained in:
Skia
2015-11-25 14:45:18 +01:00
parent d72b18c120
commit b237cdbaae
11 changed files with 163 additions and 185 deletions

View File

@ -56,42 +56,3 @@ class UserEditForm(UserChangeForm):
"""We never handle password in this form"""
return
class PagePropForm(forms.ModelForm):
error_css_class = 'error'
required_css_class = 'required'
parent = forms.ModelChoiceField(queryset=Page.objects.all())
def __init__(self, *args, **kwargs):
super(PagePropForm, self).__init__(*args, **kwargs)
self.fields['parent'].required = False
class Meta:
model = Page
fields = ['parent', 'name', 'owner_group', 'edit_group', 'view_group']
def save(self, commit=True):
page = super(PagePropForm, self).save(commit=False)
if commit:
page.save()
return page
class PageEditForm(forms.ModelForm):
error_css_class = 'error'
required_css_class = 'required'
def __init__(self, *args, **kwargs):
super(PageEditForm, self).__init__(*args, **kwargs)
class Meta:
model = Page
fields = ['title', 'content', ]
def save(self, commit=True):
page = super(PageEditForm, self).save(commit=False)
if commit:
page.save()
return page