src/hdalab/migrations/0003_default_site.py
author ymh <ymh.work@gmail.com>
Fri, 19 Jul 2024 09:38:03 +0200
changeset 704 b5835dca2624
parent 686 385e3a12ee27
permissions -rw-r--r--
Adapt renkan preview to uses chrome headless/puppeteer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
686
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
from __future__ import unicode_literals
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import re
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
from django.conf import settings
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
from django.db import models, migrations
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
def set_site_name(apps, schema_editor):
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    Sites = apps.get_model('sites', 'site')
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    site = Sites.objects.filter(id=1).first()
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    if site == None:
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
        site = Sites()
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    m = re.match(r"^https?\:\/\/(.+)", settings.WEB_URL)
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    if m:
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
        site.name = "HDALab"
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
        site.domain = m.group(1)
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
        site.save()
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
class Migration(migrations.Migration):
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    dependencies = [
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
        ('sites', '0001_initial'),
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
        ('hdalab', '0002_alter_tagyears_tag_one2one'),
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    ]
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    operations = [
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
        migrations.RunPython(set_site_name),
385e3a12ee27 Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    ]