diff --git a/project/common/context.py b/project/common/context.py index 1182890..4c0ce42 100644 --- a/project/common/context.py +++ b/project/common/context.py @@ -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} diff --git a/project/common/migrations/0001_initial.py b/project/common/migrations/0001_initial.py new file mode 100644 index 0000000..f2fcfe0 --- /dev/null +++ b/project/common/migrations/0001_initial.py @@ -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, + }, + ), + ] diff --git a/project/common/migrations/__init__.py b/project/common/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/common/models.py b/project/common/models.py index bdf14d0..d981feb 100644 --- a/project/common/models.py +++ b/project/common/models.py @@ -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') diff --git a/project/common/tests.py b/project/common/tests.py index 1106e48..205bd18 100644 --- a/project/common/tests.py +++ b/project/common/tests.py @@ -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): diff --git a/project/settings.py b/project/settings.py index ba5c76d..15fc6a3 100755 --- a/project/settings.py +++ b/project/settings.py @@ -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' ], }, diff --git a/templates/base.html b/templates/base.html index e994c77..82544fc 100755 --- a/templates/base.html +++ b/templates/base.html @@ -1,15 +1,15 @@ {% load static wagtailuserbar wagtailmetadata_tags %} - +