diff --git a/Changelog b/Changelog index 471f0720..d616964f 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,21 @@ +Next: + * bugfix: Fix flake8 error that was ignored in release 1.9.1 +1.9.1: 2018-06-24 + * #4799: [dcl] Show selected vm templates only in calculator (PR #638) + * #4847: [comic] Add google analytics code for comic.ungleich.ch (PR #639) + * feature: add vm_type option to vm_template and dcl calculator to distinguish between public and ipv6only templates (PR #635) +1.9: 2018-05-16 + * #4559: [cms] enable discount on cms calculator +1.8: 2018-05-01 + * #4527: [hosting] cms calculator on non-cms pages for the hosting app + * bgfix: [dcl] navbar dropdown target fix + * bgfix: [hosting] login/signup pages footer link fix +1.7.2: 2018-04-30 + * bgfix: [cms] add favicon extension to ungleich cms pages + * #4474: [cms] reduce heading slider side padding +1.7.1: 2018-04-21 + * #4481: [blog] fix de blog pages 500 error + * #4370: [comic] new url /comic to show only comic blogs 1.7: 2018-04-20 * bgfix: [all] Make /blog available on all domains * #4367: [dcl] email logo resolution fix diff --git a/datacenterlight/admin.py b/datacenterlight/admin.py index d95e4f87..5a1fc8a2 100644 --- a/datacenterlight/admin.py +++ b/datacenterlight/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin from cms.admin.placeholderadmin import PlaceholderAdminMixin from cms.extensions import PageExtensionAdmin from .cms_models import CMSIntegration, CMSFaviconExtension -from .models import VMPricing +from .models import VMPricing, VMTemplate class CMSIntegrationAdmin(PlaceholderAdminMixin, admin.ModelAdmin): @@ -16,3 +16,4 @@ class CMSFaviconExtensionAdmin(PageExtensionAdmin): admin.site.register(CMSIntegration, CMSIntegrationAdmin) admin.site.register(CMSFaviconExtension, CMSFaviconExtensionAdmin) admin.site.register(VMPricing) +admin.site.register(VMTemplate) diff --git a/datacenterlight/cms_models.py b/datacenterlight/cms_models.py index dd6a165f..62a7b312 100644 --- a/datacenterlight/cms_models.py +++ b/datacenterlight/cms_models.py @@ -2,6 +2,9 @@ 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 import forms +from django.conf import settings +from django.contrib.postgres.fields import ArrayField from django.contrib.sites.models import Site from django.db import models from django.utils.safestring import mark_safe @@ -9,7 +12,7 @@ from djangocms_text_ckeditor.fields import HTMLField from filer.fields.file import FilerFileField from filer.fields.image import FilerImageField -from datacenterlight.models import VMPricing +from datacenterlight.models import VMPricing, VMTemplate class CMSIntegration(models.Model): @@ -26,6 +29,10 @@ class CMSIntegration(models.Model): 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: @@ -288,10 +295,58 @@ class DCLSectionPromoPluginModel(CMSPlugin): return extra_classes -class DCLCustomPricingModel(CMSPlugin): +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. + """ + 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 + ) + ) + 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): pricing = models.ForeignKey( VMPricing, related_name="dcl_custom_pricing_vm_pricing", help_text='Choose a pricing that will be associated with this ' 'Calculator' ) + 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." + ) diff --git a/datacenterlight/cms_plugins.py b/datacenterlight/cms_plugins.py index 19dc0b39..95a496d8 100644 --- a/datacenterlight/cms_plugins.py +++ b/datacenterlight/cms_plugins.py @@ -6,9 +6,9 @@ from .cms_models import ( DCLFooterPluginModel, DCLLinkPluginModel, DCLNavbarDropdownPluginModel, DCLSectionIconPluginModel, DCLSectionImagePluginModel, DCLSectionPluginModel, DCLNavbarPluginModel, - DCLSectionPromoPluginModel, DCLCustomPricingModel + DCLSectionPromoPluginModel, DCLCalculatorPluginModel ) -from .models import VMTemplate, VMPricing +from .models import VMTemplate @plugin_pool.register_plugin @@ -21,7 +21,7 @@ class DCLSectionPlugin(CMSPluginBase): allow_children = True child_classes = [ 'DCLSectionIconPlugin', 'DCLSectionImagePlugin', - 'DCLSectionPromoPlugin', 'UngleichHTMLPlugin' + 'DCLSectionPromoPlugin', 'UngleichHTMLPlugin', 'DCLCalculatorPlugin' ] def render(self, context, instance, placeholder): @@ -30,14 +30,17 @@ class DCLSectionPlugin(CMSPluginBase): ) context['children_to_side'] = [] context['children_to_content'] = [] + context['children_calculator'] = [] if instance.child_plugin_instances is not None: right_children = [ 'DCLSectionImagePluginModel', - 'DCLSectionIconPluginModel' + 'DCLSectionIconPluginModel', ] for child in instance.child_plugin_instances: if child.__class__.__name__ in right_children: context['children_to_side'].append(child) + elif child.plugin_type == 'DCLCalculatorPlugin': + context['children_calculator'].append(child) else: context['children_to_content'].append(child) return context @@ -75,52 +78,28 @@ class DCLSectionPromoPlugin(CMSPluginBase): @plugin_pool.register_plugin class DCLCalculatorPlugin(CMSPluginBase): module = "Datacenterlight" - name = "DCL Calculator Section Plugin" - model = DCLSectionPluginModel + name = "DCL Calculator Plugin" + model = DCLCalculatorPluginModel render_template = "datacenterlight/cms/calculator.html" cache = False - allow_children = True - child_classes = [ - 'DCLSectionPromoPlugin', 'UngleichHTMLPlugin', 'DCLCustomPricingPlugin' - ] + require_parent = True def render(self, context, instance, placeholder): context = super(DCLCalculatorPlugin, self).render( context, instance, placeholder ) - context['templates'] = VMTemplate.objects.all() - context['children_to_content'] = [] - pricing_plugin_model = None - if instance.child_plugin_instances is not None: - context['children_to_content'].extend( - instance.child_plugin_instances - ) - for child in instance.child_plugin_instances: - if child.__class__.__name__ == 'DCLCustomPricingModel': - # The second clause is just to make sure we pick up the - # most recent CustomPricing, if more than one is present - if (pricing_plugin_model is None or child.pricing_id > - pricing_plugin_model.model.pricing_id): - pricing_plugin_model = child - - if pricing_plugin_model: - context['vm_pricing'] = VMPricing.get_vm_pricing_by_name( - name=pricing_plugin_model.pricing.name - ) + ids = instance.vm_templates_to_show + if ids: + context['templates'] = VMTemplate.objects.filter( + vm_type=instance.vm_type + ).filter(opennebula_vm_template_id__in=ids) else: - context['vm_pricing'] = VMPricing.get_default_pricing() - + context['templates'] = VMTemplate.objects.filter( + vm_type=instance.vm_type + ) return context -@plugin_pool.register_plugin -class DCLCustomPricingPlugin(CMSPluginBase): - module = "Datacenterlight" - name = "DCL Custom Pricing Plugin" - model = DCLCustomPricingModel - render_plugin = False - - @plugin_pool.register_plugin class DCLBannerListPlugin(CMSPluginBase): module = "Datacenterlight" diff --git a/datacenterlight/locale/de/LC_MESSAGES/django.po b/datacenterlight/locale/de/LC_MESSAGES/django.po index 50dbfbe8..4a95c2fc 100644 --- a/datacenterlight/locale/de/LC_MESSAGES/django.po +++ b/datacenterlight/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-04-17 19:26+0000\n" +"POT-Creation-Date: 2018-05-12 21:43+0530\n" "PO-Revision-Date: 2018-03-30 23:22+0000\n" "Last-Translator: b'Anonymous User '\n" "Language-Team: LANGUAGE \n" @@ -19,6 +19,9 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Translated-Using: django-rosetta 0.8.1\n" +msgid "CMS Favicon" +msgstr "" + #, python-format msgid "Your New VM %(vm_name)s at Data Center Light" msgstr "Deine neue VM %(vm_name)s bei Data Center Light" @@ -140,6 +143,9 @@ msgstr "Monat" msgid "VAT included" msgstr "MwSt. inklusive" +msgid "You save" +msgstr "Du sparst" + msgid "Hosted in Switzerland" msgstr "Standort: Schweiz" @@ -314,6 +320,12 @@ msgstr "exkl. Mehrwertsteuer" msgid "Month" msgstr "Monat" +msgid "Discount" +msgstr "Rabatt" + +msgid "Will be applied at checkout" +msgstr "wird an der Kasse angewendet" + msgid "Credit Card" msgstr "Kreditkarte" @@ -386,9 +398,10 @@ msgstr "Zwischensumme" msgid "VAT" msgstr "Mehrwertsteuer" +#, python-format msgid "" "By clicking \"Place order\" this plan will charge your credit card account " -"with the fee of %(vm_total_price)s CHF/month" +"with %(vm_total_price)s CHF/month" msgstr "" "Wenn Du \"bestellen\" auswählst, wird Deine Kreditkarte mit " "%(vm_total_price)s CHF pro Monat belastet" diff --git a/datacenterlight/management/commands/fetchvmtemplates.py b/datacenterlight/management/commands/fetchvmtemplates.py index 6a45ebad..89271dc4 100644 --- a/datacenterlight/management/commands/fetchvmtemplates.py +++ b/datacenterlight/management/commands/fetchvmtemplates.py @@ -10,16 +10,28 @@ class Command(BaseCommand): help = '''Fetches the VM templates from OpenNebula and populates the dcl VMTemplate model''' + def get_templates(self, manager, prefix): + templates = manager.get_templates('%s-' % prefix) + dcl_vm_templates = [] + for template in templates: + template_name = template.name.lstrip('%s-' % prefix) + template_id = template.id + dcl_vm_template = VMTemplate.create( + template_name, template_id, prefix + ) + dcl_vm_templates.append(dcl_vm_template) + return dcl_vm_templates + def handle(self, *args, **options): try: manager = OpenNebulaManager() - templates = manager.get_templates() dcl_vm_templates = [] - for template in templates: - template_name = template.name.lstrip('public-') - template_id = template.id - dcl_vm_template = VMTemplate.create(template_name, template_id) - dcl_vm_templates.append(dcl_vm_template) + dcl_vm_templates.extend( + self.get_templates(manager, VMTemplate.PUBLIC) + ) + dcl_vm_templates.extend( + self.get_templates(manager, VMTemplate.IPV6) + ) old_vm_templates = VMTemplate.objects.all() old_vm_templates.delete() diff --git a/datacenterlight/migrations/0021_cmsintegration_calculator_placeholder.py b/datacenterlight/migrations/0021_cmsintegration_calculator_placeholder.py new file mode 100644 index 00000000..3ebbb469 --- /dev/null +++ b/datacenterlight/migrations/0021_cmsintegration_calculator_placeholder.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2018-04-25 09:20 +from __future__ import unicode_literals + +import cms.models.fields +from django.db import migrations +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('datacenterlight', '0020_merge'), + ('cms', '0014_auto_20160404_1908'), + ] + + operations = [ + migrations.AddField( + model_name='cmsintegration', + name='calculator_placeholder', + field=cms.models.fields.PlaceholderField(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, + related_name='dcl-calculator-placeholder+', slotname='datacenterlight_calculator', to='cms.Placeholder'), + ), + migrations.RenameModel( + old_name='DCLCustomPricingModel', + new_name='DCLCalculatorPluginModel', + ), + ] diff --git a/datacenterlight/migrations/0022_auto_20180506_1950.py b/datacenterlight/migrations/0022_auto_20180506_1950.py new file mode 100644 index 00000000..a5554a58 --- /dev/null +++ b/datacenterlight/migrations/0022_auto_20180506_1950.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2018-05-07 02:19 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('datacenterlight', '0021_cmsintegration_calculator_placeholder'), + ] + + operations = [ + migrations.AddField( + model_name='vmpricing', + name='discount_amount', + field=models.DecimalField( + decimal_places=2, default=0, max_digits=6), + ), + migrations.AddField( + model_name='vmpricing', + name='discount_name', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/datacenterlight/migrations/0023_auto_20180524_0349.py b/datacenterlight/migrations/0023_auto_20180524_0349.py new file mode 100644 index 00000000..f37d6634 --- /dev/null +++ b/datacenterlight/migrations/0023_auto_20180524_0349.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2018-05-23 22:19 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('datacenterlight', '0022_auto_20180506_1950'), + ] + + operations = [ + migrations.AddField( + model_name='dclcalculatorpluginmodel', + name='vm_type', + field=models.CharField(choices=[('public', 'Public'), ('ipv6only', 'Ipv6Only')], default='public', max_length=50), + ), + migrations.AddField( + model_name='vmtemplate', + name='vm_type', + field=models.CharField(choices=[('public', 'Public'), ('ipv6only', 'Ipv6Only')], default='public', max_length=50), + ), + ] diff --git a/datacenterlight/migrations/0024_dclcalculatorpluginmodel_vm_templates_to_show.py b/datacenterlight/migrations/0024_dclcalculatorpluginmodel_vm_templates_to_show.py new file mode 100644 index 00000000..65bfce21 --- /dev/null +++ b/datacenterlight/migrations/0024_dclcalculatorpluginmodel_vm_templates_to_show.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2018-06-24 08:23 +from __future__ import unicode_literals + +import datacenterlight.cms_models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('datacenterlight', '0023_auto_20180524_0349'), + ] + + operations = [ + migrations.AddField( + model_name='dclcalculatorpluginmodel', + name='vm_templates_to_show', + field=datacenterlight.cms_models.MultipleChoiceArrayField(base_field=models.CharField(blank=True, max_length=256), blank=True, default=list, 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.', size=None), + ), + ] diff --git a/datacenterlight/models.py b/datacenterlight/models.py index eceb7617..729bbdf9 100644 --- a/datacenterlight/models.py +++ b/datacenterlight/models.py @@ -6,13 +6,29 @@ logger = logging.getLogger(__name__) class VMTemplate(models.Model): + PUBLIC = 'public' + IPV6 = 'ipv6only' + VM_TYPE_CHOICES = ( + (PUBLIC, PUBLIC.title()), + (IPV6, IPV6.title()), + ) name = models.CharField(max_length=50) opennebula_vm_template_id = models.IntegerField() + vm_type = models.CharField( + max_length=50, choices=VM_TYPE_CHOICES, default=PUBLIC + ) + + def __str__(self): + return '%s - %s - %s' % ( + self.opennebula_vm_template_id, self.vm_type, self.name + ) @classmethod - def create(cls, name, opennebula_vm_template_id): + def create(cls, name, opennebula_vm_template_id, vm_type): vm_template = cls( - name=name, opennebula_vm_template_id=opennebula_vm_template_id) + name=name, opennebula_vm_template_id=opennebula_vm_template_id, + vm_type=vm_type + ) return vm_template @@ -34,16 +50,29 @@ class VMPricing(models.Model): hdd_unit_price = models.DecimalField( max_digits=7, decimal_places=6, default=0 ) + discount_name = models.CharField(max_length=255, null=True, blank=True) + discount_amount = models.DecimalField( + max_digits=6, decimal_places=2, default=0 + ) def __str__(self): - return self.name + ' => ' + ' - '.join([ + display_str = self.name + ' => ' + ' - '.join([ '{}/Core'.format(self.cores_unit_price.normalize()), '{}/GB RAM'.format(self.ram_unit_price.normalize()), '{}/GB SSD'.format(self.ssd_unit_price.normalize()), '{}/GB HDD'.format(self.hdd_unit_price.normalize()), '{}% VAT'.format(self.vat_percentage.normalize()) - if not self.vat_inclusive else 'VAT-Incl', ] - ) + if not self.vat_inclusive else 'VAT-Incl', + ]) + if self.discount_amount: + display_str = ' - '.join([ + display_str, + '{} {}'.format( + self.discount_amount, + self.discount_name if self.discount_name else 'Discount' + ) + ]) + return display_str @classmethod def get_vm_pricing_by_name(cls, name): diff --git a/datacenterlight/static/datacenterlight/css/common.css b/datacenterlight/static/datacenterlight/css/common.css index 895256ef..b6eabd75 100644 --- a/datacenterlight/static/datacenterlight/css/common.css +++ b/datacenterlight/static/datacenterlight/css/common.css @@ -150,3 +150,12 @@ footer .dcl-link-separator::before { border-radius: 100%; background: #777; } + +.mb-0 { + margin-bottom: 0; +} + +.thin-hr { + margin-top: 10px; + margin-bottom: 10px; +} \ No newline at end of file diff --git a/datacenterlight/static/datacenterlight/css/header-slider.css b/datacenterlight/static/datacenterlight/css/header-slider.css index d01f02a7..ea01edf7 100644 --- a/datacenterlight/static/datacenterlight/css/header-slider.css +++ b/datacenterlight/static/datacenterlight/css/header-slider.css @@ -55,7 +55,7 @@ flex: 1; } -.header_slider > .carousel .item .container { +.header_slider > .carousel .item .container-fluid { overflow: auto; padding: 50px 20px 60px; height: 100%; @@ -104,9 +104,9 @@ .header_slider .carousel-control .fa { font-size: 4em; } - .header_slider > .carousel .item .container { + .header_slider > .carousel .item .container-fluid { overflow: auto; - padding: 75px 50px; + padding: 75px; } .header_slider .btn-trans { padding: 8px 15px; @@ -120,11 +120,6 @@ .header_slider .intro-cap { font-size: 3.25em; } - - .header_slider > .carousel .item .container { - padding-left: 0; - padding-right: 0; - } } .header_slider .intro_lead { diff --git a/datacenterlight/static/datacenterlight/css/hosting.css b/datacenterlight/static/datacenterlight/css/hosting.css index b4c5909c..0f16ab77 100644 --- a/datacenterlight/static/datacenterlight/css/hosting.css +++ b/datacenterlight/static/datacenterlight/css/hosting.css @@ -482,6 +482,7 @@ margin: 100px auto 40px; border: 1px solid #ccc; padding: 30px 30px 20px; + color: #595959; } .order-detail-container .dashboard-title-thin { @@ -503,10 +504,6 @@ margin-bottom: 15px; } -.order-detail-container .order-details strong { - color: #595959; -} - .order-detail-container h4 { font-size: 16px; font-weight: bold; @@ -515,13 +512,28 @@ .order-detail-container p { margin-bottom: 5px; - color: #595959; } .order-detail-container hr { margin: 15px 0; } +.order-detail-container .thin-hr { + margin: 10px 0; +} + +.order-detail-container .subtotal-price { + font-size: 16px; +} + +.order-detail-container .subtotal-price .text-primary { + font-size: 17px; +} + +.order-detail-container .total-price { + font-size: 18px; +} + @media (max-width: 767px) { .order-detail-container { padding: 15px; diff --git a/datacenterlight/static/datacenterlight/css/landing-page.css b/datacenterlight/static/datacenterlight/css/landing-page.css index 8e9f2c2d..f241ed71 100755 --- a/datacenterlight/static/datacenterlight/css/landing-page.css +++ b/datacenterlight/static/datacenterlight/css/landing-page.css @@ -776,7 +776,7 @@ textarea { width: 100%; margin: 0 auto; background: #fff; - box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23); + box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1), 0 0 6px rgba(0, 0, 0, 0.15); padding-bottom: 40px; border-radius: 7px; text-align: center; @@ -929,7 +929,7 @@ textarea { } -@media(max-width:991px) { +@media(max-width:767px) { .section-sm-center .split-text, .section-sm-center .space { text-align: center !important; diff --git a/datacenterlight/static/datacenterlight/js/main.js b/datacenterlight/static/datacenterlight/js/main.js index 35f2b247..292e8c16 100644 --- a/datacenterlight/static/datacenterlight/js/main.js +++ b/datacenterlight/static/datacenterlight/js/main.js @@ -175,14 +175,18 @@ window.coresUnitPrice = 5; } if(typeof window.ramUnitPrice === 'undefined'){ - window.coresUnitPrice = 2; + window.ramUnitPrice = 2; } if(typeof window.ssdUnitPrice === 'undefined'){ window.ssdUnitPrice = 0.6; } + if(typeof window.discountAmount === 'undefined'){ + window.discountAmount = 0; + } var total = (cardPricing['cpu'].value * window.coresUnitPrice) + (cardPricing['ram'].value * window.ramUnitPrice) + - (cardPricing['storage'].value * window.ssdUnitPrice); + (cardPricing['storage'].value * window.ssdUnitPrice) - + window.discountAmount; total = parseFloat(total.toFixed(2)); $("#total").text(total); } diff --git a/datacenterlight/templates/datacenterlight/cms/base.html b/datacenterlight/templates/datacenterlight/cms/base.html index 942a0ad4..a614db67 100644 --- a/datacenterlight/templates/datacenterlight/cms/base.html +++ b/datacenterlight/templates/datacenterlight/cms/base.html @@ -61,6 +61,7 @@ {% endplaceholder %} + {% url 'datacenterlight:index' as calculator_form_url %} {% placeholder 'Datacenterlight Content' %} {% placeholder 'datacenterlight_footer'%} diff --git a/datacenterlight/templates/datacenterlight/cms/calculator.html b/datacenterlight/templates/datacenterlight/cms/calculator.html index 27d1f89c..7b123a72 100644 --- a/datacenterlight/templates/datacenterlight/cms/calculator.html +++ b/datacenterlight/templates/datacenterlight/cms/calculator.html @@ -1,16 +1,5 @@ -
-
-
-
- {% include "datacenterlight/cms/includes/_section_split_content.html" %} -
-
-
-
- {% include "datacenterlight/includes/_calculator_form.html" %} -
-
-
-
+
+
+ {% include "datacenterlight/includes/_calculator_form.html" with vm_pricing=instance.pricing %}
\ No newline at end of file diff --git a/datacenterlight/templates/datacenterlight/cms/navbar_dropdown.html b/datacenterlight/templates/datacenterlight/cms/navbar_dropdown.html index 051e8914..70926874 100644 --- a/datacenterlight/templates/datacenterlight/cms/navbar_dropdown.html +++ b/datacenterlight/templates/datacenterlight/cms/navbar_dropdown.html @@ -1,10 +1,10 @@ {% load cms_tags %} \ No newline at end of file +
diff --git a/datacenterlight/templates/datacenterlight/cms/section.html b/datacenterlight/templates/datacenterlight/cms/section.html index 5a420a99..4438cf7d 100644 --- a/datacenterlight/templates/datacenterlight/cms/section.html +++ b/datacenterlight/templates/datacenterlight/cms/section.html @@ -2,17 +2,24 @@
- {% if children_to_side|length %} + {% if children_to_side|length or children_calculator|length %}
{% include "datacenterlight/cms/includes/_section_split_content.html" %}
-
- {% for plugin in children_to_side %} + {% if children_calculator|length %} + {% for plugin in children_calculator %} {% render_plugin plugin %} {% endfor %} -
+ {% endif %} + {% if children_to_side %} +
+ {% for plugin in children_to_side %} + {% render_plugin plugin %} + {% endfor %} +
+ {% endif %}
{% else %} diff --git a/datacenterlight/templates/datacenterlight/includes/_calculator_form.html b/datacenterlight/templates/datacenterlight/includes/_calculator_form.html index e3fe8676..72ca5a05 100644 --- a/datacenterlight/templates/datacenterlight/includes/_calculator_form.html +++ b/datacenterlight/templates/datacenterlight/includes/_calculator_form.html @@ -8,22 +8,26 @@ window.ramUnitPrice = {{vm_pricing.ram_unit_price|default:0}}; window.ssdUnitPrice = {{vm_pricing.ssd_unit_price|default:0}}; window.hddUnitPrice = {{vm_pricing.hdd_unit_price|default:0}}; + window.discountAmount = {{vm_pricing.discount_amount|default:0}}; {% endif %} -
+ {% csrf_token %}

