Adjust urls in datacenterlight/hosting apps urls/views after refactor
This commit is contained in:
parent
b6eb72af7d
commit
47fd9a8f28
4 changed files with 6 additions and 83 deletions
|
@ -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 = [
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<pk>\d+)/?$', OrdersHostingDetailView.as_view(),
|
||||
name='orders'),
|
||||
url(r'invoice/(?P<invoice_id>[-\w]+)/?$', InvoiceDetailView.as_view(),
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue