Adjust urls in datacenterlight/hosting apps urls/views after refactor

This commit is contained in:
PCoder 2019-07-01 08:09:37 +05:30
parent b6eb72af7d
commit 47fd9a8f28
4 changed files with 6 additions and 83 deletions

View file

@ -1,9 +1,10 @@
from django.conf.urls import url from django.conf.urls import url
from django.views.generic import TemplateView, RedirectView from django.views.generic import TemplateView, RedirectView
from utils.views import AskSSHKeyView
from .views import ( from .views import (
IndexView, PaymentOrderView, OrderConfirmationView, IndexView, PaymentOrderView, OrderConfirmationView,
WhyDataCenterLightView, ContactUsView, AskSSHKeyView WhyDataCenterLightView, ContactUsView
) )
urlpatterns = [ urlpatterns = [

View file

@ -530,26 +530,6 @@ class PaymentOrderView(FormView):
return self.render_to_response(context) 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): class OrderConfirmationView(DetailView, FormView):
form_class = UserHostingKeyForm form_class = UserHostingKeyForm
template_name = "datacenterlight/order_detail.html" template_name = "datacenterlight/order_detail.html"

View file

@ -1,6 +1,7 @@
from django.conf.urls import url from django.conf.urls import url
from django.contrib.auth import views as auth_views from django.contrib.auth import views as auth_views
from utils.views import SSHKeyCreateView, AskSSHKeyView
from .views import ( from .views import (
DjangoHostingView, RailsHostingView, PaymentVMView, NodeJSHostingView, DjangoHostingView, RailsHostingView, PaymentVMView, NodeJSHostingView,
LoginView, SignupView, SignupValidateView, SignupValidatedView, IndexView, LoginView, SignupView, SignupValidateView, SignupValidatedView, IndexView,
@ -8,7 +9,7 @@ from .views import (
VirtualMachinesPlanListView, VirtualMachineView, OrdersHostingDeleteView, VirtualMachinesPlanListView, VirtualMachineView, OrdersHostingDeleteView,
MarkAsReadNotificationView, PasswordResetView, PasswordResetConfirmView, MarkAsReadNotificationView, PasswordResetView, PasswordResetConfirmView,
HostingPricingView, CreateVirtualMachinesView, HostingBillListView, HostingPricingView, CreateVirtualMachinesView, HostingBillListView,
HostingBillDetailView, SSHKeyDeleteView, SSHKeyCreateView, SSHKeyListView, HostingBillDetailView, SSHKeyDeleteView, SSHKeyListView,
SSHKeyChoiceView, DashboardView, SettingsView, ResendActivationEmailView, SSHKeyChoiceView, DashboardView, SettingsView, ResendActivationEmailView,
InvoiceListView, InvoiceDetailView, CheckUserVM InvoiceListView, InvoiceDetailView, CheckUserVM
) )
@ -27,6 +28,8 @@ urlpatterns = [
url(r'invoices/?$', InvoiceListView.as_view(), name='invoices'), url(r'invoices/?$', InvoiceListView.as_view(), name='invoices'),
url(r'order-confirmation/?$', OrdersHostingDetailView.as_view(), url(r'order-confirmation/?$', OrdersHostingDetailView.as_view(),
name='order-confirmation'), name='order-confirmation'),
url(r'^add-ssh-key/?$', AskSSHKeyView.as_view(),
name='add_ssh_key'),
url(r'orders/(?P<pk>\d+)/?$', OrdersHostingDetailView.as_view(), url(r'orders/(?P<pk>\d+)/?$', OrdersHostingDetailView.as_view(),
name='orders'), name='orders'),
url(r'invoice/(?P<invoice_id>[-\w]+)/?$', InvoiceDetailView.as_view(), url(r'invoice/(?P<invoice_id>[-\w]+)/?$', InvoiceDetailView.as_view(),

View file

@ -523,67 +523,6 @@ class SSHKeyChoiceView(LoginRequiredMixin, View):
return redirect(reverse_lazy('hosting:ssh_keys'), foo='bar') 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') @method_decorator(decorators, name='dispatch')
class SettingsView(LoginRequiredMixin, FormView): class SettingsView(LoginRequiredMixin, FormView):
template_name = "hosting/settings.html" template_name = "hosting/settings.html"