Create social media settings model
This commit is contained in:
parent
f0142fe42c
commit
b6b012ca10
8 changed files with 59 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from .models import SocialMediaSettings
|
||||||
|
|
||||||
|
|
||||||
SETTINGS_KEYS = [
|
SETTINGS_KEYS = [
|
||||||
|
@ -13,8 +14,11 @@ SETTINGS_KEYS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def settings_injector(request=None):
|
def settings_injector(request):
|
||||||
injected_settings = {}
|
django_settings = {}
|
||||||
for setting in SETTINGS_KEYS:
|
for setting in SETTINGS_KEYS:
|
||||||
injected_settings[setting] = getattr(settings, setting)
|
django_settings[setting] = getattr(settings, setting)
|
||||||
return {'django_settings': injected_settings}
|
django_settings.update({
|
||||||
|
'social': SocialMediaSettings.for_site(request.site)
|
||||||
|
})
|
||||||
|
return {'settings': django_settings}
|
||||||
|
|
34
project/common/migrations/0001_initial.py
Normal file
34
project/common/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.4 on 2016-12-28 21:21
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('wagtailcore', '0032_add_bulk_delete_page_permission'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='SocialMediaSettings',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('flickr', models.URLField(help_text='Flickr Profile URL')),
|
||||||
|
('freenode', models.CharField(help_text='Freenode Username', max_length=15)),
|
||||||
|
('github', models.URLField(help_text='GitHub Profile URL')),
|
||||||
|
('reddit', models.URLField(help_text='Reddit Profile URL')),
|
||||||
|
('twitter', models.CharField(help_text='Twitter Username', max_length=15)),
|
||||||
|
('youtube', models.URLField(help_text='Youtube Channel URL')),
|
||||||
|
('site', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to='wagtailcore.Site')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
0
project/common/migrations/__init__.py
Normal file
0
project/common/migrations/__init__.py
Normal file
|
@ -4,6 +4,7 @@ from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel
|
||||||
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
|
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
|
||||||
from wagtailmetadata.models import MetadataPageMixin
|
from wagtailmetadata.models import MetadataPageMixin
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from wagtail.contrib.settings.models import BaseSetting, register_setting
|
||||||
|
|
||||||
|
|
||||||
class Entity(MetadataPageMixin, Page):
|
class Entity(MetadataPageMixin, Page):
|
||||||
|
@ -37,3 +38,13 @@ class Entity(MetadataPageMixin, Page):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
@register_setting
|
||||||
|
class SocialMediaSettings(BaseSetting):
|
||||||
|
flickr = models.URLField(help_text="Flickr Profile URL")
|
||||||
|
freenode = models.CharField(help_text="Freenode Username", max_length=15)
|
||||||
|
github = models.URLField(help_text="GitHub Profile URL")
|
||||||
|
reddit = models.URLField(help_text="Reddit Profile URL")
|
||||||
|
twitter = models.CharField(help_text='Twitter Username', max_length=15)
|
||||||
|
youtube = models.URLField(help_text='Youtube Channel URL')
|
||||||
|
|
|
@ -62,8 +62,8 @@ class ContextInjectorTestCase(BaseTestCase):
|
||||||
def test_has_keys(self):
|
def test_has_keys(self):
|
||||||
response = self.client.get('/')
|
response = self.client.get('/')
|
||||||
for key in SETTINGS_KEYS:
|
for key in SETTINGS_KEYS:
|
||||||
self.assertIn(key, response.context['django_settings'])
|
self.assertIn(key, response.context['settings'])
|
||||||
self.assertEqual(response.context['django_settings'][key], getattr(settings, key))
|
self.assertEqual(response.context['settings'][key], getattr(settings, key))
|
||||||
|
|
||||||
|
|
||||||
class DjangoAdminDisabledTestCase(BaseTestCase):
|
class DjangoAdminDisabledTestCase(BaseTestCase):
|
||||||
|
|
|
@ -100,7 +100,6 @@ TEMPLATES = [
|
||||||
'django.template.context_processors.request',
|
'django.template.context_processors.request',
|
||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'django.contrib.messages.context_processors.messages',
|
||||||
'wagtail.contrib.settings.context_processors.settings',
|
|
||||||
'project.common.context.settings_injector'
|
'project.common.context.settings_injector'
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
{% load static wagtailuserbar wagtailmetadata_tags %}
|
{% load static wagtailuserbar wagtailmetadata_tags %}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="{{ django_settings.LANGUAGE_CODE }}">
|
<html lang="{{ settings.LANGUAGE_CODE }}">
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<title>{% block htmltitle %}{% if self.seo_title %}{{ self.seo_title }}{% else %}{{ self.title }}{% endif %}{% endblock %}</title>
|
<title>{% block htmltitle %}{% if self.seo_title %}{{ self.seo_title }}{% else %}{{ self.title }}{% endif %}{% endblock %}</title>
|
||||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
|
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
|
||||||
<meta http-equiv="Content-Language" content="{{ django_settings.LANGUAGE_CODE }}" />
|
<meta http-equiv="Content-Language" content="{{ settings.LANGUAGE_CODE }}" />
|
||||||
<meta name="superfish" content="nofish" />
|
<meta name="superfish" content="nofish" />
|
||||||
<meta name="application-name" content="{{ django_settings.WAGTAIL_SITE_NAME }}" />
|
<meta name="application-name" content="{{ settings.WAGTAIL_SITE_NAME }}" />
|
||||||
|
|
||||||
{% meta_tags %}
|
{% meta_tags %}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
</button>
|
</button>
|
||||||
<a class="navbar-brand" href="#">
|
<a class="navbar-brand" href="#">
|
||||||
{{ django_settings.WAGTAIL_SITE_NAME }}
|
{{ settings.WAGTAIL_SITE_NAME }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||||
|
|
Reference in a new issue