diff --git a/.travis.yml b/.travis.yml index 1e92e42e..a1d0aacc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,10 @@ python: - "3.6" env: - # Set a dummy secret key + # Set a dummy secret key - DJANGO_SECRET_KEY=0 # install dependencies install: "pip install -r requirements.txt" -script: python manage.py test +script: +- flake8 +- python manage.py test diff --git a/alplora/admin.py b/alplora/admin.py index 8c38f3f3..4185d360 100644 --- a/alplora/admin.py +++ b/alplora/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +# from django.contrib import admin # Register your models here. diff --git a/alplora/models.py b/alplora/models.py index 71a83623..0b4331b3 100644 --- a/alplora/models.py +++ b/alplora/models.py @@ -1,3 +1,3 @@ -from django.db import models +# from django.db import models # Create your models here. diff --git a/alplora/tests.py b/alplora/tests.py index 7ce503c2..a79ca8be 100644 --- a/alplora/tests.py +++ b/alplora/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +# from django.test import TestCase # Create your tests here. diff --git a/alplora/urls.py b/alplora/urls.py index f792f13f..071bb2ac 100644 --- a/alplora/urls.py +++ b/alplora/urls.py @@ -7,6 +7,6 @@ urlpatterns = [ url(r'^/?$', IndexView.as_view(), name='index'), url(r'/login/', LoginView.as_view(), name='login'), url(r'/contact', ContactView.as_view(), name='contact'), -# url(r'^/beta-program/?$', BetaProgramView.as_view(), name='beta'), -# url(r'^/landing/?$', LandingProgramView.as_view(), name='landing'), + # url(r'^/beta-program/?$', BetaProgramView.as_view(), name='beta'), + # url(r'^/landing/?$', LandingProgramView.as_view(), name='landing'), ] diff --git a/alplora/views.py b/alplora/views.py index ba249887..0a10b4e0 100644 --- a/alplora/views.py +++ b/alplora/views.py @@ -4,11 +4,11 @@ from django.utils.translation import get_language, get_language_info from django.utils.translation import ugettext_lazy as _ from django.views.generic.edit import FormView from django.contrib import messages -from django.core.urlresolvers import reverse_lazy, reverse from django.shortcuts import render from utils.forms import ContactUsForm + class IndexView(TemplateView): template_name = "alplora/index.html" @@ -18,6 +18,7 @@ class IndexView(TemplateView): context.update(languages) return context + class ContactView(FormView): template_name = 'alplora/contact.html' form_class = ContactUsForm @@ -33,7 +34,8 @@ class ContactView(FormView): form.save() form.send_email(email_to='info@alplora.ch') messages.add_message(self.request, messages.SUCCESS, self.success_message) - return render(self.request, 'alplora/contact_success.html', {}) + return render(self.request, 'alplora/contact_success.html', {}) + class LoginView(TemplateView): template_name = "alplora/login.html" diff --git a/datacenterlight/forms.py b/datacenterlight/forms.py index 90340e8d..33d95c29 100644 --- a/datacenterlight/forms.py +++ b/datacenterlight/forms.py @@ -1,6 +1,6 @@ from django import forms -from .models import BetaAccess, BetaAccessVM +from .models import BetaAccess class BetaAccessForm(forms.ModelForm): diff --git a/datacenterlight/static/datacenterlight/css/landing-page.css b/datacenterlight/static/datacenterlight/css/landing-page.css index c9fd76aa..cdd88e30 100755 --- a/datacenterlight/static/datacenterlight/css/landing-page.css +++ b/datacenterlight/static/datacenterlight/css/landing-page.css @@ -826,6 +826,7 @@ tech-sub-sec h2 { margin-top: 20px; font-size: 20px; width: 200px; + border: none; } .price-calc-section .card .select-configuration select{ outline: none; diff --git a/datacenterlight/templatetags/custom_tags.py b/datacenterlight/templatetags/custom_tags.py index ed59af9a..ce6e6724 100644 --- a/datacenterlight/templatetags/custom_tags.py +++ b/datacenterlight/templatetags/custom_tags.py @@ -5,24 +5,23 @@ from django.utils.translation import activate, get_language register = template.Library() - @register.simple_tag(takes_context=True) def change_lang(context, lang=None, *args, **kwargs): path = context['request'].path - url_parts = resolve( path ) + url_parts = resolve(path) url = path cur_language = get_language() try: activate(lang) - url = reverse( url_parts.view_name, kwargs=url_parts.kwargs ) + url = reverse(url_parts.view_name, kwargs=url_parts.kwargs) finally: activate(cur_language) - return "%s" % url + @register.filter('get_value_from_dict') def get_value_from_dict(dict_data, key): """ @@ -30,5 +29,5 @@ def get_value_from_dict(dict_data, key): """ if key: return dict_data.get(key) - else : + else: return "" diff --git a/datacenterlight/tests.py b/datacenterlight/tests.py index 7ce503c2..a79ca8be 100644 --- a/datacenterlight/tests.py +++ b/datacenterlight/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +# from django.test import TestCase # Create your tests here. diff --git a/datacenterlight/urls.py b/datacenterlight/urls.py index 33ea644e..a08bacdb 100644 --- a/datacenterlight/urls.py +++ b/datacenterlight/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import url -from .views import IndexView, BetaProgramView, LandingProgramView, BetaAccessView, PricingView, SuccessView, PaymentOrderView, OrderConfirmationView, WhyDataCenterLightView +from .views import IndexView, BetaProgramView, LandingProgramView, BetaAccessView, PricingView, SuccessView, \ + PaymentOrderView, OrderConfirmationView, WhyDataCenterLightView urlpatterns = [ diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 51256053..ea7ca3ef 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -3,7 +3,7 @@ from django.http import HttpResponseRedirect from .forms import BetaAccessForm from .models import BetaAccess, BetaAccessVMType, BetaAccessVM from django.contrib import messages -from django.core.urlresolvers import reverse_lazy, reverse +from django.core.urlresolvers import reverse from django.core.mail import EmailMessage from utils.mailer import BaseEmail from django.shortcuts import render @@ -15,7 +15,6 @@ from django.conf import settings from django.utils.translation import ugettext_lazy as _ from utils.forms import BillingAddressForm, UserBillingAddressForm from utils.models import BillingAddress -from membership.models import StripeCustomer from hosting.models import HostingOrder, HostingBill from utils.stripe_utils import StripeUtils from datetime import datetime @@ -24,9 +23,11 @@ from membership.models import CustomUser, StripeCustomer from opennebula_api.models import OpenNebulaManager from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer + class LandingProgramView(TemplateView): template_name = "datacenterlight/landing.html" + class SuccessView(TemplateView): template_name = "datacenterlight/success.html" @@ -34,15 +35,17 @@ class SuccessView(TemplateView): if 'specs' not in request.session or 'user' not in request.session: return HttpResponseRedirect(reverse('datacenterlight:index')) elif 'token' not in request.session: - return HttpResponseRedirect(reverse('datacenterlight:payment')) + return HttpResponseRedirect(reverse('datacenterlight:payment')) elif 'order_confirmation' not in request.session: - return HttpResponseRedirect(reverse('datacenterlight:order_confirmation')) + return HttpResponseRedirect(reverse('datacenterlight:order_confirmation')) else: - for session_var in ['specs', 'user', 'template', 'billing_address', 'billing_address_data', 'token', 'customer']: + for session_var in ['specs', 'user', 'template', 'billing_address', 'billing_address_data', + 'token', 'customer']: if session_var in request.session: del request.session[session_var] return render(request, self.template_name) + class PricingView(TemplateView): template_name = "datacenterlight/pricing.html" @@ -55,17 +58,16 @@ class PricingView(TemplateView): 'templates': VirtualMachineTemplateSerializer(templates, many=True).data, } except: - messages.error( request, - 'We have a temporary problem to connect to our backend. \ - Please try again in a few minutes' - ) + messages.error(request, + 'We have a temporary problem to connect to our backend. \ + Please try again in a few minutes' + ) context = { - 'error' : 'connection' - } + 'error': 'connection' + } return render(request, self.template_name, context) - def post(self, request): cores = request.POST.get('cpu') @@ -74,7 +76,6 @@ class PricingView(TemplateView): price = request.POST.get('total') template_id = int(request.POST.get('config')) - manager = OpenNebulaManager() template = manager.get_template(template_id) @@ -84,7 +85,7 @@ class PricingView(TemplateView): request.session['next'] = reverse('hosting:payment') request.session['specs'] = { - 'cpu':cores, + 'cpu': cores, 'memory': memory, 'disk_size': storage, 'price': price, @@ -99,7 +100,6 @@ class BetaAccessView(FormView): success_message = "Thank you, we will contact you as soon as possible" def form_valid(self, form): - context = { 'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()) } @@ -134,6 +134,7 @@ class BetaAccessView(FormView): messages.add_message(self.request, messages.SUCCESS, self.success_message) return render(self.request, 'datacenterlight/beta_success.html', {}) + class BetaProgramView(CreateView): template_name = "datacenterlight/beta.html" model = BetaAccessVM @@ -185,13 +186,14 @@ class BetaProgramView(CreateView): messages.add_message(self.request, messages.SUCCESS, self.success_message) return HttpResponseRedirect(self.get_success_url()) + class IndexView(CreateView): template_name = "datacenterlight/index.html" model = BetaAccess form_class = BetaAccessForm success_url = "/datacenterlight#requestform" success_message = "Thank you, we will contact you as soon as possible" - + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): for session_var in ['specs', 'user', 'billing_address_data']: @@ -204,13 +206,13 @@ class IndexView(CreateView): 'templates': VirtualMachineTemplateSerializer(templates, many=True).data } except: - messages.error( request, - 'We have a temporary problem to connect to our backend. \ - Please try again in a few minutes' - ) + messages.error(request, + 'We have a temporary problem to connect to our backend. \ + Please try again in a few minutes' + ) context = { - 'error' : 'connection' - } + 'error': 'connection' + } return render(request, self.template_name, context) def post(self, request): @@ -222,7 +224,7 @@ class IndexView(CreateView): manager = OpenNebulaManager() template = manager.get_template(template_id) template_data = VirtualMachineTemplateSerializer(template).data - + name = request.POST.get('name') email = request.POST.get('email') name_field = forms.CharField() @@ -230,14 +232,14 @@ class IndexView(CreateView): try: name = name_field.clean(name) except ValidationError as err: - msg='{} {}.'.format(name, _('is not a proper name')) + msg = '{} {}.'.format(name, _('is not a proper name')) messages.add_message(self.request, messages.ERROR, msg, extra_tags='name') return HttpResponseRedirect(reverse('datacenterlight:index') + "#order_form") - try: + try: email = email_field.clean(email) except ValidationError as err: - msg='{} {}.'.format(email, _('is not a proper email')) + msg = '{} {}.'.format(email, _('is not a proper email')) messages.add_message(self.request, messages.ERROR, msg, extra_tags='email') return HttpResponseRedirect(reverse('datacenterlight:index') + "#order_form") @@ -247,12 +249,12 @@ class IndexView(CreateView): 'disk_size': storage, 'price': price } - + this_user = { 'name': name, 'email': email } - + request.session['specs'] = specs request.session['template'] = template_data request.session['user'] = this_user @@ -306,6 +308,7 @@ class IndexView(CreateView): messages.add_message(self.request, messages.SUCCESS, self.success_message) return super(IndexView, self).form_valid(form) + class WhyDataCenterLightView(IndexView): template_name = "datacenterlight/whydatacenterlight.html" model = BetaAccess @@ -319,19 +322,21 @@ class WhyDataCenterLightView(IndexView): 'templates': VirtualMachineTemplateSerializer(templates, many=True).data, } except: - messages.error( request, + messages.error( + request, 'We have a temporary problem to connect to our backend. \ Please try again in a few minutes' - ) + ) context = { - 'error' : 'connection' + 'error': 'connection' } - return render(request, self.template_name, context) + return render(request, self.template_name, context) + class PaymentOrderView(FormView): template_name = 'hosting/payment.html' form_class = BillingAddressForm - + def get_form_kwargs(self): form_kwargs = super(PaymentOrderView, self).get_form_kwargs() billing_address_data = self.request.session.get('billing_address_data') @@ -346,7 +351,6 @@ class PaymentOrderView(FormView): }) return form_kwargs - def get_context_data(self, **kwargs): context = super(PaymentOrderView, self).get_context_data(**kwargs) context.update({ @@ -368,16 +372,15 @@ class PaymentOrderView(FormView): billing_address_data = form.cleaned_data token = form.cleaned_data.get('token') user = request.session.get('user') - try: - custom_user = CustomUser.objects.get(email=user.get('email')) + CustomUser.objects.get(email=user.get('email')) except CustomUser.DoesNotExist: password = CustomUser.get_random_password() # Register the user, and do not send emails - CustomUser.register(user.get('name'), - password, - user.get('email'), - app='dcl', + CustomUser.register(user.get('name'), + password, + user.get('email'), + app='dcl', base_url=None, send_email=False) # Get or create stripe customer @@ -397,12 +400,13 @@ class PaymentOrderView(FormView): else: return self.form_invalid(form) + class OrderConfirmationView(DetailView): template_name = "datacenterlight/order_detail.html" payment_template_name = 'hosting/payment.html' context_object_name = "order" model = HostingOrder - + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): if 'specs' not in request.session or 'user' not in request.session: @@ -415,11 +419,11 @@ class OrderConfirmationView(DetailView): card_details = stripe_utils.get_card_details(customer.stripe_id, request.session.get('token')) context = { 'site_url': reverse('datacenterlight:index'), - 'cc_last4' : card_details.get('response_object').get('last4'), - 'cc_brand' : card_details.get('response_object').get('brand') + 'cc_last4': card_details.get('response_object').get('last4'), + 'cc_brand': card_details.get('response_object').get('brand') } return render(request, self.template_name, context) - + def post(self, request, *args, **kwargs): template = request.session.get('template') specs = request.session.get('specs') @@ -429,7 +433,6 @@ class OrderConfirmationView(DetailView): billing_address_data = request.session.get('billing_address_data') billing_address_id = request.session.get('billing_address') billing_address = BillingAddress.objects.filter(id=billing_address_id).first() - token = request.session.get('token') vm_template_id = template.get('id', 1) final_price = specs.get('price') @@ -441,29 +444,28 @@ class OrderConfirmationView(DetailView): # Check if the payment was approved if not charge: + context = {} context.update({ 'paymentError': charge_response.get('error') - # TODO add logic in payment form to autofill data - #'form': form }) return render(request, self.payment_template_name, context) charge = charge_response.get('response_object') - + # Create OpenNebulaManager manager = OpenNebulaManager(email=settings.OPENNEBULA_USERNAME, password=settings.OPENNEBULA_PASSWORD) - + # Create a vm using oneadmin, also specify the name vm_id = manager.create_vm( template_id=vm_template_id, specs=specs, vm_name="{email}-{template_name}-{date}".format( - email=user.get('email'), + email=user.get('email'), template_name=template.get('name'), date=int(datetime.now().strftime("%s"))) ) - + # Create a Hosting Order order = HostingOrder.create( price=final_price, @@ -471,9 +473,9 @@ class OrderConfirmationView(DetailView): customer=customer, billing_address=billing_address ) - + # Create a Hosting Bill - bill = HostingBill.create( + HostingBill.create( customer=customer, billing_address=billing_address) # Create Billing Address for User if he does not have one @@ -491,9 +493,9 @@ class OrderConfirmationView(DetailView): # If the Stripe payment was successed, set order status approved order.set_approved() - + vm = VirtualMachineSerializer(manager.get_vm(vm_id)).data - + context = { 'name': user.get('name'), 'email': user.get('email'), diff --git a/digitalglarus/admin.py b/digitalglarus/admin.py index 4f8bdcfa..c887e8d2 100644 --- a/digitalglarus/admin.py +++ b/digitalglarus/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Supporter, DGGallery, DGPicture, Booking, BookingPrice,\ +from .models import DGGallery, DGPicture, Booking, BookingPrice,\ MembershipOrder, Membership, MembershipType, BookingOrder, BookingCancellation from django.core.urlresolvers import reverse diff --git a/digitalglarus/cms_plugins.py b/digitalglarus/cms_plugins.py index e58dffb9..7c61bea6 100644 --- a/digitalglarus/cms_plugins.py +++ b/digitalglarus/cms_plugins.py @@ -1,9 +1,9 @@ from cms.plugin_base import CMSPluginBase from cms.plugin_pool import plugin_pool -from cms.wizards import wizard_base from .models import DGGalleryPlugin, DGSupportersPlugin, Supporter from django.utils.translation import ugettext as _ -# + + class CMSGalleryPlugin(CMSPluginBase): model = DGGalleryPlugin name = _("Digital Glarus Gallery") @@ -11,12 +11,13 @@ class CMSGalleryPlugin(CMSPluginBase): def render(self, context, instance, placeholder): context.update({ - 'gallery':instance.dgGallery, - 'object':instance, - 'placeholder':placeholder + 'gallery': instance.dgGallery, + 'object': instance, + 'placeholder': placeholder }) return context + class CMSSupportersPlugin(CMSPluginBase): name = _("Digital Glarus Supporters") model = DGSupportersPlugin @@ -26,11 +27,10 @@ class CMSSupportersPlugin(CMSPluginBase): context.update({ 'supporters': Supporter.objects.all().order_by('name'), 'object': instance, - 'placeholder':placeholder + 'placeholder': placeholder }) return context -# -# -# + + plugin_pool.register_plugin(CMSGalleryPlugin) plugin_pool.register_plugin(CMSSupportersPlugin) diff --git a/digitalglarus/forms.py b/digitalglarus/forms.py index 90a1024e..a0e685f8 100644 --- a/digitalglarus/forms.py +++ b/digitalglarus/forms.py @@ -1,7 +1,6 @@ from django import forms from django.db.models import Q from django.utils.translation import ugettext_lazy as _ -from datetime import datetime from utils.models import BillingAddress @@ -92,7 +91,7 @@ class CancelBookingForm(forms.ModelForm): class BookingDateForm(forms.Form): start_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'id': 'booking-date-1', - 'value': 'Select your date'})) + 'value': 'Select your date'})) end_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'id': 'booking-date-2'})) diff --git a/digitalglarus/management/commands/list.py b/digitalglarus/management/commands/list.py index e2d6b1b3..653966e8 100644 --- a/digitalglarus/management/commands/list.py +++ b/digitalglarus/management/commands/list.py @@ -3,6 +3,7 @@ from django.conf import settings import stripe stripe.api_key = settings.STRIPE_API_PRIVATE_KEY + class Command(BaseCommand): help = "Record payment plans for Digital Glarus on stripe" @@ -10,5 +11,3 @@ class Command(BaseCommand): print("Available plans:") for plan in stripe.Plan.all(): print(plan) - - diff --git a/digitalglarus/management/commands/plans.py b/digitalglarus/management/commands/plans.py index 2104cc1d..9e6dbc01 100644 --- a/digitalglarus/management/commands/plans.py +++ b/digitalglarus/management/commands/plans.py @@ -11,11 +11,11 @@ PAYMENT_PLANS = [ 'id': "spontaneus" }), ('committed', { - 'amount':36000, - 'interval':'year', - 'name':'The Committed', - 'currency':'chf', - 'id':'committed' + 'amount': 36000, + 'interval': 'year', + 'name': 'The Committed', + 'currency': 'chf', + 'id': 'committed' }) ] @@ -26,8 +26,6 @@ class Command(BaseCommand): def handle(self, *args, **options): for payment_plan, data in PAYMENT_PLANS: try: - res = stripe.Plan.create(**data) + stripe.Plan.create(**data) except stripe.InvalidRequestError as e: print(e) - - diff --git a/digitalglarus/models.py b/digitalglarus/models.py index 2e12e265..16d6b639 100644 --- a/digitalglarus/models.py +++ b/digitalglarus/models.py @@ -105,7 +105,7 @@ class Membership(models.Model): has_order_current_month = Q(membershiporder__customer__user=user, membershiporder__created_at__month=datetime.today().month) # has_order_past_month = Q(membershiporder__customer__user=user, - # membershiporder__created_at__month=past_month) + # membershiporder__created_at__month=past_month) active_membership = Q(active=True) # return cls.objects.filter(has_order_past_month | has_order_current_month).\ return cls.objects.filter(has_order_current_month).\ @@ -316,17 +316,20 @@ class DGGallery(models.Model): class Meta: verbose_name_plural = 'dgGallery' -# + + class DGPicture(models.Model): gallery = models.ForeignKey(DGGallery) - image = FilerImageField(related_name='dg_gallery') + image = FilerImageField(related_name='dg_gallery') description = models.CharField(max_length=60) def __str__(self): return "%s" % (self.image.name) + class DGGalleryPlugin(CMSPlugin): dgGallery = models.ForeignKey(DGGallery) + class DGSupportersPlugin(CMSPlugin): pass diff --git a/digitalglarus/test_views.py b/digitalglarus/test_views.py index 63b2cc06..f3e427ba 100644 --- a/digitalglarus/test_views.py +++ b/digitalglarus/test_views.py @@ -1,4 +1,3 @@ -import json from model_mommy import mommy from unittest import mock @@ -150,7 +149,7 @@ class MembershipPaymentViewTest(BaseTestCase): # self.assertTrue(HostingOrder.objects.filter(customer=stripe_customer).exists()) # hosting_order = HostingOrder.objects.filter(customer=stripe_customer)[0] # vm_plan = { - # 'cores': hosting_order.vm_plan.cores, + # 'cores': hosting_order.vm_plan.cores, # 'memory': hosting_order.vm_plan.memory, # 'disk_size': hosting_order.vm_plan.disk_size, # 'price': hosting_order.vm_plan.price, diff --git a/digitalglarus/views.py b/digitalglarus/views.py index a33775c9..87c1ccd2 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -720,7 +720,9 @@ class ContactView(FormView): messages.add_message(self.request, messages.SUCCESS, self.success_message) return super(ContactView, self).form_valid(form) -############## OLD VIEWS + +# OLD VIEWS + def blog(request): tags = ["digitalglarus"] @@ -751,6 +753,3 @@ def supporters(request): 'supporters': Supporter.objects.order_by('name') } return render(request, 'supporters.html', context) - - - diff --git a/dynamicweb/settings-test/__init__.py b/dynamicweb/settings-test/__init__.py index 22ef8531..1a8babdd 100644 --- a/dynamicweb/settings-test/__init__.py +++ b/dynamicweb/settings-test/__init__.py @@ -9,12 +9,15 @@ from django.utils.translation import ugettext_lazy as _ # dotenv import dotenv -gettext = lambda s: s + +def gettext(s): + return s def env(env_name): return os.environ.get(env_name) + BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_DIR = os.path.abspath( @@ -83,7 +86,7 @@ INSTALLED_APPS = ( 'django_select2', 'meta', 'meta_mixin', -# 'admin_enhancer', + # 'admin_enhancer', 'djangocms_blog', 'bootstrap3', 'compressor', @@ -433,5 +436,5 @@ MANAGERS = ADMINS ALLOWED_HOSTS = [ ".ungleich.ch", - "digital.glarus.ungleich.ch" , + "digital.glarus.ungleich.ch", ] diff --git a/dynamicweb/settings/__init__.py b/dynamicweb/settings/__init__.py index 9b5ed21c..8d236968 100644 --- a/dynamicweb/settings/__init__.py +++ b/dynamicweb/settings/__init__.py @@ -1 +1 @@ -from .base import * +from .base import * # flake8: noqa diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index ba304ff9..0df9031f 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -11,13 +11,20 @@ from django.utils.translation import ugettext_lazy as _ # dotenv import dotenv -gettext = lambda s: s + +def gettext(s): + return s def env(env_name): return os.environ.get(env_name) +def bool_env(val): + """Replaces string based environment values with Python booleans""" + return True if os.environ.get(val, False) == 'True' else False + + BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_DIR = os.path.abspath( @@ -465,19 +472,13 @@ STRIPE_DESCRIPTION_ON_PAYMENT = "Payment for ungleich GmbH services" # EMAIL MESSAGES REGISTRATION_MESSAGE = {'subject': "Validation mail", - 'message': 'Thank You for registering for account on Digital Glarus.\nPlease verify Your account under following link http://{host}/en-us/digitalglarus/login/validate/{slug}', + 'message': 'Thank You for registering for account on Digital Glarus.\n' + 'Please verify Your account under following link ' + 'http://{host}/en-us/digitalglarus/login/validate/{slug}', } STRIPE_API_PRIVATE_KEY = env('STRIPE_API_PRIVATE_KEY') STRIPE_API_PUBLIC_KEY = env('STRIPE_API_PUBLIC_KEY') -DEBUG = True - -if DEBUG: - from .local import * -else: - from .prod import * - - ANONYMOUS_USER_NAME = 'anonymous@ungleich.ch' GUARDIAN_GET_INIT_ANONYMOUS_USER = 'membership.models.get_anonymous_user_instance' @@ -521,3 +522,10 @@ GOOGLE_ANALYTICS_PROPERTY_IDS = { 'dynamicweb-development.ungleich.ch': 'development', 'dynamicweb-staging.ungleich.ch': 'staging' } + +DEBUG = bool_env('DEBUG') + +if DEBUG: + from .local import * # flake8: noqa +else: + from .prod import * # flake8: noqa diff --git a/dynamicweb/settings/local.py b/dynamicweb/settings/local.py index 799df594..1b03f3fe 100644 --- a/dynamicweb/settings/local.py +++ b/dynamicweb/settings/local.py @@ -1,5 +1,7 @@ -from .base import * -REGISTRATION_MESSAGE['message'] = REGISTRATION_MESSAGE['message'].format(host='dynamicweb-development.ungleich.ch',slug='{slug}') +from .base import * # flake8: noqa + +REGISTRATION_MESSAGE['message'] = REGISTRATION_MESSAGE['message'].format(host='dynamicweb-development.ungleich.ch', + slug='{slug}') ALLOWED_HOSTS = [ "*" ] @@ -13,9 +15,9 @@ CACHES = { } } -MIDDLEWARE_CLASSES+=("debug_toolbar.middleware.DebugToolbarMiddleware",) +MIDDLEWARE_CLASSES += ("debug_toolbar.middleware.DebugToolbarMiddleware",) -INSTALLED_APPS+=( +INSTALLED_APPS += ( 'django_extensions', 'debug_toolbar' ) diff --git a/dynamicweb/settings/prod.py b/dynamicweb/settings/prod.py index 4f96593f..a2eb69e0 100644 --- a/dynamicweb/settings/prod.py +++ b/dynamicweb/settings/prod.py @@ -1,15 +1,23 @@ -from .base import * +from .base import * # flake8: noqa # List of people that get admin messages -ADMINS = ( (x, x + "@ungleich.ch") for x in ["web-team"] ) +ADMINS = ((x, x + "@ungleich.ch") for x in ["web-team"]) -DEBUG=False +DEBUG = False EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -#MANAGERS = ADMINS +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', + 'LOCATION': '127.0.0.1:11211', + } +} -REGISTRATION_MESSAGE['message'] = REGISTRATION_MESSAGE['message'].format(host='digitalglarus.ungleich.ch',slug='{slug}') +# MANAGERS = ADMINS + +REGISTRATION_MESSAGE['message'] = REGISTRATION_MESSAGE['message'].format(host='digitalglarus.ungleich.ch', + slug='{slug}') # flake8: noqa ALLOWED_HOSTS = [ ".ungleich.ch", diff --git a/dynamicweb/urls.py b/dynamicweb/urls.py index 0b1a0844..66bf74df 100644 --- a/dynamicweb/urls.py +++ b/dynamicweb/urls.py @@ -12,42 +12,42 @@ from django.views.generic import RedirectView from django.core.urlresolvers import reverse_lazy import debug_toolbar -urlpatterns = [ url(r'^index.html$', LandingView.as_view()), - url(r'^hosting/', include('hosting.urls', namespace="hosting")), - url(r'^open_api/', include('opennebula_api.urls', - namespace='opennebula_api')), - url(r'^railshosting/', RailsHostingView.as_view(), name="rails.hosting"), - url(r'^nodehosting/', NodeJSHostingView.as_view(), name="node.hosting"), - url(r'^djangohosting/', DjangoHostingView.as_view(), name="django.hosting"), - url(r'^nosystemd/', include('nosystemd.urls', namespace="nosystemd")), - url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')), - url(r'^jsi18n/(?P\S+?)/$', - 'django.views.i18n.javascript_catalog'), - ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +urlpatterns = [url(r'^index.html$', LandingView.as_view()), + url(r'^hosting/', include('hosting.urls', namespace="hosting")), + url(r'^open_api/', include('opennebula_api.urls', + namespace='opennebula_api')), + url(r'^railshosting/', RailsHostingView.as_view(), name="rails.hosting"), + url(r'^nodehosting/', NodeJSHostingView.as_view(), name="node.hosting"), + url(r'^djangohosting/', DjangoHostingView.as_view(), name="django.hosting"), + url(r'^nosystemd/', include('nosystemd.urls', namespace="nosystemd")), + url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')), + url(r'^jsi18n/(?P\S+?)/$', + 'django.views.i18n.javascript_catalog'), + ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # note the django CMS URLs included via i18n_patterns urlpatterns += i18n_patterns('', url(r'^/?$', LandingView.as_view()), url(r'^admin/', include(admin.site.urls)), url(r'^datacenterlight', include('datacenterlight.urls', namespace="datacenterlight")), - url(r'^hosting/', RedirectView.as_view(url=reverse_lazy('hosting:login')), name='redirect_hosting_login'), + url(r'^hosting/', RedirectView.as_view( + url=reverse_lazy('hosting:login')), name='redirect_hosting_login'), url(r'^alplora', include('alplora.urls', namespace="alplora")), url(r'^membership/', include(membership_urls)), url(r'^digitalglarus/', include('digitalglarus.urls', namespace="digitalglarus")), - #url(r'^blog/', include('ungleich.urls', namespace='ungleich')), + # url(r'^blog/', include('ungleich.urls', namespace='ungleich')), url(r'^', include('ungleich_page.urls', namespace='ungleich_page'), name='ungleich_page'), url(r'^blog/', include('ungleich.urls', namespace='ungleich')), url(r'^', include('cms.urls')) ) - +urlpatterns += patterns('', + url(r'^media/(?P.*)$', + 'django.views.static.serve', { + 'document_root': settings.MEDIA_ROOT, + }), + ) if settings.DEBUG: - urlpatterns += patterns('', - url(r'^media/(?P.*)$', - 'django.views.static.serve', { - 'document_root': settings.MEDIA_ROOT, - }), - ) - urlpatterns += patterns('',url(r'^__debug__/', include(debug_toolbar.urls))) + urlpatterns += patterns('', url(r'^__debug__/', include(debug_toolbar.urls))) diff --git a/dynamicweb/wsgi.py b/dynamicweb/wsgi.py index 69d05eb9..8b8d9981 100644 --- a/dynamicweb/wsgi.py +++ b/dynamicweb/wsgi.py @@ -7,13 +7,13 @@ For more information on this file, see https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ """ -import os,sys -#sys.path.append(os.path.dirname(__file__)) +import os +import sys +from django.core.wsgi import get_wsgi_application + +# sys.path.append(os.path.dirname(__file__)) sys.path.append('/home/app/pyvenv/lib/python3.4/site-packages/') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dynamicweb.settings.prod") -from django.core.wsgi import get_wsgi_application - - application = get_wsgi_application() diff --git a/hosting/admin.py b/hosting/admin.py index c38fa8d0..6ebe461d 100644 --- a/hosting/admin.py +++ b/hosting/admin.py @@ -1,8 +1,4 @@ from django.contrib import admin -from django.utils.html import format_html -from django.core.urlresolvers import reverse - -from utils.mailer import BaseEmail from .models import HostingOrder, HostingBill, HostingPlan diff --git a/hosting/forms.py b/hosting/forms.py index d9a3b985..505ecbce 100644 --- a/hosting/forms.py +++ b/hosting/forms.py @@ -1,14 +1,11 @@ -import random -import string from django import forms from membership.models import CustomUser from django.contrib.auth import authenticate from django.utils.translation import ugettext_lazy as _ -from utils.stripe_utils import StripeUtils +from .models import UserHostingKey -from .models import HostingOrder, UserHostingKey class HostingUserLoginForm(forms.Form): @@ -62,9 +59,9 @@ class HostingUserSignupForm(forms.ModelForm): class UserHostingKeyForm(forms.ModelForm): private_key = forms.CharField(widget=forms.HiddenInput(), required=False) public_key = forms.CharField(widget=forms.Textarea(), required=False, - help_text=_('Paste here your public key')) + help_text=_('Paste here your public key')) user = forms.models.ModelChoiceField(queryset=CustomUser.objects.all(), - required=False, widget=forms.HiddenInput()) + required=False, widget=forms.HiddenInput()) name = forms.CharField(required=True) def __init__(self, *args, **kwargs): diff --git a/hosting/management/commands/create_vm_types.py b/hosting/management/commands/create_vm_types.py index f92cc3a1..0b5f8df5 100644 --- a/hosting/management/commands/create_vm_types.py +++ b/hosting/management/commands/create_vm_types.py @@ -1,4 +1,4 @@ -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from hosting.models import VirtualMachineType @@ -55,15 +55,15 @@ class Command(BaseCommand): }, ] - - hetzner = { - 'base_price': 10, - 'core_price': 5, - 'memory_price': 2, - 'disk_size_price': 0.6, - 'description': 'VM auf einzelner HW, Raid1, kein HA', - 'location': 'DE' - } + # not used + # hetzner = { + # 'base_price': 10, + # 'core_price': 5, + # 'memory_price': 2, + # 'disk_size_price': 0.6, + # 'description': 'VM auf einzelner HW, Raid1, kein HA', + # 'location': 'DE' + # } # return { # # 'hetzner_nug': { diff --git a/hosting/models.py b/hosting/models.py index 25f852f1..bb53589d 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -1,22 +1,16 @@ import os -import socket import logging -import oca from django.db import models -from django.utils.translation import ugettext_lazy as _ from django.utils.functional import cached_property -from django.conf import settings from Crypto.PublicKey import RSA -from stored_messages.settings import stored_messages_settings from membership.models import StripeCustomer, CustomUser from utils.models import BillingAddress from utils.mixins import AssignPermissionsMixin -from .managers import VMPlansManager logger = logging.getLogger(__name__) @@ -29,7 +23,7 @@ class HostingPlan(models.Model): def serialize(self): return { 'id': self.id, - 'cpu':self.cpu_cores, + 'cpu': self.cpu_cores, 'memory': self.memory, 'disk_size': self.disk_size, 'price': self.price(), @@ -46,6 +40,7 @@ class HostingPlan(models.Model): price += self.memory * 2 return price + class HostingOrder(AssignPermissionsMixin, models.Model): ORDER_APPROVED_STATUS = 'Approved' @@ -128,6 +123,7 @@ class UserHostingKey(models.Model): # self.save(update_fields=['public_key']) return private_key, public_key + class HostingBill(AssignPermissionsMixin, models.Model): customer = models.ForeignKey(StripeCustomer) billing_address = models.ForeignKey(BillingAddress) @@ -147,4 +143,3 @@ class HostingBill(AssignPermissionsMixin, models.Model): def create(cls, customer=None, billing_address=None): instance = cls.objects.create(customer=customer, billing_address=billing_address) return instance - diff --git a/hosting/templates/hosting/payment.html b/hosting/templates/hosting/payment.html index 8bde4d47..b6550925 100644 --- a/hosting/templates/hosting/payment.html +++ b/hosting/templates/hosting/payment.html @@ -64,21 +64,30 @@
Type: {{credit_card_data.cc_brand}}
-
- -
+ + + + {% else %}
-
-
- -
-
+
+
+ +
+
@@ -118,14 +127,13 @@

-

{% trans "You are not making any payment yet. After placing your order, you will be taken to the Submit Payment Page." %}

+

{% trans "You are not making any payment yet. After placing your order, you will be taken to the Submit Payment Page." %}

-
+
-