From ebba6d3795076c4e06ac6fc66079013cd2bd16dc Mon Sep 17 00:00:00 2001 From: Arvind Tiwari Date: Thu, 12 Apr 2018 08:56:24 +0530 Subject: [PATCH] cms page extension favicon --- datacenterlight/admin.py | 8 ++++- datacenterlight/cms_models.py | 11 ++++++- datacenterlight/cms_toolbar.py | 24 +++++++++++++++ .../migrations/0019_cmsfaviconextension.py | 29 +++++++++++++++++++ .../templates/datacenterlight/cms/base.html | 12 +++++--- 5 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 datacenterlight/cms_toolbar.py create mode 100644 datacenterlight/migrations/0019_cmsfaviconextension.py diff --git a/datacenterlight/admin.py b/datacenterlight/admin.py index acb93fff..b8dc2f32 100644 --- a/datacenterlight/admin.py +++ b/datacenterlight/admin.py @@ -1,10 +1,16 @@ from django.contrib import admin from cms.admin.placeholderadmin import PlaceholderAdminMixin -from .cms_models import CMSIntegration +from cms.extensions import PageExtensionAdmin +from .cms_models import CMSIntegration, CMSFaviconExtension class CMSIntegrationAdmin(PlaceholderAdminMixin, admin.ModelAdmin): list_display = ('name', 'domain') +class CMSFaviconExtensionAdmin(PageExtensionAdmin): + pass + + admin.site.register(CMSIntegration, CMSIntegrationAdmin) +admin.site.register(CMSFaviconExtension, CMSFaviconExtensionAdmin) diff --git a/datacenterlight/cms_models.py b/datacenterlight/cms_models.py index 9eb55e0c..4aec69b1 100644 --- a/datacenterlight/cms_models.py +++ b/datacenterlight/cms_models.py @@ -1,9 +1,12 @@ +from cms.extensions import PageExtension +from cms.extensions.extension_pool import extension_pool from cms.models.fields import PlaceholderField from cms.models.pluginmodel import CMSPlugin from django.contrib.sites.models import Site from django.db import models from django.utils.safestring import mark_safe from djangocms_text_ckeditor.fields import HTMLField +from filer.fields.file import FilerFileField from filer.fields.image import FilerImageField @@ -30,9 +33,15 @@ class CMSIntegration(models.Model): return self.name -# Models for CMS Plugins +class CMSFaviconExtension(PageExtension): + favicon = FilerFileField(related_name="cms_favicon_image") +extension_pool.register(CMSFaviconExtension) + + +# Models for CMS Plugins + class DCLSectionPluginModel(CMSPlugin): heading = models.CharField( blank=True, null=True, max_length=100, diff --git a/datacenterlight/cms_toolbar.py b/datacenterlight/cms_toolbar.py new file mode 100644 index 00000000..15a8cb4b --- /dev/null +++ b/datacenterlight/cms_toolbar.py @@ -0,0 +1,24 @@ +from cms.extensions.toolbar import ExtensionToolbar +from cms.toolbar_pool import toolbar_pool +from django.utils.translation import ugettext_lazy as _ + +from .cms_models import CMSFaviconExtension + + +@toolbar_pool.register +class CMSFaviconExtensionToolbar(ExtensionToolbar): + # defineds the model for the current toolbar + model = CMSFaviconExtension + + 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( + _('CMS Favicon'), url=url, disabled=not self.toolbar.edit_mode + ) diff --git a/datacenterlight/migrations/0019_cmsfaviconextension.py b/datacenterlight/migrations/0019_cmsfaviconextension.py new file mode 100644 index 00000000..7b350a70 --- /dev/null +++ b/datacenterlight/migrations/0019_cmsfaviconextension.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2018-04-12 03:16 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import filer.fields.file + + +class Migration(migrations.Migration): + + dependencies = [ + ('datacenterlight', '0018_auto_20180403_1930'), + ] + + operations = [ + migrations.CreateModel( + name='CMSFaviconExtension', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('extended_object', models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to='cms.Page')), + ('favicon', filer.fields.file.FilerFileField(on_delete=django.db.models.deletion.CASCADE, related_name='cms_favicon_image', to='filer.File')), + ('public_extension', models.OneToOneField(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='draft_extension', to='datacenterlight.CMSFaviconExtension')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/datacenterlight/templates/datacenterlight/cms/base.html b/datacenterlight/templates/datacenterlight/cms/base.html index 0c356735..942a0ad4 100644 --- a/datacenterlight/templates/datacenterlight/cms/base.html +++ b/datacenterlight/templates/datacenterlight/cms/base.html @@ -8,9 +8,9 @@ - + - {% page_attribute page_title %} + {% page_attribute "page_title" %} @@ -30,7 +30,11 @@ - + {% if request.current_page.cmsfaviconextension %} + + {% else %} + + {% endif %} @@ -52,7 +56,7 @@ {% placeholder 'Datacenterlight Header' or %}
-

{% page_attribute page_title %}

+

{% page_attribute "page_title" %}

{% endplaceholder %}