{% trans "VM hosting" %}

- 15 + CHF/{% trans "month" %} - {% if vm_pricing.vat_inclusive %}
-

{% trans "VAT included" %}

+

+ {% if vm_pricing.vat_inclusive %}{% trans "VAT included" %}
{% endif %} + {% if vm_pricing.discount_amount %} + {% trans "You save" %} {{ vm_pricing.discount_amount }} CHF + {% endif %} +

- {% endif %}
@@ -94,4 +98,4 @@
- + \ No newline at end of file diff --git a/datacenterlight/templates/datacenterlight/landing_payment.html b/datacenterlight/templates/datacenterlight/landing_payment.html index b808e033..4d111fa1 100644 --- a/datacenterlight/templates/datacenterlight/landing_payment.html +++ b/datacenterlight/templates/datacenterlight/landing_payment.html @@ -78,7 +78,24 @@

{% trans "Configuration"%} {{request.session.template.name}}


-

{%trans "Total" %}  ({% if vm_pricing.vat_inclusive %}{%trans "including VAT" %}{% else %}{%trans "excluding VAT" %}{% endif %}) {{request.session.specs.price|intcomma}} CHF/{% trans "Month" %}

+

+ {%trans "Total" %}   + + ({% if vm_pricing.vat_inclusive %}{%trans "including VAT" %}{% else %}{%trans "excluding VAT" %}{% endif %}) + + {{request.session.specs.price|intcomma}} CHF/{% trans "Month" %} +

