Completed
Push — master ( 8738db...eecf08 )
by Paolo
06:03
created

image.site-migrations.0003_auto_20191003_1007   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 45
dl 0
loc 86
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A reverse_func() 0 14 1
A forwards_func() 0 16 1
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.11.24 on 2019-10-03 08:07
3
from __future__ import unicode_literals
4
5
from django.db import migrations
6
7
8
cookie_policy_link = "/image/privacy/"
9
10
11
# This is the old banner content
12
OLD_BANNER = {
13
        "message": (
14
            "This website uses cookies to ensure you get the best "
15
            "experience on our website."),
16
        "button_text": "Got it!",
17
        "cookie_policy_link": cookie_policy_link,
18
        "cookie_policy_link_text": "Learn more",
19
        "banner_colour": "#2FA4E7",
20
        "banner_text_colour": "#ffffff",
21
        "button_colour": "#73A839",
22
        "button_text_colour": "#ffffff"
23
    }
24
25
26
# this will be NEW the banner content
27
BANNER = {
28
        "message": (
29
            "This website requires cookies, and the limited processing of "
30
            "your personal data in order to function. By using the site you "
31
            "are agreeing to this as outlined in our"),
32
        "button_text": "I agree, dismiss this banner",
33
        "cookie_policy_link": cookie_policy_link,
34
        "cookie_policy_link_text": "Data Privacy Notice",
35
        "banner_colour": "#2FA4E7",
36
        "banner_text_colour": "#ffffff",
37
        "button_colour": "#73A839",
38
        "button_text_colour": "#ffffff"
39
    }
40
41
42
def forwards_func(apps, schema_editor):
43
    # We get the model from the versioned app registry;
44
    # if we directly import it, it'll be the wrong version
45
46
    CookieConsentSettings = apps.get_model(
47
        "django_simple_cookie_consent",
48
        "CookieConsentSettings")
49
50
    db_alias = schema_editor.connection.alias
51
52
    # delete the old banner
53
    CookieConsentSettings.objects.using(db_alias).filter(**OLD_BANNER).delete()
54
55
    # create the new banner
56
    CookieConsentSettings.objects.using(db_alias).bulk_create([
57
        CookieConsentSettings(**BANNER),
58
    ])
59
60
61
def reverse_func(apps, schema_editor):
62
63
    CookieConsentSettings = apps.get_model(
64
        "django_simple_cookie_consent",
65
        "CookieConsentSettings")
66
67
    db_alias = schema_editor.connection.alias
68
69
    # delete the new banner
70
    CookieConsentSettings.objects.using(db_alias).filter(**BANNER).delete()
71
72
    # restore the old banner
73
    CookieConsentSettings.objects.using(db_alias).bulk_create([
74
        CookieConsentSettings(**OLD_BANNER),
75
    ])
76
77
78
class Migration(migrations.Migration):
79
80
    dependencies = [
81
        ('django_simple_cookie_consent', '0002_auto_20190416_1252'),
82
    ]
83
84
    operations = [
85
        migrations.RunPython(forwards_func, reverse_func),
86
    ]
87