mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-10 08:14:53 +00:00
Created initial data migrations
This commit is contained in:
parent
3c64287488
commit
78643d40cd
5 changed files with 236 additions and 0 deletions
|
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
def create_admin_access_permissions(apps, schema_editor):
|
||||
ContentType = apps.get_model('contenttypes.ContentType')
|
||||
Permission = apps.get_model('auth.Permission')
|
||||
Group = apps.get_model('auth.Group')
|
||||
|
||||
# Add a fake content type to hang the 'can access Wagtail admin' permission off.
|
||||
# The fact that this doesn't correspond to an actual defined model shouldn't matter, I hope...
|
||||
wagtailadmin_content_type = ContentType.objects.create(
|
||||
app_label='wagtailadmin',
|
||||
model='admin',
|
||||
name='Wagtail admin'
|
||||
)
|
||||
|
||||
# Create admin permission
|
||||
admin_permission = Permission.objects.create(
|
||||
content_type=wagtailadmin_content_type,
|
||||
codename='access_admin',
|
||||
name='Can access Wagtail admin'
|
||||
)
|
||||
|
||||
# Assign it to Editors and Moderators groups
|
||||
for group in Group.objects.filter(name__in=['Editors', 'Moderators']):
|
||||
group.permissions.add(admin_permission)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
# Need to run wagtailcores initial data migration to make sure the groups are created
|
||||
('wagtailcore', '0002_initial_data'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_admin_access_permissions),
|
||||
]
|
||||
0
wagtail/wagtailadmin/migrations/__init__.py
Normal file
0
wagtail/wagtailadmin/migrations/__init__.py
Normal file
91
wagtail/wagtailcore/migrations/0002_initial_data.py
Normal file
91
wagtail/wagtailcore/migrations/0002_initial_data.py
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
def initial_data(apps, schema_editor):
|
||||
ContentType = apps.get_model('contenttypes.ContentType')
|
||||
Group = apps.get_model('auth.Group')
|
||||
Page = apps.get_model('wagtailcore.Page')
|
||||
Site = apps.get_model('wagtailcore.Site')
|
||||
GroupPagePermission = apps.get_model('wagtailcore.GroupPagePermission')
|
||||
|
||||
# Create page content type
|
||||
page_content_type, created = ContentType.objects.get_or_create(
|
||||
model='page',
|
||||
app_label='wagtailcore',
|
||||
defaults={'name': 'page'}
|
||||
)
|
||||
|
||||
# Create root page
|
||||
root = Page.objects.create(
|
||||
title="Root",
|
||||
slug='root',
|
||||
content_type=page_content_type,
|
||||
path='0001',
|
||||
depth=1,
|
||||
numchild=1,
|
||||
url_path='/',
|
||||
)
|
||||
|
||||
# Create homepage
|
||||
homepage = Page.objects.create(
|
||||
title="Welcome to your new Wagtail site!",
|
||||
slug='home',
|
||||
content_type=page_content_type,
|
||||
path='00010001',
|
||||
depth=2,
|
||||
numchild=0,
|
||||
url_path='/home/',
|
||||
)
|
||||
|
||||
# Create default site
|
||||
Site.objects.create(
|
||||
hostname='localhost',
|
||||
root_page_id=homepage.id,
|
||||
is_default_site=True
|
||||
)
|
||||
|
||||
# Create auth groups
|
||||
moderators_group = Group.objects.create(name='Moderators')
|
||||
editors_group = Group.objects.create(name='Editors')
|
||||
|
||||
# Create group permissions
|
||||
GroupPagePermission.objects.create(
|
||||
group=moderators_group,
|
||||
page=root,
|
||||
permission_type='add',
|
||||
)
|
||||
GroupPagePermission.objects.create(
|
||||
group=moderators_group,
|
||||
page=root,
|
||||
permission_type='edit',
|
||||
)
|
||||
GroupPagePermission.objects.create(
|
||||
group=moderators_group,
|
||||
page=root,
|
||||
permission_type='publish',
|
||||
)
|
||||
|
||||
GroupPagePermission.objects.create(
|
||||
group=editors_group,
|
||||
page=root,
|
||||
permission_type='add',
|
||||
)
|
||||
GroupPagePermission.objects.create(
|
||||
group=editors_group,
|
||||
page=root,
|
||||
permission_type='edit',
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(initial_data),
|
||||
]
|
||||
52
wagtail/wagtaildocs/migrations/0002_initial_data.py
Normal file
52
wagtail/wagtaildocs/migrations/0002_initial_data.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
def add_document_permissions_to_admin_groups(apps, schema_editor):
|
||||
ContentType = apps.get_model('contenttypes.ContentType')
|
||||
Permission = apps.get_model('auth.Permission')
|
||||
Group = apps.get_model('auth.Group')
|
||||
Document = apps.get_model('wagtaildocs.Document')
|
||||
|
||||
# Get document permissions
|
||||
document_content_type, _created = ContentType.objects.get_or_create(
|
||||
model='document',
|
||||
app_label='wagtaildocs',
|
||||
defaults={'name': 'document'}
|
||||
)
|
||||
|
||||
add_document_permission, _created = Permission.objects.get_or_create(
|
||||
content_type=document_content_type,
|
||||
codename='add_document',
|
||||
defaults={'name': 'Can add document'}
|
||||
)
|
||||
change_document_permission, _created = Permission.objects.get_or_create(
|
||||
content_type=document_content_type,
|
||||
codename='change_document',
|
||||
defaults={'name': 'Can change document'}
|
||||
)
|
||||
delete_document_permission, _created = Permission.objects.get_or_create(
|
||||
content_type=document_content_type,
|
||||
codename='delete_document',
|
||||
defaults={'name': 'Can delete document'}
|
||||
)
|
||||
|
||||
# Assign it to Editors and Moderators groups
|
||||
for group in Group.objects.filter(name__in=['Editors', 'Moderators']):
|
||||
group.permissions.add(add_document_permission, change_document_permission, delete_document_permission)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtaildocs', '0001_initial'),
|
||||
|
||||
# Need to run wagtailcores initial data migration to make sure the groups are created
|
||||
('wagtailcore', '0002_initial_data'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(add_document_permissions_to_admin_groups),
|
||||
]
|
||||
52
wagtail/wagtailimages/migrations/0002_initial_data.py
Normal file
52
wagtail/wagtailimages/migrations/0002_initial_data.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
def add_image_permissions_to_admin_groups(apps, schema_editor):
|
||||
ContentType = apps.get_model('contenttypes.ContentType')
|
||||
Permission = apps.get_model('auth.Permission')
|
||||
Group = apps.get_model('auth.Group')
|
||||
Image = apps.get_model('wagtailimages.Image')
|
||||
|
||||
# Get image permissions
|
||||
image_content_type, _created = ContentType.objects.get_or_create(
|
||||
model='image',
|
||||
app_label='wagtailimages',
|
||||
defaults={'name': 'image'}
|
||||
)
|
||||
|
||||
add_image_permission, _created = Permission.objects.get_or_create(
|
||||
content_type=image_content_type,
|
||||
codename='add_image',
|
||||
defaults={'name': 'Can add image'}
|
||||
)
|
||||
change_image_permission, _created = Permission.objects.get_or_create(
|
||||
content_type=image_content_type,
|
||||
codename='change_image',
|
||||
defaults={'name': 'Can change image'}
|
||||
)
|
||||
delete_image_permission, _created = Permission.objects.get_or_create(
|
||||
content_type=image_content_type,
|
||||
codename='delete_image',
|
||||
defaults={'name': 'Can delete image'}
|
||||
)
|
||||
|
||||
# Assign it to Editors and Moderators groups
|
||||
for group in Group.objects.filter(name__in=['Editors', 'Moderators']):
|
||||
group.permissions.add(add_image_permission, change_image_permission, delete_image_permission)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailimages', '0001_initial'),
|
||||
|
||||
# Need to run wagtailcores initial data migration to make sure the groups are created
|
||||
('wagtailcore', '0002_initial_data'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(add_image_permissions_to_admin_groups),
|
||||
]
|
||||
Loading…
Reference in a new issue