+
+ {% if vm_pricing.discount_amount %} +

+ {%trans "Discount" as discount_name %} + {{ vm_pricing.discount_name|default:discount_name }}   + - {{ vm_pricing.discount_amount }} CHF/{% trans "Month" %} +

+

+ ({% trans "Will be applied at checkout" %}) +

+ {% endif %}
diff --git a/datacenterlight/templates/datacenterlight/order_detail.html b/datacenterlight/templates/datacenterlight/order_detail.html index 95bfa3c6..49347ba2 100644 --- a/datacenterlight/templates/datacenterlight/order_detail.html +++ b/datacenterlight/templates/datacenterlight/order_detail.html @@ -55,40 +55,61 @@

{% trans "Cores" %}: - {{vm.cpu|floatformat}} + {{vm.cpu|floatformat}}

{% trans "Memory" %}: - {{vm.memory|intcomma}} GB + {{vm.memory|intcomma}} GB

{% trans "Disk space" %}: - {{vm.disk_size|intcomma}} GB + {{vm.disk_size|intcomma}} GB

- {% if vm.vat > 0 %} -

- {% trans "Subtotal" %}: - {{vm.price|floatformat:2|intcomma}} CHF -

-

- {% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%): - {{vm.vat|floatformat:2|intcomma}} CHF -

