diff --git a/hosting/templates/hosting/settings.html b/hosting/templates/hosting/settings.html
new file mode 100644
index 00000000..0bafe8e5
--- /dev/null
+++ b/hosting/templates/hosting/settings.html
@@ -0,0 +1,149 @@
+{% extends "hosting/base_short.html" %}
+{% load staticfiles bootstrap3 i18n %}
+
+{% block css_extra %}
+
+
+ {% comment %}
+
+ {% if stripe_key %}
+ {% get_current_language as LANGUAGE_CODE %}
+
+ {%endif%}
+
+ {% if credit_card_data.last4 and credit_card_data.cc_brand %}
+
+ {%endif%}
+ {% endcomment %}
+{%endblock%}
diff --git a/hosting/templates/hosting/signup_validate.html b/hosting/templates/hosting/signup_validate.html
index 3ccbe15b..449064dc 100644
--- a/hosting/templates/hosting/signup_validate.html
+++ b/hosting/templates/hosting/signup_validate.html
@@ -1,6 +1,10 @@
{% extends "hosting/base_short.html" %}
{% load staticfiles bootstrap3 i18n %}
+{% block navbar %}
+ {% include 'hosting/includes/_navbar_transparent.html' %}
+{% endblock navbar %}
+
{% block content %}
diff --git a/hosting/urls.py b/hosting/urls.py
index e6b6fee3..455aa97f 100644
--- a/hosting/urls.py
+++ b/hosting/urls.py
@@ -1,6 +1,5 @@
from django.conf.urls import url
from django.contrib.auth import views as auth_views
-
from .views import (
DjangoHostingView, RailsHostingView, PaymentVMView, NodeJSHostingView,
LoginView, SignupView, SignupValidateView, SignupValidatedView, IndexView,
@@ -9,7 +8,8 @@ from .views import (
MarkAsReadNotificationView, PasswordResetView, PasswordResetConfirmView,
HostingPricingView, CreateVirtualMachinesView, HostingBillListView,
HostingBillDetailView, SSHKeyDeleteView, SSHKeyCreateView, SSHKeyListView,
- SSHKeyChoiceView, DashboardView)
+ SSHKeyChoiceView, DashboardView, SettingsView)
+
urlpatterns = [
url(r'index/?$', IndexView.as_view(), name='index'),
@@ -19,6 +19,7 @@ urlpatterns = [
url(r'rails/?$', RailsHostingView.as_view(), name='railshosting'),
url(r'pricing/?$', HostingPricingView.as_view(), name='pricing'),
url(r'payment/?$', PaymentVMView.as_view(), name='payment'),
+ url(r'settings/?$', SettingsView.as_view(), name='settings'),
url(r'orders/?$', OrdersHostingListView.as_view(), name='orders'),
url(r'orders/(?P
\d+)/?$', OrdersHostingDetailView.as_view(), name='orders'),
url(r'bills/?$', HostingBillListView.as_view(), name='bills'),
diff --git a/hosting/views.py b/hosting/views.py
index 08f0862e..e38d2bac 100644
--- a/hosting/views.py
+++ b/hosting/views.py
@@ -190,7 +190,7 @@ class IndexView(View):
class LoginView(LoginViewMixin):
template_name = "hosting/login.html"
form_class = HostingUserLoginForm
- success_url = reverse_lazy('hosting:virtual_machines')
+ success_url = reverse_lazy('hosting:dashboard')
class SignupView(CreateView):
@@ -487,6 +487,57 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView):
return self.form_invalid(form)
+class SettingsView(LoginRequiredMixin, FormView):
+ template_name = "hosting/settings.html"
+ login_url = reverse_lazy('hosting:login')
+ form_class = BillingAddressForm
+
+ def get_form(self, form_class):
+ """
+ Check if the user already saved contact details. If so, then show
+ the form populated with those details, to let user change them.
+ """
+ return form_class(
+ instance=self.request.user.billing_addresses.first(),
+ **self.get_form_kwargs())
+
+ def get_context_data(self, **kwargs):
+ context = super(SettingsView, self).get_context_data(**kwargs)
+ # Get user
+ user = self.request.user
+ # Get user last order
+ last_hosting_order = HostingOrder.objects.filter(
+ customer__user=user).last()
+ # If user has already an hosting order, get the credit card data from
+ # it
+ if last_hosting_order:
+ credit_card_data = last_hosting_order.get_cc_data()
+ context.update({
+ 'credit_card_data': credit_card_data if credit_card_data else None,
+ })
+ context.update({
+ 'stripe_key': settings.STRIPE_API_PUBLIC_KEY
+ })
+
+ return context
+
+ def post(self, request, *args, **kwargs):
+ form = self.get_form()
+ if form.is_valid():
+ billing_address_data = form.cleaned_data
+ billing_address_data.update({
+ 'user': self.request.user.id
+ })
+ billing_address_user_form = UserBillingAddressForm(
+ instance=self.request.user.billing_addresses.first(),
+ data=billing_address_data)
+ billing_address_user_form.save()
+ return self.render_to_response(self.get_context_data())
+ else:
+ billing_address_data = form.cleaned_data
+ return self.form_invalid(form)
+
+
class PaymentVMView(LoginRequiredMixin, FormView):
template_name = 'hosting/payment.html'
login_url = reverse_lazy('hosting:login')
diff --git a/utils/forms.py b/utils/forms.py
index c521e3ba..c3f3b6db 100644
--- a/utils/forms.py
+++ b/utils/forms.py
@@ -41,7 +41,8 @@ class LoginFormMixin(forms.Form):
password = self.cleaned_data.get('password')
is_auth = authenticate(email=email, password=password)
if not is_auth:
- raise forms.ValidationError("Your username and/or password were incorrect.")
+ raise forms.ValidationError(
+ "Your username and/or password were incorrect.")
return self.cleaned_data
def clean_email(self):
@@ -101,7 +102,8 @@ class BillingAddressForm(forms.ModelForm):
class Meta:
model = BillingAddress
- fields = ['cardholder_name', 'street_address', 'city', 'postal_code', 'country']
+ fields = ['cardholder_name', 'street_address',
+ 'city', 'postal_code', 'country']
labels = {
'cardholder_name': _('Cardholder Name'),
'street_address': _('Street Address'),
@@ -117,8 +119,10 @@ class UserBillingAddressForm(forms.ModelForm):
class Meta:
model = UserBillingAddress
- fields = ['street_address', 'city', 'postal_code', 'country', 'user']
+ fields = ['cardholder_name', 'street_address',
+ 'city', 'postal_code', 'country', 'user']
labels = {
+ 'cardholder_name': _('Cardholder Name'),
'street_address': _('Street Building'),
'city': _('City'),
'postal_code': _('Postal Code'),
@@ -146,8 +150,10 @@ class ContactUsForm(forms.ModelForm):
}
def send_email(self, email_to='info@digitalglarus.ch'):
- text_content = render_to_string('emails/contact.txt', {'data': self.cleaned_data})
- html_content = render_to_string('emails/contact.html', {'data': self.cleaned_data})
+ text_content = render_to_string(
+ 'emails/contact.txt', {'data': self.cleaned_data})
+ html_content = render_to_string(
+ 'emails/contact.html', {'data': self.cleaned_data})
email = EmailMultiAlternatives('Subject', text_content)
email.attach_alternative(html_content, "text/html")
email.to = [email_to]