Skip to content
Snippets Groups Projects
Commit 8aaf6a24 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Adding Django sites app

Activate Django sites app and create a migration which adds the
LIGO.ORG domain name of the GraceDB instance as a Site. This will
be used to build absolute URIs without needed a request object.
parent aad39aca
No related branches found
No related tags found
No related merge requests found
......@@ -279,13 +279,16 @@ MIDDLEWARE = [
# Path to root URLconf
ROOT_URLCONF = '{module}.urls'.format(module=os.path.basename(CONFIG_ROOT))
# Database ID of the current site (for sites framework)
SITE_ID=1
# List of string designating all applications which are enabled.
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
# 'django.contrib.sites',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.messages',
'maintenance_mode',
......@@ -348,10 +351,12 @@ STATICFILES_DIRS = [
BOWER_DIR,
]
# Added in order to perform data migrations on the auth and guardian apps
# Added in order to perform data migrations on Django apps
# and other third-party apps
MIGRATION_MODULES = {
'auth': 'migrations.auth',
'guardian': 'migrations.guardian',
'sites': 'migrations.sites',
}
# Forces test database to be created with syncdb rather than via
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-06-04 16:04
from __future__ import unicode_literals
import django.contrib.sites.models
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Site',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('domain', models.CharField(max_length=100, unique=True, validators=[django.contrib.sites.models._simple_domain_name_validator], verbose_name='domain name')),
('name', models.CharField(max_length=50, verbose_name='display name')),
],
options={
'ordering': ('domain',),
'db_table': 'django_site',
'verbose_name': 'site',
'verbose_name_plural': 'sites',
},
managers=[
('objects', django.contrib.sites.models.SiteManager()),
],
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-06-04 16:05
from __future__ import unicode_literals
from django.db import migrations
from django.conf import settings
import socket
SITES = {
'old': {
'domain': 'example.com',
'name': 'example.com',
},
'new': {
'domain': socket.gethostname() + '.ligo.org',
'name': 'ligo.org',
},
}
def update_site(apps, schema_editor):
Site = apps.get_model('sites', 'Site')
# Get current site matching SITE_ID, should be example.com at this point
site1 = Site.objects.get(id=settings.SITE_ID)
# Update with new site name and domain
site1.name = SITES['new']['name']
site1.domain = SITES['new']['domain']
site1.save()
def revert_site(apps, schema_editor):
Site = apps.get_model('sites', 'Site')
# Get current site matching SITE_ID should be ligo.org
site1 = Site.objects.get(id=settings.SITE_ID)
# Revert to original site
site1.name = SITES['old']['name']
site1.domain = SITES['old']['domain']
site1.save()
class Migration(migrations.Migration):
dependencies = [
('sites', '0001_initial'),
]
operations = [
migrations.RunPython(update_site, revert_site),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment