Merge pull request #618 from tiwariav/task/4297/cms_favicon

Task/4297 dcl cms favicon as page attribute
This commit is contained in:
Arvind Tiwari 2018-04-20 20:59:17 +05:30 committed by GitHub
commit d21e2a8abe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 6 deletions

View file

@ -1,6 +1,7 @@
from django.contrib import admin from django.contrib import admin
from cms.admin.placeholderadmin import PlaceholderAdminMixin from cms.admin.placeholderadmin import PlaceholderAdminMixin
from .cms_models import CMSIntegration from cms.extensions import PageExtensionAdmin
from .cms_models import CMSIntegration, CMSFaviconExtension
from .models import VMPricing from .models import VMPricing
@ -8,5 +9,10 @@ class CMSIntegrationAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
list_display = ('name', 'domain') list_display = ('name', 'domain')
class CMSFaviconExtensionAdmin(PageExtensionAdmin):
pass
admin.site.register(CMSIntegration, CMSIntegrationAdmin) admin.site.register(CMSIntegration, CMSIntegrationAdmin)
admin.site.register(CMSFaviconExtension, CMSFaviconExtensionAdmin)
admin.site.register(VMPricing) admin.site.register(VMPricing)

View file

@ -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.fields import PlaceholderField
from cms.models.pluginmodel import CMSPlugin from cms.models.pluginmodel import CMSPlugin
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.db import models from django.db import models
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from djangocms_text_ckeditor.fields import HTMLField from djangocms_text_ckeditor.fields import HTMLField
from filer.fields.file import FilerFileField
from filer.fields.image import FilerImageField from filer.fields.image import FilerImageField
from datacenterlight.models import VMPricing from datacenterlight.models import VMPricing
@ -32,9 +35,15 @@ class CMSIntegration(models.Model):
return self.name 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): class DCLSectionPluginModel(CMSPlugin):
heading = models.CharField( heading = models.CharField(
blank=True, null=True, max_length=100, blank=True, null=True, max_length=100,

View file

@ -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
)

View file

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

View file

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2018-04-20 15:04
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('datacenterlight', '0019_auto_20180415_2236'),
('datacenterlight', '0019_cmsfaviconextension'),
]
operations = [
]

View file

@ -8,9 +8,9 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Data Center Light by ungleich"> <meta name="description" content="{% page_attribute 'meta_description' %}">
<meta name="author" content="ungleich glarus ag"> <meta name="author" content="ungleich glarus ag">
<title>{% page_attribute page_title %}</title> <title>{% page_attribute "page_title" %}</title>
<!-- Vendor CSS --> <!-- Vendor CSS -->
<!-- Bootstrap Core CSS --> <!-- Bootstrap Core CSS -->
@ -30,7 +30,11 @@
<!-- External Fonts --> <!-- External Fonts -->
<link href="//fonts.googleapis.com/css?family=Lato:300,400,600,700" rel="stylesheet" type="text/css"> <link href="//fonts.googleapis.com/css?family=Lato:300,400,600,700" rel="stylesheet" type="text/css">
{% if request.current_page.cmsfaviconextension %}
<link rel="shortcut icon" href="{% static request.current_page.cmsfaviconextension.favicon.url %}" type="image/x-icon">
{% else %}
<link rel="shortcut icon" href="{% static 'datacenterlight/img/favicon.ico' %}" type="image/x-icon"> <link rel="shortcut icon" href="{% static 'datacenterlight/img/favicon.ico' %}" type="image/x-icon">
{% endif %}
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
@ -52,7 +56,7 @@
{% placeholder 'Datacenterlight Header' or %} {% placeholder 'Datacenterlight Header' or %}
<div class="dcl-header"> <div class="dcl-header">
<div class="container"> <div class="container">
<h1>{% page_attribute page_title %}</h1> <h1>{% page_attribute "page_title" %}</h1>
</div> </div>
</div> </div>
{% endplaceholder %} {% endplaceholder %}