- {% endif %} -

- {% trans "Total" %} - {{vm.total_price|floatformat:2|intcomma}} CHF +

+
+
+
+ {% if vm.vat > 0 or vm.discount.amount > 0 %} +
+
+ {% if vm.vat > 0 %} +

+ {% trans "Subtotal" %} + {{vm.price|floatformat:2|intcomma}} CHF +

+

+ {% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%) + {{vm.vat|floatformat:2|intcomma}} CHF +

+ {% endif %} + {% if vm.discount.amount > 0 %} +

+ {%trans "Discount" as discount_name %} + {{ vm.discount.name|default:discount_name }} + - {{ vm.discount.amount }} CHF +

+ {% endif %} +
+
+
+
+
+ {% endif %} +
+

+ {% trans "Total" %} + {{vm.total_price|floatformat:2|intcomma}} CHF

-
+
{% csrf_token %}
-
{% blocktrans with vm_total_price=vm.total_price|floatformat:2|intcomma %}By clicking "Place order" this plan will charge your credit card account with the fee of {{vm_total_price}} CHF/month{% endblocktrans %}.
+
{% blocktrans with vm_total_price=vm.total_price|floatformat:2|intcomma %}By clicking "Place order" this plan will charge your credit card account with {{vm_total_price}} CHF/month{% endblocktrans %}.
+
+
+
+ {% if vm.vat > 0 or vm.discount.amount > 0 %} +
+
+ {% if vm.vat > 0 %} +

