From bad0870035aebdea6d1166b56944bf5589c120ba Mon Sep 17 00:00:00 2001 From: rscnt Date: Sat, 23 May 2015 00:33:35 -0600 Subject: [PATCH] Added ungleich app to extend Page models. Ungleich app has a model called UngleichPage, this model has an attribute called image_header which will be used to set the background image for the page header. Signed-off-by: rscnt --- dynamicweb/settings.py | 66 ++++++++++++++++++++++++++--- dynamicweb/urls.py | 15 +++++-- ungleich/__init__.py | 0 ungleich/admin.py | 12 ++++++ ungleich/cms_toolbar.py | 25 +++++++++++ ungleich/migrations/0001_initial.py | 27 ++++++++++++ ungleich/migrations/__init__.py | 0 ungleich/models.py | 12 ++++++ ungleich/tests.py | 3 ++ ungleich/views.py | 3 ++ 10 files changed, 152 insertions(+), 11 deletions(-) create mode 100644 ungleich/__init__.py create mode 100644 ungleich/admin.py create mode 100644 ungleich/cms_toolbar.py create mode 100644 ungleich/migrations/0001_initial.py create mode 100644 ungleich/migrations/__init__.py create mode 100644 ungleich/models.py create mode 100644 ungleich/tests.py create mode 100644 ungleich/views.py diff --git a/dynamicweb/settings.py b/dynamicweb/settings.py index 375dab94..2cece707 100644 --- a/dynamicweb/settings.py +++ b/dynamicweb/settings.py @@ -7,7 +7,7 @@ Copyright 2015 Ungleich. import os import logging import django.db.backends.postgresql_psycopg2 - +from django.utils.translation import ugettext_lazy as _ gettext = lambda s: s BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -81,6 +81,8 @@ INSTALLED_APPS = ( 'djangocms_blog', 'bootstrap3', 'compressor', + # ungleich + 'ungleich', ) MIDDLEWARE_CLASSES = ( @@ -159,12 +161,6 @@ DATABASES = { # Internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/ -LANGUAGES = ( - ('en', 'English'), -) - -LANGUAGE_CODE = 'en' - TIME_ZONE = 'UTC' USE_I18N = True @@ -173,6 +169,62 @@ USE_L10N = True USE_TZ = True +LANGUAGES = ( + ('en-us', _('US English')), +) + +LANGUAGE_CODE = 'en-us' + +CMS_PLACEHOLDER_CONF = { + 'logo_image': { + 'name': 'Logo Image', + 'plugins': ['FilerImagePlugin'], + 'limits': { + 'global': 1, + } + }, + 'page-title': { + 'name': 'Page Title', + 'plugins': ['TextPlugin'], + 'default_plugins': [ + { + 'plugin_type': 'TextPlugin', + 'values': { + 'body': 'Page Title...' + } + } + ], + 'limits': { + 'global': 1, + } + }, + 'page-subtitle': { + 'name': 'Page Subtitle', + 'inherit': 'page-title', + 'default_plugins': [ + { + 'plugin_type': 'TextPlugin', + 'values': { + 'body': 'Page subtitle...' + } + } + ], + }, + 'footer_copyright': { + 'name': 'Copyright', + 'inherit': 'page-title', + 'default_plugins': [ + { + 'plugin_type': 'TextPlugin', + 'values': { + 'body': 'Copyright...' + } + } + ], + } +} + + try: from dynamicweb.local.local_settings import * except ImportError: diff --git a/dynamicweb/urls.py b/dynamicweb/urls.py index da84ab4e..4a8bdc86 100644 --- a/dynamicweb/urls.py +++ b/dynamicweb/urls.py @@ -1,14 +1,21 @@ -from django.conf.urls import include, url +from django.conf.urls import patterns, include, url from django.contrib import admin # deprecated in version 1.8 from django.conf.urls.i18n import i18n_patterns from django.conf.urls.static import static from dynamicweb import settings -urlpatterns = i18n_patterns('', +urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^digital.glarus/', include('digital_glarus.urls', - namespace="digital_glarus")), + namespace="digital_glarus")), url(r'^', include('cms.urls')), url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')), -) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +if settings.DEBUG: + urlpatterns += patterns('', + url(r'^media/(?P.*)$', 'django.views.static.serve', { + 'document_root': settings.MEDIA_ROOT, + }), + ) diff --git a/ungleich/__init__.py b/ungleich/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ungleich/admin.py b/ungleich/admin.py new file mode 100644 index 00000000..98dce73d --- /dev/null +++ b/ungleich/admin.py @@ -0,0 +1,12 @@ +from django.contrib import admin +from cms.extensions import PageExtensionAdmin + +# Register your models here. + +from .models import UngleichPage + + +class UngleichPageAdmin(PageExtensionAdmin): + pass + +admin.site.register(UngleichPage, UngleichPageAdmin) diff --git a/ungleich/cms_toolbar.py b/ungleich/cms_toolbar.py new file mode 100644 index 00000000..4986368f --- /dev/null +++ b/ungleich/cms_toolbar.py @@ -0,0 +1,25 @@ +from cms.extensions.toolbar import ExtensionToolbar +from django.utils.translation import ugettext_lazy as _ + +from cms.toolbar_pool import toolbar_pool +from cms.toolbar_base import CMSToolbar + +from .models import UngleichPage + + +@toolbar_pool.register +class UngleichPageToolbar(ExtensionToolbar): + # defineds the model for the current toolbar + model = UngleichPage + + def populate(self): + # setup the extension toolbar with permissions and sanity checks + current_page_menu = self._setup_extension_toolbar() + # if it's all ok + if current_page_menu: + # retrieves the instance of the current extension (if any) and the toolbar item url + page_extension, url = self.get_page_extension_admin() + if url: + # adds a toolbar item + current_page_menu.add_modal_item(_('Page Header'), url=url, + disabled=not self.toolbar.edit_mode) diff --git a/ungleich/migrations/0001_initial.py b/ungleich/migrations/0001_initial.py new file mode 100644 index 00000000..1672c3cc --- /dev/null +++ b/ungleich/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('cms', '0011_auto_20150419_1006'), + ] + + operations = [ + migrations.CreateModel( + name='UngleichPage', + fields=[ + ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')), + ('image_header', models.ImageField(upload_to='image_header')), + ('extended_object', models.OneToOneField(editable=False, to='cms.Page')), + ('public_extension', models.OneToOneField(editable=False, related_name='draft_extension', null=True, to='ungleich.UngleichPage')), + ], + options={ + 'abstract': False, + }, + bases=(models.Model,), + ), + ] diff --git a/ungleich/migrations/__init__.py b/ungleich/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ungleich/models.py b/ungleich/models.py new file mode 100644 index 00000000..07b7e479 --- /dev/null +++ b/ungleich/models.py @@ -0,0 +1,12 @@ +from django.db import models + +from cms.extensions import PageExtension +from cms.extensions.extension_pool import extension_pool + + +# Create your models here. + +class UngleichPage(PageExtension): + image_header = models.ImageField(upload_to='image_header') + +extension_pool.register(UngleichPage) diff --git a/ungleich/tests.py b/ungleich/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/ungleich/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/ungleich/views.py b/ungleich/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/ungleich/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.