1
Fork 0

Create social media settings model

This commit is contained in:
Jake Howard 2016-12-28 21:38:31 +00:00
parent f0142fe42c
commit b6b012ca10
8 changed files with 59 additions and 11 deletions

View file

@ -1,4 +1,5 @@
from django.conf import settings
from .models import SocialMediaSettings
SETTINGS_KEYS = [
@ -13,8 +14,11 @@ SETTINGS_KEYS = [
]
def settings_injector(request=None):
injected_settings = {}
def settings_injector(request):
django_settings = {}
for setting in SETTINGS_KEYS:
injected_settings[setting] = getattr(settings, setting)
return {'django_settings': injected_settings}
django_settings[setting] = getattr(settings, setting)
django_settings.update({
'social': SocialMediaSettings.for_site(request.site)
})
return {'settings': django_settings}

View 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,
},
),
]

View file

View file

@ -4,6 +4,7 @@ from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin
from bs4 import BeautifulSoup
from wagtail.contrib.settings.models import BaseSetting, register_setting
class Entity(MetadataPageMixin, Page):
@ -37,3 +38,13 @@ class Entity(MetadataPageMixin, Page):
class Meta:
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')

View file

@ -62,8 +62,8 @@ class ContextInjectorTestCase(BaseTestCase):
def test_has_keys(self):
response = self.client.get('/')
for key in SETTINGS_KEYS:
self.assertIn(key, response.context['django_settings'])
self.assertEqual(response.context['django_settings'][key], getattr(settings, key))
self.assertIn(key, response.context['settings'])
self.assertEqual(response.context['settings'][key], getattr(settings, key))
class DjangoAdminDisabledTestCase(BaseTestCase):

View file

@ -100,7 +100,6 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'wagtail.contrib.settings.context_processors.settings',
'project.common.context.settings_injector'
],
},

View file

@ -1,15 +1,15 @@
{% load static wagtailuserbar wagtailmetadata_tags %}
<!DOCTYPE html>
<html lang="{{ django_settings.LANGUAGE_CODE }}">
<html lang="{{ settings.LANGUAGE_CODE }}">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<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>
<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="application-name" content="{{ django_settings.WAGTAIL_SITE_NAME }}" />
<meta name="application-name" content="{{ settings.WAGTAIL_SITE_NAME }}" />
{% meta_tags %}

View file

@ -8,7 +8,7 @@
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
{{ django_settings.WAGTAIL_SITE_NAME }}
{{ settings.WAGTAIL_SITE_NAME }}
</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">