From dd54b3052e284edc698f2161216da1e90be71a48 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2017 15:07:12 +0100 Subject: [PATCH 01/13] Reorganize imports --- hosting/views.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 576b3534..25d89b64 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -12,13 +12,13 @@ from django.contrib.auth.tokens import default_token_generator from django.core.exceptions import ValidationError from django.core.files.base import ContentFile from django.core.urlresolvers import reverse_lazy, reverse - from django.http import Http404, HttpResponseRedirect, HttpResponse from django.shortcuts import redirect, render from django.utils.http import urlsafe_base64_decode from django.utils.safestring import mark_safe from django.utils.translation import get_language, ugettext_lazy as _ from django.utils.translation import ugettext +from django.views.decorators.cache import cache_control from django.views.generic import ( View, CreateView, FormView, ListView, DetailView, DeleteView, TemplateView, UpdateView @@ -29,11 +29,14 @@ 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.tasks import create_vm_task from membership.models import CustomUser, StripeCustomer from opennebula_api.models import OpenNebulaManager -from opennebula_api.serializers import VirtualMachineSerializer, \ - VirtualMachineTemplateSerializer, VMTemplateSerializer +from opennebula_api.serializers import ( + VirtualMachineSerializer, VirtualMachineTemplateSerializer, + VMTemplateSerializer +) from utils.forms import ( BillingAddressForm, PasswordResetRequestForm, UserBillingAddressForm, ResendActivationEmailForm @@ -46,13 +49,14 @@ from utils.views import ( PasswordResetViewMixin, PasswordResetConfirmViewMixin, LoginViewMixin, ResendActivationLinkViewMixin ) -from .forms import HostingUserSignupForm, HostingUserLoginForm, \ - UserHostingKeyForm, generate_ssh_key_name +from .forms import ( + HostingUserSignupForm, HostingUserLoginForm, UserHostingKeyForm, + generate_ssh_key_name +) from .mixins import ProcessVMSelectionMixin from .models import ( HostingOrder, HostingBill, HostingPlan, UserHostingKey, VMDetail ) -from datacenterlight.models import VMTemplate logger = logging.getLogger(__name__) From b4f03b95531dce6772eac684ed29fb66693b9457 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2017 15:10:34 +0100 Subject: [PATCH 02/13] Add cache_control decorator to all hosting views --- hosting/views.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 25d89b64..a6922a70 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -65,6 +65,7 @@ CONNECTION_ERROR = "Your VMs cannot be displayed at the moment due to a \ minutes." +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class DashboardView(LoginRequiredMixin, View): template_name = "hosting/dashboard.html" login_url = reverse_lazy('hosting:login') @@ -186,6 +187,7 @@ class HostingPricingView(ProcessVMSelectionMixin, View): return render(request, self.template_name, context) +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class IndexView(View): template_name = "hosting/index.html" @@ -210,6 +212,7 @@ class IndexView(View): return render(request, self.template_name, context) +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class LoginView(LoginViewMixin): template_name = "hosting/login.html" form_class = HostingUserLoginForm @@ -310,6 +313,7 @@ class SignupValidatedView(SignupValidateView): return context +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class ResendActivationEmailView(ResendActivationLinkViewMixin): template_name = 'hosting/resend_activation_link.html' form_class = ResendActivationEmailForm @@ -318,6 +322,7 @@ class ResendActivationEmailView(ResendActivationLinkViewMixin): email_template_name = 'user_activation' +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class PasswordResetView(PasswordResetViewMixin): site = 'dcl' template_name = 'hosting/reset_password.html' @@ -326,6 +331,7 @@ class PasswordResetView(PasswordResetViewMixin): template_email_path = 'hosting/emails/' +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class PasswordResetConfirmView(PasswordResetConfirmViewMixin): template_name = 'hosting/confirm_reset_password.html' success_url = reverse_lazy('hosting:login') @@ -402,6 +408,7 @@ class MarkAsReadNotificationView(LoginRequiredMixin, UpdateView): return HttpResponseRedirect(reverse('hosting:notifications')) +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SSHKeyDeleteView(LoginRequiredMixin, DeleteView): login_url = reverse_lazy('hosting:login') success_url = reverse_lazy('hosting:ssh_keys') @@ -430,6 +437,7 @@ class SSHKeyDeleteView(LoginRequiredMixin, DeleteView): return super(SSHKeyDeleteView, self).delete(request, *args, **kwargs) +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SSHKeyListView(LoginRequiredMixin, ListView): template_name = "hosting/user_keys.html" login_url = reverse_lazy('hosting:login') @@ -450,6 +458,7 @@ class SSHKeyListView(LoginRequiredMixin, ListView): **response_kwargs) +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SSHKeyChoiceView(LoginRequiredMixin, View): template_name = "hosting/choice_ssh_keys.html" login_url = reverse_lazy('hosting:login') @@ -476,6 +485,7 @@ class SSHKeyChoiceView(LoginRequiredMixin, View): return redirect(reverse_lazy('hosting:ssh_keys'), foo='bar') +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SSHKeyCreateView(LoginRequiredMixin, FormView): form_class = UserHostingKeyForm model = UserHostingKey @@ -538,6 +548,7 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView): return self.form_invalid(form) +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SettingsView(LoginRequiredMixin, FormView): template_name = "hosting/settings.html" login_url = reverse_lazy('hosting:login') @@ -589,6 +600,7 @@ class SettingsView(LoginRequiredMixin, FormView): return self.form_invalid(form) +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class PaymentVMView(LoginRequiredMixin, FormView): template_name = 'hosting/payment.html' login_url = reverse_lazy('hosting:login') @@ -667,8 +679,8 @@ class PaymentVMView(LoginRequiredMixin, FormView): return self.form_invalid(form) -class OrdersHostingDetailView(LoginRequiredMixin, - DetailView): +@cache_control(no_cache=True, must_revalidate=True, no_store=True) +class OrdersHostingDetailView(LoginRequiredMixin, DetailView): template_name = "hosting/order_detail.html" context_object_name = "order" login_url = reverse_lazy('hosting:login') @@ -881,6 +893,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, content_type="application/json") +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class OrdersHostingListView(LoginRequiredMixin, ListView): template_name = "hosting/orders.html" login_url = reverse_lazy('hosting:login') @@ -895,6 +908,7 @@ class OrdersHostingListView(LoginRequiredMixin, ListView): return super(OrdersHostingListView, self).get_queryset() +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class OrdersHostingDeleteView(LoginRequiredMixin, DeleteView): login_url = reverse_lazy('hosting:login') success_url = reverse_lazy('hosting:orders') @@ -939,6 +953,7 @@ class VirtualMachinesPlanListView(LoginRequiredMixin, ListView): return context +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class CreateVirtualMachinesView(LoginRequiredMixin, View): template_name = "hosting/create_virtual_machine.html" login_url = reverse_lazy('hosting:login') @@ -1011,6 +1026,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): return redirect(reverse('hosting:payment')) +@cache_control(no_cache=True, must_revalidate=True, no_store=True) class VirtualMachineView(LoginRequiredMixin, View): template_name = "hosting/virtual_machine_detail.html" login_url = reverse_lazy('hosting:login') From f357c83fc4c7edef344d8f1c9a79ddf1ca00bc69 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2017 15:53:24 +0100 Subject: [PATCH 03/13] Remove cache_control headers from Classes --- hosting/views.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index a6922a70..3a596394 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -65,7 +65,6 @@ CONNECTION_ERROR = "Your VMs cannot be displayed at the moment due to a \ minutes." -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class DashboardView(LoginRequiredMixin, View): template_name = "hosting/dashboard.html" login_url = reverse_lazy('hosting:login') @@ -187,7 +186,6 @@ class HostingPricingView(ProcessVMSelectionMixin, View): return render(request, self.template_name, context) -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class IndexView(View): template_name = "hosting/index.html" @@ -212,7 +210,6 @@ class IndexView(View): return render(request, self.template_name, context) -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class LoginView(LoginViewMixin): template_name = "hosting/login.html" form_class = HostingUserLoginForm @@ -313,7 +310,6 @@ class SignupValidatedView(SignupValidateView): return context -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class ResendActivationEmailView(ResendActivationLinkViewMixin): template_name = 'hosting/resend_activation_link.html' form_class = ResendActivationEmailForm @@ -322,7 +318,6 @@ class ResendActivationEmailView(ResendActivationLinkViewMixin): email_template_name = 'user_activation' -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class PasswordResetView(PasswordResetViewMixin): site = 'dcl' template_name = 'hosting/reset_password.html' @@ -331,7 +326,6 @@ class PasswordResetView(PasswordResetViewMixin): template_email_path = 'hosting/emails/' -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class PasswordResetConfirmView(PasswordResetConfirmViewMixin): template_name = 'hosting/confirm_reset_password.html' success_url = reverse_lazy('hosting:login') @@ -408,7 +402,6 @@ class MarkAsReadNotificationView(LoginRequiredMixin, UpdateView): return HttpResponseRedirect(reverse('hosting:notifications')) -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SSHKeyDeleteView(LoginRequiredMixin, DeleteView): login_url = reverse_lazy('hosting:login') success_url = reverse_lazy('hosting:ssh_keys') @@ -437,7 +430,6 @@ class SSHKeyDeleteView(LoginRequiredMixin, DeleteView): return super(SSHKeyDeleteView, self).delete(request, *args, **kwargs) -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SSHKeyListView(LoginRequiredMixin, ListView): template_name = "hosting/user_keys.html" login_url = reverse_lazy('hosting:login') @@ -458,7 +450,6 @@ class SSHKeyListView(LoginRequiredMixin, ListView): **response_kwargs) -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SSHKeyChoiceView(LoginRequiredMixin, View): template_name = "hosting/choice_ssh_keys.html" login_url = reverse_lazy('hosting:login') @@ -485,7 +476,6 @@ class SSHKeyChoiceView(LoginRequiredMixin, View): return redirect(reverse_lazy('hosting:ssh_keys'), foo='bar') -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SSHKeyCreateView(LoginRequiredMixin, FormView): form_class = UserHostingKeyForm model = UserHostingKey @@ -548,7 +538,6 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView): return self.form_invalid(form) -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class SettingsView(LoginRequiredMixin, FormView): template_name = "hosting/settings.html" login_url = reverse_lazy('hosting:login') @@ -600,7 +589,6 @@ class SettingsView(LoginRequiredMixin, FormView): return self.form_invalid(form) -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class PaymentVMView(LoginRequiredMixin, FormView): template_name = 'hosting/payment.html' login_url = reverse_lazy('hosting:login') @@ -679,7 +667,6 @@ class PaymentVMView(LoginRequiredMixin, FormView): return self.form_invalid(form) -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class OrdersHostingDetailView(LoginRequiredMixin, DetailView): template_name = "hosting/order_detail.html" context_object_name = "order" @@ -893,7 +880,6 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): content_type="application/json") -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class OrdersHostingListView(LoginRequiredMixin, ListView): template_name = "hosting/orders.html" login_url = reverse_lazy('hosting:login') @@ -908,7 +894,6 @@ class OrdersHostingListView(LoginRequiredMixin, ListView): return super(OrdersHostingListView, self).get_queryset() -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class OrdersHostingDeleteView(LoginRequiredMixin, DeleteView): login_url = reverse_lazy('hosting:login') success_url = reverse_lazy('hosting:orders') @@ -953,7 +938,6 @@ class VirtualMachinesPlanListView(LoginRequiredMixin, ListView): return context -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class CreateVirtualMachinesView(LoginRequiredMixin, View): template_name = "hosting/create_virtual_machine.html" login_url = reverse_lazy('hosting:login') @@ -1026,7 +1010,6 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): return redirect(reverse('hosting:payment')) -@cache_control(no_cache=True, must_revalidate=True, no_store=True) class VirtualMachineView(LoginRequiredMixin, View): template_name = "hosting/virtual_machine_detail.html" login_url = reverse_lazy('hosting:login') From d796272c1053f644758bab7eb3a6b0f48bb90734 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 25 Dec 2017 15:54:23 +0100 Subject: [PATCH 04/13] Add cache_control headers to get and post methods --- hosting/views.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hosting/views.py b/hosting/views.py index 3a596394..879fc3e7 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -73,6 +73,7 @@ class DashboardView(LoginRequiredMixin, View): context = {} return context + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): context = self.get_context_data() return render(request, self.template_name, context) @@ -204,9 +205,9 @@ class IndexView(View): } return context + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): context = self.get_context_data() - return render(request, self.template_name, context) @@ -443,6 +444,7 @@ class SSHKeyListView(LoginRequiredMixin, ListView): self.queryset = UserHostingKey.objects.filter(user=user) return super(SSHKeyListView, self).get_queryset() + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def render_to_response(self, context, **response_kwargs): if not self.queryset: return HttpResponseRedirect(reverse('hosting:choice_ssh_keys')) @@ -454,10 +456,12 @@ class SSHKeyChoiceView(LoginRequiredMixin, View): template_name = "hosting/choice_ssh_keys.html" login_url = reverse_lazy('hosting:login') + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): context = {} return render(request, self.template_name, context) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def post(self, request, *args, **kwargs): name = generate_ssh_key_name() private_key, public_key = UserHostingKey.generate_keys() @@ -527,6 +531,10 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView): manager.manage_public_key([{'value': public_key, 'state': True}]) return HttpResponseRedirect(self.success_url) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) + def get(self, request, *args, **kwargs): + return render(request, self.template_name) + def post(self, request, *args, **kwargs): form = self.get_form() required = 'add_ssh' in self.request.POST @@ -572,6 +580,10 @@ class SettingsView(LoginRequiredMixin, FormView): return context + @cache_control(no_cache=True, must_revalidate=True, no_store=True) + def get(self, request, *args, **kwargs): + return render(request, self.template_name) + def post(self, request, *args, **kwargs): form = self.get_form() if form.is_valid(): @@ -1045,6 +1057,7 @@ class VirtualMachineView(LoginRequiredMixin, View): final_url = reverse('hosting:virtual_machines') return final_url + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): vm = self.get_object() if vm is None: From 72baa3635bad0f94712f284d9b4abb3a7bb8b3ec Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2017 08:31:19 +0100 Subject: [PATCH 05/13] Add cache_control decorator to LoginViewMixin --- utils/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/views.py b/utils/views.py index 6e54cde6..394a9fc2 100644 --- a/utils/views.py +++ b/utils/views.py @@ -8,6 +8,7 @@ from django.utils.encoding import force_bytes from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode from django.utils.translation import ugettext_lazy as _ from django.views.generic import FormView, CreateView +from django.views.decorators.cache import cache_control from membership.models import CustomUser from .forms import SetPasswordForm @@ -57,6 +58,7 @@ class LoginViewMixin(FormView): return HttpResponseRedirect(self.get_success_url()) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): if self.request.user.is_authenticated(): return HttpResponseRedirect(self.get_success_url()) From 87cdb08f3c94a70e100f41d879490c01e90feac1 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2017 08:32:55 +0100 Subject: [PATCH 06/13] Change success_url in hosting.SignupView from ssh_keys to dashboard --- hosting/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/views.py b/hosting/views.py index 879fc3e7..02e30808 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -221,7 +221,7 @@ class SignupView(CreateView): template_name = 'hosting/signup.html' form_class = HostingUserSignupForm model = CustomUser - success_url = reverse_lazy('hosting:ssh_keys') + success_url = reverse_lazy('hosting:dashboard') def get_success_url(self): next_url = self.request.session.get( From bec541c06a4b574d7ccc6b53d44e2f65e3570a18 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2017 08:33:53 +0100 Subject: [PATCH 07/13] Add get method to hosting.SignupView and cache_control --- hosting/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hosting/views.py b/hosting/views.py index 02e30808..7d60d7b4 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -239,6 +239,12 @@ class SignupView(CreateView): return HttpResponseRedirect(reverse_lazy('hosting:signup-validate')) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) + def get(self, request, *args, **kwargs): + if self.request.user.is_authenticated(): + return HttpResponseRedirect(self.get_success_url()) + return super(SignupView, self).get(request, *args, **kwargs) + class SignupValidateView(TemplateView): template_name = "hosting/signup_validate.html" From 98e06686f9a556614301a5605de12be4b100a7f7 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2017 09:03:17 +0100 Subject: [PATCH 08/13] Add get method and cache_control to SignupValidatedView --- hosting/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hosting/views.py b/hosting/views.py index 7d60d7b4..76be4a67 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -316,6 +316,12 @@ class SignupValidatedView(SignupValidateView): context['section_title'] = section_title return context + @cache_control(no_cache=True, must_revalidate=True, no_store=True) + def get(self, request, *args, **kwargs): + if self.request.user.is_authenticated(): + return HttpResponseRedirect(reverse_lazy('hosting:dashboard')) + return super(SignupValidatedView, self).get(request, *args, **kwargs) + class ResendActivationEmailView(ResendActivationLinkViewMixin): template_name = 'hosting/resend_activation_link.html' From ab06eeff674ce7b59609957619eadf5a0e22fff7 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2017 09:04:58 +0100 Subject: [PATCH 09/13] Add cache_control to SSHKEyCreateView and SettingsView post methods --- hosting/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hosting/views.py b/hosting/views.py index 76be4a67..0b258536 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -547,6 +547,7 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView): def get(self, request, *args, **kwargs): return render(request, self.template_name) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def post(self, request, *args, **kwargs): form = self.get_form() required = 'add_ssh' in self.request.POST @@ -596,6 +597,7 @@ class SettingsView(LoginRequiredMixin, FormView): def get(self, request, *args, **kwargs): return render(request, self.template_name) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def post(self, request, *args, **kwargs): form = self.get_form() if form.is_valid(): From 14ff876fbf9c984ce54a22ed1d913bb43441b993 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2017 09:06:46 +0100 Subject: [PATCH 10/13] Add cache_control to PaymentVMView and OrdersHostingDetailView --- hosting/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hosting/views.py b/hosting/views.py index 0b258536..26adb834 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -660,11 +660,13 @@ class PaymentVMView(LoginRequiredMixin, FormView): return context + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): if 'next' in request.session: del request.session['next'] return self.render_to_response(self.get_context_data()) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def post(self, request, *args, **kwargs): form = self.get_form() if form.is_valid(): @@ -792,6 +794,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): context['vm'] = self.request.session.get('specs') return context + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): if not self.kwargs.get('pk'): if 'specs' not in self.request.session: @@ -813,6 +816,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): ) return self.render_to_response(context) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def post(self, request): template = request.session.get('template') specs = request.session.get('specs') From 639e4cf414aaddd374e51286f5d2d02533d0f9c7 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2017 09:09:54 +0100 Subject: [PATCH 11/13] Add get method and cache_control to OrdersHostingListView --- hosting/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hosting/views.py b/hosting/views.py index 26adb834..b6d65455 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -923,6 +923,10 @@ class OrdersHostingListView(LoginRequiredMixin, ListView): self.queryset = HostingOrder.objects.filter(customer__user=user) return super(OrdersHostingListView, self).get_queryset() + @cache_control(no_cache=True, must_revalidate=True, no_store=True) + def get(self, request, *args, **kwargs): + return super(OrdersHostingListView, self).get(request, *args, **kwargs) + class OrdersHostingDeleteView(LoginRequiredMixin, DeleteView): login_url = reverse_lazy('hosting:login') From 1395c04a001033bc0813e4ada4f509dc7e90f85f Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2017 09:10:41 +0100 Subject: [PATCH 12/13] Add cache_control to CreateVirtualMachinesView and VirtualMachineView --- hosting/views.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hosting/views.py b/hosting/views.py index b6d65455..f43221c6 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -988,10 +988,12 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): if (value > 2000) or (value < 10): raise ValidationError(_('Invalid storage size')) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def get(self, request, *args, **kwargs): context = {'templates': VMTemplate.objects.all()} return render(request, self.template_name, context) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def post(self, request): cores = request.POST.get('cpu') cores_field = forms.IntegerField(validators=[self.validate_cores]) @@ -1114,6 +1116,7 @@ class VirtualMachineView(LoginRequiredMixin, View): return render(request, self.template_name, context) + @cache_control(no_cache=True, must_revalidate=True, no_store=True) def post(self, request, *args, **kwargs): response = {'status': False} admin_email_body = {} From a7a0ec88643e646f7ebf84b50d42b26414fc7348 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 9 Mar 2018 19:49:40 +0100 Subject: [PATCH 13/13] Add no_cache decorators instead of cache_control --- hosting/views.py | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 606ef60d..5f4ed639 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -18,7 +18,8 @@ from django.utils.http import urlsafe_base64_decode from django.utils.safestring import mark_safe from django.utils.translation import get_language, ugettext_lazy as _ from django.utils.translation import ugettext -from django.views.decorators.cache import cache_control +from django.utils.decorators import method_decorator +from django.views.decorators.cache import never_cache from django.views.generic import ( View, CreateView, FormView, ListView, DetailView, DeleteView, TemplateView, UpdateView @@ -63,6 +64,7 @@ logger = logging.getLogger(__name__) CONNECTION_ERROR = "Your VMs cannot be displayed at the moment due to a \ backend connection error. please try again in a few \ minutes." +decorators = [never_cache] class DashboardView(LoginRequiredMixin, View): @@ -73,7 +75,7 @@ class DashboardView(LoginRequiredMixin, View): context = {} return context - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): context = self.get_context_data() return render(request, self.template_name, context) @@ -205,7 +207,7 @@ class IndexView(View): } return context - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): context = self.get_context_data() return render(request, self.template_name, context) @@ -239,7 +241,7 @@ class SignupView(CreateView): return HttpResponseRedirect(reverse_lazy('hosting:signup-validate')) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): if self.request.user.is_authenticated(): return HttpResponseRedirect(self.get_success_url()) @@ -316,7 +318,7 @@ class SignupValidatedView(SignupValidateView): context['section_title'] = section_title return context - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): if self.request.user.is_authenticated(): return HttpResponseRedirect(reverse_lazy('hosting:dashboard')) @@ -456,7 +458,7 @@ class SSHKeyListView(LoginRequiredMixin, ListView): self.queryset = UserHostingKey.objects.filter(user=user) return super(SSHKeyListView, self).get_queryset() - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def render_to_response(self, context, **response_kwargs): if not self.queryset: return HttpResponseRedirect(reverse('hosting:choice_ssh_keys')) @@ -468,12 +470,12 @@ class SSHKeyChoiceView(LoginRequiredMixin, View): template_name = "hosting/choice_ssh_keys.html" login_url = reverse_lazy('hosting:login') - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): context = {} return render(request, self.template_name, context) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def post(self, request, *args, **kwargs): name = generate_ssh_key_name() private_key, public_key = UserHostingKey.generate_keys() @@ -543,11 +545,11 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView): manager.manage_public_key([{'value': public_key, 'state': True}]) return HttpResponseRedirect(self.success_url) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): return render(request, self.template_name) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def post(self, request, *args, **kwargs): form = self.get_form() required = 'add_ssh' in self.request.POST @@ -593,11 +595,11 @@ class SettingsView(LoginRequiredMixin, FormView): return context - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): return render(request, self.template_name) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def post(self, request, *args, **kwargs): form = self.get_form() if form.is_valid(): @@ -660,13 +662,13 @@ class PaymentVMView(LoginRequiredMixin, FormView): return context - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): if 'next' in request.session: del request.session['next'] return self.render_to_response(self.get_context_data()) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def post(self, request, *args, **kwargs): form = self.get_form() if form.is_valid(): @@ -794,7 +796,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): context['vm'] = self.request.session.get('specs') return context - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): if not self.kwargs.get('pk'): if 'specs' not in self.request.session: @@ -816,7 +818,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView): ) return self.render_to_response(context) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def post(self, request): template = request.session.get('template') specs = request.session.get('specs') @@ -923,7 +925,7 @@ class OrdersHostingListView(LoginRequiredMixin, ListView): self.queryset = HostingOrder.objects.filter(customer__user=user) return super(OrdersHostingListView, self).get_queryset() - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): return super(OrdersHostingListView, self).get(request, *args, **kwargs) @@ -988,12 +990,12 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View): if (value > 2000) or (value < 10): raise ValidationError(_('Invalid storage size')) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): context = {'templates': VMTemplate.objects.all()} return render(request, self.template_name, context) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def post(self, request): cores = request.POST.get('cpu') cores_field = forms.IntegerField(validators=[self.validate_cores]) @@ -1081,7 +1083,7 @@ class VirtualMachineView(LoginRequiredMixin, View): final_url = reverse('hosting:virtual_machines') return final_url - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def get(self, request, *args, **kwargs): vm = self.get_object() if vm is None: @@ -1116,7 +1118,7 @@ class VirtualMachineView(LoginRequiredMixin, View): return render(request, self.template_name, context) - @cache_control(no_cache=True, must_revalidate=True, no_store=True) + @method_decorator(decorators) def post(self, request, *args, **kwargs): response = {'status': False} admin_email_body = {}