From 47fd9a8f28d85f580bad8947a0aea15435f70ce3 Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 1 Jul 2019 08:09:37 +0530 Subject: [PATCH] Adjust urls in datacenterlight/hosting apps urls/views after refactor --- datacenterlight/urls.py | 3 +- datacenterlight/views.py | 20 ------------- hosting/urls.py | 5 +++- hosting/views.py | 61 ---------------------------------------- 4 files changed, 6 insertions(+), 83 deletions(-) diff --git a/datacenterlight/urls.py b/datacenterlight/urls.py index d20366bf..13296de7 100644 --- a/datacenterlight/urls.py +++ b/datacenterlight/urls.py @@ -1,9 +1,10 @@ from django.conf.urls import url from django.views.generic import TemplateView, RedirectView +from utils.views import AskSSHKeyView from .views import ( IndexView, PaymentOrderView, OrderConfirmationView, - WhyDataCenterLightView, ContactUsView, AskSSHKeyView + WhyDataCenterLightView, ContactUsView ) urlpatterns = [ diff --git a/datacenterlight/views.py b/datacenterlight/views.py index d76303f7..99ceae8f 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -530,26 +530,6 @@ class PaymentOrderView(FormView): return self.render_to_response(context) -class AskSSHKeyView(FormView): - form_class = UserHostingKeyForm - template_name = "datacenterlight/add_ssh_key.html" - - def get_form_kwargs(self): - kwargs = super(AskSSHKeyView, self).get_form_kwargs() - kwargs.update({'request': self.request}) - return kwargs - - @cache_control(no_cache=True, must_revalidate=True, no_store=True) - def get(self, request, *args, **kwargs): - context = { - 'site_url': reverse('datacenterlight:index'), - 'cms_integration': get_cms_integration('default'), - 'form': UserHostingKeyForm(request=self.request), - 'keys': get_all_public_keys(self.request.user) - } - return render(request, self.template_name, context) - - class OrderConfirmationView(DetailView, FormView): form_class = UserHostingKeyForm template_name = "datacenterlight/order_detail.html" diff --git a/hosting/urls.py b/hosting/urls.py index 4779f67c..5b2b87b0 100644 --- a/hosting/urls.py +++ b/hosting/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import url from django.contrib.auth import views as auth_views +from utils.views import SSHKeyCreateView, AskSSHKeyView from .views import ( DjangoHostingView, RailsHostingView, PaymentVMView, NodeJSHostingView, LoginView, SignupView, SignupValidateView, SignupValidatedView, IndexView, @@ -8,7 +9,7 @@ from .views import ( VirtualMachinesPlanListView, VirtualMachineView, OrdersHostingDeleteView, MarkAsReadNotificationView, PasswordResetView, PasswordResetConfirmView, HostingPricingView, CreateVirtualMachinesView, HostingBillListView, - HostingBillDetailView, SSHKeyDeleteView, SSHKeyCreateView, SSHKeyListView, + HostingBillDetailView, SSHKeyDeleteView, SSHKeyListView, SSHKeyChoiceView, DashboardView, SettingsView, ResendActivationEmailView, InvoiceListView, InvoiceDetailView, CheckUserVM ) @@ -27,6 +28,8 @@ urlpatterns = [ url(r'invoices/?$', InvoiceListView.as_view(), name='invoices'), url(r'order-confirmation/?$', OrdersHostingDetailView.as_view(), name='order-confirmation'), + url(r'^add-ssh-key/?$', AskSSHKeyView.as_view(), + name='add_ssh_key'), url(r'orders/(?P\d+)/?$', OrdersHostingDetailView.as_view(), name='orders'), url(r'invoice/(?P[-\w]+)/?$', InvoiceDetailView.as_view(), diff --git a/hosting/views.py b/hosting/views.py index f5146fbf..97b7f42c 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -523,67 +523,6 @@ class SSHKeyChoiceView(LoginRequiredMixin, View): return redirect(reverse_lazy('hosting:ssh_keys'), foo='bar') -@method_decorator(decorators, name='dispatch') -class SSHKeyCreateView(LoginRequiredMixin, FormView): - form_class = UserHostingKeyForm - model = UserHostingKey - template_name = 'hosting/user_key.html' - login_url = reverse_lazy('hosting:login') - context_object_name = "virtual_machine" - success_url = reverse_lazy('hosting:ssh_keys') - - def get_form_kwargs(self): - kwargs = super(SSHKeyCreateView, self).get_form_kwargs() - kwargs.update({'request': self.request}) - return kwargs - - def form_valid(self, form): - form.save() - if settings.DCL_SSH_KEY_NAME_PREFIX in form.instance.name: - content = ContentFile(form.cleaned_data.get('private_key')) - filename = form.cleaned_data.get( - 'name') + '_' + str(uuid.uuid4())[:8] + '_private.pem' - form.instance.private_key.save(filename, content) - context = self.get_context_data() - - next_url = self.request.session.get( - 'next', - reverse('hosting:create_virtual_machine') - ) - - if 'next' in self.request.session: - context.update({ - 'next_url': next_url - }) - del (self.request.session['next']) - - if form.cleaned_data.get('private_key'): - context.update({ - 'private_key': form.cleaned_data.get('private_key'), - 'key_name': form.cleaned_data.get('name'), - 'form': UserHostingKeyForm(request=self.request), - }) - - owner = self.request.user - manager = OpenNebulaManager( - email=owner.email, - password=owner.password - ) - keys_to_save = get_all_public_keys(self.request.user) - manager.save_key_in_opennebula_user('\n'.join(keys_to_save)) - return HttpResponseRedirect(self.success_url) - - def post(self, request, *args, **kwargs): - form = self.get_form() - required = 'add_ssh' in self.request.POST - form.fields['name'].required = required - form.fields['public_key'].required = required - if form.is_valid(): - return self.form_valid(form) - else: - return self.form_invalid(form) - - @method_decorator(decorators, name='dispatch') class SettingsView(LoginRequiredMixin, FormView): template_name = "hosting/settings.html"