dynamicweb/datacenterlight/cms_models.py

273 lines
8.4 KiB
Python
Raw Permalink Normal View History

2018-02-27 22:39:19 +00:00
from cms.models.pluginmodel import CMSPlugin
from django.db import models
from django.utils.safestring import mark_safe
2018-03-22 23:06:40 +00:00
from djangocms_text_ckeditor.fields import HTMLField
2018-02-27 22:39:19 +00:00
from filer.fields.image import FilerImageField
2018-03-27 13:49:26 +00:00
from cms.models.fields import PlaceholderField
class CMSIntegration(models.Model):
name = models.CharField(
max_length=100, unique=True, default='default',
2018-03-27 15:34:44 +00:00
help_text=(
'A unique name for the Integration. This name will be used to '
'fetch the Integration into pages'
)
2018-03-27 13:49:26 +00:00
)
footer_placeholder = PlaceholderField(
'datacenterlight_footer', related_name='dcl-footer-placeholder+'
)
navbar_placeholder = PlaceholderField(
'datacenterlight_navbar', related_name='dcl-navbar-placeholder+'
)
2018-03-27 13:49:26 +00:00
2018-03-27 15:34:44 +00:00
def __str__(self):
return self.name
2018-02-27 22:39:19 +00:00
# Models for CMS Plugins
class DCLSectionPluginModel(CMSPlugin):
heading = models.CharField(
blank=True, null=True, max_length=100,
help_text='An optional heading for the Section',
)
content = HTMLField()
TEXT_DIRECTIONS = (
('left', 'Left'),
('right', 'Right')
)
text_direction = models.CharField(
choices=TEXT_DIRECTIONS, max_length=10, default=True,
help_text='The alignment of text in the section'
)
2018-03-01 20:35:42 +00:00
html_id = models.SlugField(
blank=True, null=True,
help_text=(
'An optional html id for the Section. Required to set as target '
'of a link on page'
)
)
plain_heading = models.BooleanField(
default=False,
help_text='Select to keep the heading style simpler.'
)
center_on_mobile = models.BooleanField(
default=False,
help_text='Select to center align content on small screens.'
)
background_gradient = models.BooleanField(
default=False,
help_text='Select to add a gradient background to the section.'
)
def get_extra_classes(self):
extra_classes = self.text_direction
if self.center_on_mobile:
extra_classes += ' section-sm-center'
if self.background_gradient:
extra_classes += ' section-gradient'
if self.plain_heading:
extra_classes += ' split-section-plain'
2018-03-01 20:35:42 +00:00
return extra_classes
def __str__(self):
return '#' + self.html_id if self.html_id else str(self.pk)
class DCLBannerListPluginModel(CMSPlugin):
heading = models.CharField(
blank=True, null=True, max_length=100,
help_text='An optional heading for the Section',
)
html_id = models.SlugField(
blank=True, null=True,
help_text=(
'An optional html id for the Section. Required to set as target '
'of a link on page'
)
)
def __str__(self):
return '#' + self.html_id if self.html_id else str(self.pk)
class DCLBannerItemPluginModel(CMSPlugin):
content = HTMLField()
banner_text = HTMLField(
blank=True, null=True, max_length=100,
help_text='Optional text to be shown as banner in other half.',
)
banner_image = FilerImageField(
on_delete=models.CASCADE, null=True, blank=True,
help_text='Optional image to be used in the banner in other half.'
)
TEXT_DIRECTIONS = (
('left', 'Left'),
('right', 'Right')
)
text_direction = models.CharField(
choices=TEXT_DIRECTIONS, max_length=10, default=True,
help_text='The alignment of text in the section'
)
def get_extra_classes(self):
extra_classes = ''
if self.text_direction == 'left':
extra_classes = 'flex-row-rev'
return extra_classes
2018-02-27 22:39:19 +00:00
class DCLLinkPluginModel(CMSPlugin):
target = models.CharField(
max_length=100,
help_text='Url or #id to navigate to'
)
text = models.CharField(
max_length=50,
help_text='Text for the menu item'
)
title = models.CharField(
blank=True, null=True, max_length=100,
help_text=(
'Optional title text, that will be shown when a user '
'hovers over the link'
)
)
separator = models.BooleanField(
default=False,
help_text='Select to include a separator after the previous link'
)
2018-03-16 09:59:24 +00:00
class DCLNavbarPluginModel(CMSPlugin):
logo_light = FilerImageField(
on_delete=models.CASCADE, null=True, blank=True,
2018-03-17 07:21:44 +00:00
help_text='Logo to be used on transparent navbar',
related_name="dcl_navbar_logo_light",
2018-03-16 09:59:24 +00:00
)
logo_dark = FilerImageField(
on_delete=models.CASCADE, null=True, blank=True,
2018-03-17 07:21:44 +00:00
help_text='Logo to be used on white navbar',
related_name="dcl_navbar_logo_dark",
2018-03-16 09:59:24 +00:00
)
logo_url = models.URLField(max_length=300, null=True, blank=True)
language_dropdown = models.BooleanField(
default=True,
help_text='Select to include the language selection dropdown.'
)
2018-03-16 09:59:24 +00:00
def get_logo_dark(self):
2018-03-16 18:12:40 +00:00
# used only if atleast one logo exists
2018-03-17 07:41:42 +00:00
return self.logo_dark.url if self.logo_dark else self.logo_light.url
2018-03-16 09:59:24 +00:00
def get_logo_light(self):
2018-03-16 18:12:40 +00:00
# used only if atleast one logo exists
return self.logo_light.url if self.logo_light else self.logo_dark.url
2018-03-16 09:59:24 +00:00
2018-02-27 22:39:19 +00:00
class DCLNavbarDropdownPluginModel(CMSPlugin):
2018-02-28 20:08:56 +00:00
target = models.CharField(
2018-03-05 14:30:31 +00:00
max_length=100, null=True, blank=True,
2018-02-27 22:39:19 +00:00
help_text='Optional Url or #id to navigate on click'
)
text = models.CharField(
max_length=50,
help_text='Text for the dropdown toggle'
)
class DCLContactPluginModel(CMSPlugin):
heading = models.CharField(max_length=100, default="Contact", blank=True)
organization_name = models.CharField(
max_length=100, default="ungleich glarus ag", blank=True
2018-02-27 22:39:19 +00:00
)
email = models.EmailField(max_length=200, default="info@ungleich.ch")
address = models.CharField(
max_length=100, default="In der Au 7, Schwanden 8762", blank=True
)
country = models.CharField(
max_length=100, default="Switzerland", blank=True
)
form_header = models.CharField(
max_length=100, default="Send us a message.", blank=True
)
class DCLFooterPluginModel(CMSPlugin):
copyright_label = models.CharField(
max_length=100, default='ungleich glarus ag', blank=True,
2018-02-27 22:39:19 +00:00
help_text='Name of the company alongside the copyright year'
)
class DCLSectionIconPluginModel(CMSPlugin):
fontawesome_icon_name = models.CharField(
max_length=30,
help_text=mark_safe(
'Name of the fontawesome icon to use. '
2018-02-28 18:52:51 +00:00
'<a href="https://fontawesome.com/v4.7.0/icons/" target="_blank">'
'Refer docs.</a>'
2018-02-27 22:39:19 +00:00
)
)
class DCLSectionImagePluginModel(CMSPlugin):
image = FilerImageField(
on_delete=models.CASCADE,
help_text=(
'Image file to be used in section. Add multiple plugins '
'to add more than one image'
)
)
caption = models.CharField(
max_length=100, null=True, blank=True,
help_text='Optional caption for the image.'
)
2018-03-21 19:22:06 +00:00
class DCLSectionPromoPluginModel(CMSPlugin):
background_image = FilerImageField(
on_delete=models.CASCADE, null=True, blank=True,
help_text=('Optional background image for the Promo Section'),
related_name="dcl_section_promo_promo",
)
heading = models.CharField(
blank=True, null=True, max_length=100,
help_text='An optional heading for the Promo Section',
)
subheading = models.CharField(
blank=True, null=True, max_length=200,
help_text='An optional subheading for the Promo Section',
)
content = HTMLField()
html_id = models.SlugField(
blank=True, null=True,
help_text=(
'An optional html id for the Section. Required to set as target '
'of a link on page'
)
)
plain_heading = models.BooleanField(
default=False,
help_text='Select to keep the heading style simpler.'
)
2018-03-22 19:20:01 +00:00
text_center = models.BooleanField(
2018-03-21 19:22:06 +00:00
default=False,
help_text='Select to center align content on small screens.'
)
def __str__(self):
return '#' + self.html_id if self.html_id else str(self.pk)
2018-03-22 19:20:01 +00:00
def get_extra_classes(self):
extra_classes = ''
if self.text_center:
extra_classes += ' text-center'
if self.plain_heading:
extra_classes += ' promo-section-plain'
if self.background_image:
extra_classes += ' promo-with-bg'
return extra_classes