+ {% trans "Subtotal" %} + {{vm.price|floatformat:2|intcomma}} CHF +

+

+ {% trans "VAT" %} ({{ vm.vat_percent|floatformat:2|intcomma }}%) + {{vm.vat|floatformat:2|intcomma}} CHF +

+ {% endif %} + {% if vm.discount.amount > 0 %} +

+ {%trans "Discount" as discount_name %} + {{ vm.discount.name|default:discount_name }} + - {{ vm.discount.amount }} CHF +

+ {% endif %} +
+
+
+
+
+ {% endif %} +
+

+ {% trans "Total" %} + {% if vm.total_price %}{{vm.total_price|floatformat:2|intcomma}}{% else %}{{vm.price|floatformat:2|intcomma}}{% endif %} CHF

-
+
{% if not order %} {% block submit_btn %} @@ -152,7 +173,7 @@ {% csrf_token %}
-
{% blocktrans with vm_price=request.session.specs.price %}By clicking "Place order" this plan will charge your credit card account with the fee of {{ vm_price|intcomma }}CHF/month{% endblocktrans %}.
+
{% blocktrans with vm_price=vm.total_price|floatformat:2|intcomma %}By clicking "Place order" this plan will charge your credit card account with {{ vm_price }} CHF/month{% endblocktrans %}.
-
- {% else %} -
- -
-
-
- -
-
-
-
- -
-
-
- -
-
-
-
- - -
-
-
-
- {% if not messages and not form.non_field_errors %} -

