Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Fix email_notifications migration in order to properly set content types for form (advanced) #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.apps import apps as django_apps
from django.db import migrations, models
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission
Expand All @@ -10,6 +11,7 @@
MODEL_NAME = 'emailnotificationformplugin'
VERBOSE_MODEL_NAME = 'form (advanced)'
ACTIONS = ('add', 'change', 'delete')
APP_CONFIG_NAME = 'aldryn_forms.contrib.email_notifications'


def get_content_type():
Expand All @@ -20,6 +22,18 @@ def get_content_type():


def forwards(apps, schema_editor):
'''
For this to work we need to have content types synced for email_notifications app. Usually this run AFTER migrations,
so we need to force execution here
'''
try:
from django.contrib.contenttypes.management import update_contenttypes as create_contenttypes # Django <1.11
except ImportError:
from django.contrib.contenttypes.management import create_contenttypes # Django >= 1.11

app_config = list(filter(lambda x: x.name == APP_CONFIG_NAME, django_apps.get_app_configs()))[0]
create_contenttypes(app_config)

content_type = get_content_type()
if content_type:
for action in ACTIONS:
Expand Down Expand Up @@ -49,6 +63,7 @@ def backwards(apps, schema_editor):
class Migration(migrations.Migration):

dependencies = [
('contenttypes', '0001_initial'),
('email_notifications', '0001_initial'),
]

Expand Down