diff --git a/core/forms.py b/core/forms.py index 0d1ca5b7..08d59629 100644 --- a/core/forms.py +++ b/core/forms.py @@ -1,4 +1,4 @@ -from django.contrib.auth.forms import UserCreationForm, AuthenticationForm +from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, UserChangeForm from django import forms from django.contrib.auth import logout, login, authenticate import logging @@ -42,21 +42,47 @@ class LoginForm(AuthenticationForm): params={'username': self.username_field.verbose_name}, ) -class PageForm(forms.ModelForm): +class EditUserForm(UserChangeForm): + error_css_class = 'error' + required_css_class = 'required' + class Meta: + model = User + fields = ('first_name', 'last_name', 'email', 'date_of_birth', 'groups', 'user_permissions') + + +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(PageForm, self).__init__(*args, **kwargs) + super(PagePropForm, self).__init__(*args, **kwargs) self.fields['parent'].required = False class Meta: model = Page - fields = ['parent', 'name', 'title', 'content', ] + fields = ['parent', 'name', 'owner_group', 'edit_group', 'view_group'] def save(self, commit=True): - page = super(PageForm, self).save(commit=False) + 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 diff --git a/core/migrations/0003_auto_20151124_1021.py b/core/migrations/0003_auto_20151124_1021.py new file mode 100644 index 00000000..c840a05a --- /dev/null +++ b/core/migrations/0003_auto_20151124_1021.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0002_page_full_name'), + ] + + operations = [ + migrations.AlterModelOptions( + name='page', + options={'permissions': ()}, + ), + ] diff --git a/core/migrations/0004_auto_20151124_1033.py b/core/migrations/0004_auto_20151124_1033.py new file mode 100644 index 00000000..ea360dba --- /dev/null +++ b/core/migrations/0004_auto_20151124_1033.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0006_require_contenttypes_0002'), + ('core', '0003_auto_20151124_1021'), + ] + + operations = [ + migrations.AddField( + model_name='page', + name='edit_group', + field=models.ForeignKey(null=True, to='auth.Group', related_name='editable_pages'), + ), + migrations.AddField( + model_name='page', + name='owner_group', + field=models.ForeignKey(null=True, to='auth.Group', related_name='owned_pages'), + ), + migrations.AddField( + model_name='page', + name='view_group', + field=models.ForeignKey(null=True, to='auth.Group', related_name='viewable_pages'), + ), + ] diff --git a/core/migrations/0005_auto_20151124_1219.py b/core/migrations/0005_auto_20151124_1219.py new file mode 100644 index 00000000..248ff8b0 --- /dev/null +++ b/core/migrations/0005_auto_20151124_1219.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0004_auto_20151124_1033'), + ] + + operations = [ + migrations.AlterField( + model_name='page', + name='edit_group', + field=models.ForeignKey(related_name='editable_pages', to='auth.Group', default=1), + ), + migrations.AlterField( + model_name='page', + name='owner_group', + field=models.ForeignKey(related_name='owned_pages', to='auth.Group', default=1), + ), + migrations.AlterField( + model_name='page', + name='view_group', + field=models.ForeignKey(related_name='viewable_pages', to='auth.Group', default=1), + ), + ] diff --git a/core/models.py b/core/models.py index 1cb113c4..975121db 100644 --- a/core/models.py +++ b/core/models.py @@ -1,5 +1,5 @@ from django.db import models -from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager +from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, UserManager, Group from django.utils.translation import ugettext_lazy as _ from django.utils import timezone from django.core import validators @@ -130,11 +130,15 @@ class Page(models.Model): # playing with a Page object, use get_full_name() instead! full_name = models.CharField(_('page name'), max_length=255, blank=True) + owner_group = models.ForeignKey(Group, related_name="owned_pages", default=1) + edit_group = models.ForeignKey(Group, related_name="editable_pages", default=1) + view_group = models.ForeignKey(Group, related_name="viewable_pages", default=1) + class Meta: unique_together = ('name', 'parent') permissions = ( - ("can_edit", "Can edit the page"), - ("can_view", "Can view the page"), + #("can_edit", "Can edit the page"), + #("can_view", "Can view the page"), ) @staticmethod diff --git a/core/templates/core/edit_user.html b/core/templates/core/edit_user.html index 99790740..16845557 100644 --- a/core/templates/core/edit_user.html +++ b/core/templates/core/edit_user.html @@ -11,5 +11,10 @@ Edit {{ profile.get_display_name }}
You're editing the profile of {{ profile.get_display_name }}
+ {% endif %} {% endblock %} diff --git a/core/templates/core/page.html b/core/templates/core/page.html index 6068061e..b0f9d413 100644 --- a/core/templates/core/page.html +++ b/core/templates/core/page.html @@ -16,6 +16,7 @@ {% if user.is_superuser %} + {% endif %}You're seeing the page {{ page.get_display_name }}