- {% trans "You are not making any payment yet. After submitting your card information, you will be taken to the Confirm Order Page." %} + {% endif %} +

+ {% for message in messages %} + {% if 'failed_payment' or 'make_charge_error' in message.tags %} +
    +
  • +

    {{ message|safe }}

    +
  • +
+ {% endif %} + {% endfor %} + {% for error in form.non_field_errors %} +

+ {{ error|escape }}

- {% endif %} -
- {% for message in messages %} - {% if 'failed_payment' or 'make_charge_error' in message.tags %} -
    -
  • -

    {{ message|safe }}

    -
  • -
- {% endif %} - {% endfor %} - - {% for error in form.non_field_errors %} -

- {{ error|escape }} + {% endfor %} +

+
+ +
+ {% else %} + + +
+
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+ + +
+
+
+
+ {% if not messages and not form.non_field_errors %} +

+ {% trans "You are not making any payment yet. After submitting your card information, you will be taken to the Confirm Order Page." %}

- {% endfor %} -
-
- -
-
+ {% endif %} +
+ {% for message in messages %} + {% if 'failed_payment' or 'make_charge_error' in message.tags %} +
    +
  • +

    {{ message|safe }}

    +
  • +
+ {% endif %} + {% endfor %} -
-

-
- - {% endif %} + {% for error in form.non_field_errors %} +

+ {{ error|escape }} +

+ {% endfor %} +
+
+ +
+ + +
+

