Make the group management more generic in the model

This commit is contained in:
Skia 2015-11-27 16:05:43 +01:00
parent 5c9e5a24ab
commit 0b962e2380
4 changed files with 87 additions and 6 deletions

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0009_auto_20151127_1007'),
]
operations = [
migrations.RemoveField(
model_name='page',
name='edit_group',
),
migrations.RemoveField(
model_name='page',
name='owner_group',
),
migrations.RemoveField(
model_name='page',
name='view_group',
),
]

View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0010_auto_20151127_1503'),
]
operations = [
migrations.AddField(
model_name='page',
name='edit_group',
field=models.ManyToManyField(to='core.Group', related_name='editable_object', null=True),
),
migrations.AddField(
model_name='page',
name='owner_group',
field=models.ForeignKey(related_name='owned_object', default=1, to='core.Group'),
),
migrations.AddField(
model_name='page',
name='view_group',
field=models.ManyToManyField(to='core.Group', related_name='viewable_object', null=True),
),
]

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0011_auto_20151127_1504'),
]
operations = [
migrations.AlterField(
model_name='page',
name='edit_group',
field=models.ManyToManyField(related_name='editable_object', to='core.Group'),
),
migrations.AlterField(
model_name='page',
name='view_group',
field=models.ManyToManyField(related_name='viewable_object', to='core.Group'),
),
]

View File

@ -132,7 +132,14 @@ class Group(AuthGroup):
"""
return reverse('core:group_edit', kwargs={'group_id': self.pk})
class Page(models.Model):
class GroupManagedObject(models.Model):
owner_group = models.ForeignKey(Group, related_name="owned_object", default=1)
edit_group = models.ManyToManyField(Group, related_name="editable_object")
view_group = models.ManyToManyField(Group, related_name="viewable_object")
class Meta:
abstract = True
class Page(GroupManagedObject, models.Model):
"""
The page class to build a Wiki
Each page may have a parent and it's URL is of the form my.site/page/<grd_pa>/<parent>/<mypage>
@ -154,11 +161,6 @@ 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)
# TODO: Rightable abstract class from which every object with right needed will be able to be child of
# Put thoses 3 attributes there
owner_group = models.ForeignKey(Group, related_name="owned_pages", default=1)
edit_group = models.ManyToManyField(Group, related_name="editable_pages", default=1)
view_group = models.ManyToManyField(Group, related_name="viewable_pages", default=1)
class Meta:
unique_together = ('name', 'parent')