dynamicweb/datacenterlight/cms_models.py

365 lines
12 KiB
Python
Raw Normal View History

2018-04-12 03:26:24 +00:00
from cms.extensions import PageExtension
from cms.extensions.extension_pool import extension_pool
from cms.models.fields import PlaceholderField
2018-02-27 22:39:19 +00:00
from cms.models.pluginmodel import CMSPlugin
from django import forms
2018-06-27 07:06:28 +00:00
from django.conf import settings
from django.contrib.postgres.fields import ArrayField
from django.contrib.sites.models import Site
2018-02-27 22:39:19 +00:00
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-04-12 03:26:24 +00:00
from filer.fields.file import FilerFileField
2018-02-27 22:39:19 +00:00
from filer.fields.image import FilerImageField
2018-03-27 13:49:26 +00:00
2018-05-23 22:27:01 +00:00
from datacenterlight.models import VMPricing, VMTemplate
2018-04-09 19:18:18 +00:00
2018-03-27 13:49:26 +00:00
class CMSIntegration(models.Model):
name = models.CharField(
max_length=100, 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+'
)
calculator_placeholder = PlaceholderField(
'datacenterlight_calculator',
related_name='dcl-calculator-placeholder+'
)
domain = models.ForeignKey(Site, null=True, blank=True)
class Meta:
unique_together = ('name', 'domain')
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
2018-04-12 03:26:24 +00:00
class CMSFaviconExtension(PageExtension):
favicon = FilerFileField(related_name="cms_favicon_image")
extension_pool.register(CMSFaviconExtension)
2018-02-27 22:39:19 +00:00
2018-04-12 03:26:24 +00:00
# Models for CMS Plugins
2018-02-27 22:39:19 +00:00
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.'
)
show_login_option = models.BooleanField(
default=True,
help_text='Uncheck this if you do not want to show login/dashboard.'
)
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
2018-04-09 19:18:18 +00:00
class MultipleChoiceArrayField(ArrayField):
"""
A field that allows us to store an array of choices.
Uses Django's Postgres ArrayField
and a MultipleChoiceField for its formfield.
"""
2018-06-27 07:06:28 +00:00
VMTemplateChoices = []
if settings.OPENNEBULA_DOMAIN != 'test_domain':
VMTemplateChoices = list(
(
str(obj.opennebula_vm_template_id),
(obj.name + ' - ' + VMTemplate.IPV6.title()
if obj.vm_type == VMTemplate.IPV6 else obj.name
)
)
2018-06-27 07:06:28 +00:00
for obj in VMTemplate.objects.all()
)
def formfield(self, **kwargs):
defaults = {
'form_class': forms.MultipleChoiceField,
'choices': self.VMTemplateChoices,
}
defaults.update(kwargs)
# Skip our parent's formfield implementation completely as we don't
# care for it.
# pylint:disable=bad-super-call
return super(ArrayField, self).formfield(**defaults)
class DCLCalculatorPluginModel(CMSPlugin):
2018-04-09 19:18:18 +00:00
pricing = models.ForeignKey(
VMPricing,
related_name="dcl_custom_pricing_vm_pricing",
2018-04-09 19:18:18 +00:00
help_text='Choose a pricing that will be associated with this '
'Calculator'
)
2018-05-23 22:27:01 +00:00
vm_type = models.CharField(
max_length=50, choices=VMTemplate.VM_TYPE_CHOICES,
default=VMTemplate.PUBLIC
)
vm_templates_to_show = MultipleChoiceArrayField(
base_field=models.CharField(
blank=True,
max_length=256,
),
default=list,
blank=True,
help_text="Recommended: If you wish to show all templates of the "
"corresponding VM Type (public/ipv6only), please do not "
"select any of the items in the above field. "
"This will allow any new template(s) added "
"in the backend to be automatically listed in this "
"calculator instance."
)
2018-09-27 20:33:24 +00:00
default_selected_template = models.CharField(
2018-09-27 20:14:42 +00:00
default="Devuan Ascii",
null=True,
max_length=128,
help_text="Write the name of the template that you need selected as"
" default when the calculator loads"
)
enable_512mb_ram = models.BooleanField(default=False)