+
+ + {% endif %} + diff --git a/hosting/views.py b/hosting/views.py index 04ccafba..07bafd97 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -31,8 +31,8 @@ from stored_messages.api import mark_read from stored_messages.models import Message from stored_messages.settings import stored_messages_settings -from datacenterlight.models import VMTemplate -from datacenterlight.utils import create_vm +from datacenterlight.models import VMTemplate, VMPricing +from datacenterlight.utils import create_vm, get_cms_integration from membership.models import CustomUser, StripeCustomer from opennebula_api.models import OpenNebulaManager from opennebula_api.serializers import ( @@ -43,7 +43,7 @@ from utils.forms import ( BillingAddressForm, PasswordResetRequestForm, UserBillingAddressForm, ResendActivationEmailForm ) -from utils.hosting_utils import get_vm_price, get_vm_price_with_vat +from utils.hosting_utils import get_vm_price_with_vat from utils.mailer import BaseEmail from utils.stripe_utils import StripeUtils from utils.tasks import send_plain_email_task @@ -652,7 +652,10 @@ class PaymentVMView(LoginRequiredMixin, FormView): }) context.update({ - 'stripe_key': settings.STRIPE_API_PUBLIC_KEY + 'stripe_key': settings.STRIPE_API_PUBLIC_KEY, + 'vm_pricing': VMPricing.get_vm_pricing_by_name( + self.request.session.get('specs', {}).get('pricing_name') + ), }) return context @@ -750,7 +753,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): context['vm'] = vm_detail.__dict__ context['vm']['name'] = '{}-{}'.format( context['vm']['configuration'], context['vm']['vm_id']) - price, vat, vat_percent = get_vm_price_with_vat( + price, vat, vat_percent, discount = get_vm_price_with_vat( cpu=context['vm']['cores'], ssd_size=context['vm']['disk_size'], memory=context['vm']['memory'], @@ -759,8 +762,9 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): ) context['vm']['vat'] = vat context['vm']['price'] = price + context['vm']['discount'] = discount context['vm']['vat_percent'] = vat_percent - context['vm']['total_price'] = price + vat + context['vm']['total_price'] = price + vat - discount['amount'] context['subscription_end_date'] = vm_detail.end_date() except VMDetail.DoesNotExist: try: @@ -769,7 +773,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): ) vm = manager.get_vm(obj.vm_id) context['vm'] = VirtualMachineSerializer(vm).data - price, vat, vat_percent = get_vm_price_with_vat( + price, vat, vat_percent, discount = get_vm_price_with_vat( cpu=context['vm']['cores'], ssd_size=context['vm']['disk_size'], memory=context['vm']['memory'], @@ -778,8 +782,10 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): ) context['vm']['vat'] = vat context['vm']['price'] = price + context['vm']['discount'] = discount context['vm']['vat_percent'] = vat_percent - context['vm']['total_price'] = price + vat + context['vm']['total_price'] = price + \ + vat - discount['amount'] except WrongIdError: messages.error( self.request, @@ -855,7 +861,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): cpu = specs.get('cpu') memory = specs.get('memory') disk_size = specs.get('disk_size') - amount_to_be_charged = specs.get('price') + amount_to_be_charged = specs.get('total_price') plan_name = StripeUtils.get_stripe_plan_name(cpu=cpu, memory=memory, disk_size=disk_size) @@ -1000,7 +1006,10 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): @method_decorator(decorators) def get(self, request, *args, **kwargs): - context = {'templates': VMTemplate.objects.all()} + context = { + 'templates': VMTemplate.objects.all(), + 'cms_integration': get_cms_integration('default'), + } return render(request, self.template_name, context) @method_decorator(decorators) @@ -1012,18 +1021,34 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): storage = request.POST.get('storage') storage_field = forms.IntegerField(validators=[self.validate_storage]) template_id = int(request.POST.get('config')) + pricing_name = request.POST.get('pricing_name') + vm_pricing = VMPricing.get_vm_pricing_by_name(pricing_name) template = VMTemplate.objects.filter( opennebula_vm_template_id=template_id).first() template_data = VMTemplateSerializer(template).data + if vm_pricing is None: + vm_pricing_name_msg = _( + "Incorrect pricing name. Please contact support" + "{support_email}".format( + support_email=settings.DCL_SUPPORT_FROM_ADDRESS + ) + ) + messages.add_message( + self.request, messages.ERROR, vm_pricing_name_msg, + extra_tags='pricing' + ) + return redirect(CreateVirtualMachinesView.as_view()) + else: + vm_pricing_name = vm_pricing.name + try: cores = cores_field.clean(cores) except ValidationError as err: msg = '{} : {}.'.format(cores, str(err)) messages.add_message(self.request, messages.ERROR, msg, extra_tags='cores') - return HttpResponseRedirect( - reverse('datacenterlight:index') + "#order_form") + return redirect(CreateVirtualMachinesView.as_view()) try: memory = memory_field.clean(memory) @@ -1031,8 +1056,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): msg = '{} : {}.'.format(memory, str(err)) messages.add_message(self.request, messages.ERROR, msg, extra_tags='memory') - return HttpResponseRedirect( - reverse('datacenterlight:index') + "#order_form") + return redirect(CreateVirtualMachinesView.as_view()) try: storage = storage_field.clean(storage) @@ -1040,15 +1064,25 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): msg = '{} : {}.'.format(storage, str(err)) messages.add_message(self.request, messages.ERROR, msg, extra_tags='storage') - return HttpResponseRedirect( - reverse('datacenterlight:index') + "#order_form") - price = get_vm_price(cpu=cores, memory=memory, - disk_size=storage) + return redirect(CreateVirtualMachinesView.as_view()) + + price, vat, vat_percent, discount = get_vm_price_with_vat( + cpu=cores, + memory=memory, + ssd_size=storage, + pricing_name=vm_pricing_name + ) + specs = { 'cpu': cores, 'memory': memory, 'disk_size': storage, - 'price': price + 'discount': discount, + 'price': price, + 'vat': vat, + 'vat_percent': vat_percent, + 'total_price': price + vat - discount['amount'], + 'pricing_name': vm_pricing_name } request.session['specs'] = specs @@ -1232,7 +1266,10 @@ class VirtualMachineView(LoginRequiredMixin, View): ["%s=%s" % (k, v) for (k, v) in admin_email_body.items()]), } send_plain_email_task.delay(email_to_admin_data) - return JsonResponse(response) + return HttpResponse( + json.dumps(response), + content_type="application/json" + ) class HostingBillListView(PermissionRequiredMixin, LoginRequiredMixin, diff --git a/opennebula_api/models.py b/opennebula_api/models.py index d9b0b6c2..35f3d8e8 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -61,7 +61,7 @@ class OpenNebulaManager(): domain=settings.OPENNEBULA_DOMAIN, port=settings.OPENNEBULA_PORT, endpoint=settings.OPENNEBULA_ENDPOINT - )) + )) def _get_opennebula_client(self, username, password): return oca.Client("{0}:{1}".format( @@ -73,7 +73,7 @@ class OpenNebulaManager(): domain=settings.OPENNEBULA_DOMAIN, port=settings.OPENNEBULA_PORT, endpoint=settings.OPENNEBULA_ENDPOINT - )) + )) def _get_user(self, user): """Get the corresponding opennebula user for a CustomUser object @@ -362,12 +362,12 @@ class OpenNebulaManager(): except: raise ConnectionRefusedError - def get_templates(self): + def get_templates(self, prefix='public-'): try: public_templates = [ template for template in self._get_template_pool() - if template.name.startswith('public-') + if template.name.startswith(prefix) ] return public_templates except ConnectionRefusedError: @@ -439,7 +439,7 @@ class OpenNebulaManager(): def delete_template(self, template_id): self.oneadmin_client.call(oca.VmTemplate.METHODS[ - 'delete'], template_id, False) + 'delete'], template_id, False) def change_user_password(self, passwd_hash): self.oneadmin_client.call( diff --git a/ungleich/views.py b/ungleich/views.py index 3610d1bc..af7cb304 100644 --- a/ungleich/views.py +++ b/ungleich/views.py @@ -7,6 +7,7 @@ from djangocms_blog.models import Post from djangocms_blog.views import PostListView from djangocms_blog.settings import get_setting from django.utils.translation import ugettext_lazy as _ +from djangocms_blog.models import BlogCategory def blog(request): @@ -20,6 +21,7 @@ def blog(request): class PostListViewUngleich(PostListView): + category = None model = Post context_object_name = 'post_list' base_template_name = 'post_list_ungleich.html' @@ -38,7 +40,26 @@ class PostListViewUngleich(PostListView): def get_queryset(self): language = get_language() - queryset = self.model.objects.filter(publish=True).translated(language) + if self.category: + blog_category = ( + BlogCategory + ._default_manager + .language(language) + .filter( + translations__language_code=language, + translations__slug=self.category + ) + ) + + queryset = (self.model + .objects + .filter(categories=blog_category, publish=True) + .translated(language)) + else: + queryset = (self.model + .objects + .filter(publish=True) + .translated(language)) setattr(self.request, get_setting('CURRENT_NAMESPACE'), self.config) return queryset diff --git a/ungleich_page/static/ungleich_page/css/ungleich.css b/ungleich_page/static/ungleich_page/css/ungleich.css index 2537a921..af71e692 100644 --- a/ungleich_page/static/ungleich_page/css/ungleich.css +++ b/ungleich_page/static/ungleich_page/css/ungleich.css @@ -195,7 +195,7 @@ flex: 1; } -.header_slider > .carousel .item .container { +.header_slider > .carousel .item .container-fluid { overflow: auto; padding: 50px 20px 60px; height: 100%; @@ -236,7 +236,7 @@ .header_slider .carousel-control .fa { font-size: 4em; } - .header_slider > .carousel .item .container { + .header_slider > .carousel .item .container-fluid { overflow: auto; padding: 75px 50px; } @@ -403,4 +403,4 @@ left: 0; bottom: 0; background: rgba(0,0,0,0.35); -} \ No newline at end of file +} diff --git a/ungleich_page/templates/ungleich_page/ungleich/_header_with_background_video_slider_item.html b/ungleich_page/templates/ungleich_page/ungleich/_header_with_background_video_slider_item.html index f1edba16..4761cdc5 100644 --- a/ungleich_page/templates/ungleich_page/ungleich/_header_with_background_video_slider_item.html +++ b/ungleich_page/templates/ungleich_page/ungleich/_header_with_background_video_slider_item.html @@ -13,7 +13,7 @@ {% endif %} -
+
{% if instance.heading %}
{{ instance.heading }}
{% endif %} diff --git a/ungleich_page/templates/ungleich_page/ungleich_cms_page.html b/ungleich_page/templates/ungleich_page/ungleich_cms_page.html index f8d32f07..42293b04 100644 --- a/ungleich_page/templates/ungleich_page/ungleich_cms_page.html +++ b/ungleich_page/templates/ungleich_page/ungleich_cms_page.html @@ -33,7 +33,11 @@ {% include "google_analytics.html" %} - + {% if request.current_page.cmsfaviconextension %} + + {% else %} + + {% endif %} diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 04ed658a..36964867 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -107,10 +107,12 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0, ) return None - price = ((decimal.Decimal(cpu) * pricing.cores_unit_price) + - (decimal.Decimal(memory) * pricing.ram_unit_price) + - (decimal.Decimal(ssd_size) * pricing.ssd_unit_price) + - (decimal.Decimal(hdd_size) * pricing.hdd_unit_price)) + price = ( + (decimal.Decimal(cpu) * pricing.cores_unit_price) + + (decimal.Decimal(memory) * pricing.ram_unit_price) + + (decimal.Decimal(ssd_size) * pricing.ssd_unit_price) + + (decimal.Decimal(hdd_size) * pricing.hdd_unit_price) + ) if pricing.vat_inclusive: vat = decimal.Decimal(0) vat_percent = decimal.Decimal(0) @@ -121,4 +123,8 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0, cents = decimal.Decimal('.01') price = price.quantize(cents, decimal.ROUND_HALF_UP) vat = vat.quantize(cents, decimal.ROUND_HALF_UP) - return float(price), float(vat), float(vat_percent) + discount = { + 'name': pricing.discount_name, + 'amount': float(pricing.discount_amount), + } + return float(price), float(vat), float(vat_percent), discount