Commit 0fecf77a by Kálmán Viktor

dashboard: remove template clone functionality

parent 17eb9faa
......@@ -30,8 +30,6 @@ from crispy_forms.layout import (
Layout, Div, BaseInput, Field, HTML, Submit, Fieldset, TEMPLATE_PACK,
)
from crispy_forms.bootstrap import UneditableField as UF
from django.shortcuts import get_object_or_404
from crispy_forms.utils import render_field
from django import forms
......@@ -640,56 +638,6 @@ class TemplateForm(forms.ModelForm):
}
class TemplateCloneForm(forms.ModelForm):
uneditable_fields = ['num_cores', 'priority', 'ram_size', 'max_ram_size',
'arch', 'access_method', 'boot_menu', 'raw_data',
'description', 'system',
'lease', 'tags']
def __init__(self, *args, **kwargs):
self.clone_from = kwargs.pop("clone_from")
self.user = kwargs.pop("user")
super(TemplateCloneForm, self).__init__(*args, **kwargs)
data = self.data.copy()
template = get_object_or_404(InstanceTemplate, pk=self.clone_from)
for f in self.uneditable_fields:
self.initial[f] = getattr(template, f)
value = getattr(template, f)
if hasattr(value, "pk"):
value = value.pk
data.update({'%s' % f: value})
data.update({'owner': self.user.pk})
self.data = data
def save(self, *args, **kwargs):
pass
@property
def helper(self):
helper = FormHelper()
ufs = [UF(uf) for uf in self.uneditable_fields]
helper.layout = Layout(
Fieldset(
_("Modify these"),
Field("name"),
),
Fieldset(
_("You can't modify these ..."),
*ufs
)
)
helper.add_input(Submit('submit', _('Clone template')))
return helper
class Meta:
model = InstanceTemplate
exclude = ('state', 'disks', )
class LeaseForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
......
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load sizefieldtags %}
{% load crispy_forms_tags %}
{% block title-page %}{% trans "Clone template" %}{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<a class="pull-right btn btn-default btn-xs" href="{% url "dashboard.views.template-list" %}">{% trans "Back" %}</a>
<h3 class="no-margin"><i class="icon-puzzle-piece"></i> {% trans "Clone template" %}</h3>
</div>
<div class="panel-body">
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
</div>
</div>
</div>
</div><!-- .row -->
<style>
fieldset {
margin-top: 40px;
}
fieldset legend {
font-weight: bold;
}
</style>
{% endblock %}
{% block extra_js %}
{% endblock %}
{% load i18n %}
<a href="{% url "dashboard.views.template-clone" pk=record.pk %}" id="template-list-clone-button" class="btn btn-default btn-xs" title="{% trans "Clone" %}">
<i class="icon-copy"></i>
</a>
<a href="{% url "dashboard.views.template-detail" pk=record.pk%}" id="template-list-edit-button" class="btn btn-default btn-xs" title="{% trans "Edit" %}">
<i class="icon-edit"></i>
</a>
......
......@@ -30,7 +30,7 @@ from .views import (
TransferOwnershipView, vm_activity, VmCreate, VmDelete, VmDetailView,
VmDetailVncTokenView, VmGraphView, VmList, VmMassDelete, VmMigrateView,
VmRenewView, DiskRemoveView, get_disk_download_status, InterfaceDeleteView,
TemplateChoose, TemplateClone,
TemplateChoose,
)
urlpatterns = patterns(
......@@ -55,8 +55,6 @@ urlpatterns = patterns(
name="dashboard.views.template-list"),
url(r"^template/delete/(?P<pk>\d+)/$", TemplateDelete.as_view(),
name="dashboard.views.template-delete"),
url(r"^template/clone/(?P<pk>\d+)/$", TemplateClone.as_view(),
name="dashboard.views.template-clone"),
url(r'^vm/(?P<pk>\d+)/op/', include('dashboard.vm.urls')),
url(r'^vm/(?P<pk>\d+)/remove_port/(?P<rule>\d+)/$', PortDelete.as_view(),
......
......@@ -52,7 +52,7 @@ from braces.views._access import AccessMixin
from .forms import (
CircleAuthenticationForm, DiskAddForm, HostForm, LeaseForm, MyProfileForm,
NodeForm, TemplateForm, TraitForm, VmCustomizeForm, TemplateCloneForm,
NodeForm, TemplateForm, TraitForm, VmCustomizeForm,
CirclePasswordChangeForm
)
from .tables import (NodeListTable, NodeVmListTable,
......@@ -865,36 +865,6 @@ class TemplateChoose(TemplateView):
return redirect(instance.get_absolute_url())
class TemplateClone(CreateView):
template_name = "dashboard/template-clone.html"
form_class = TemplateCloneForm
model = InstanceTemplate
def get_form_kwargs(self):
kwargs = super(TemplateClone, self).get_form_kwargs()
kwargs['clone_from'] = self.kwargs['pk']
kwargs['user'] = self.request.user
return kwargs
def get(self, *args, **kwargs):
if not self.request.user.has_perm('vm.create_template'):
raise PermissionDenied()
return super(TemplateClone, self).get(*args, **kwargs)
def post(self, request, *args, **kwargs):
if not self.request.user.has_perm('vm.create_template'):
raise PermissionDenied()
form = self.form_class(request.POST, clone_from=kwargs['pk'],
user=request.user)
if not form.is_valid():
return self.get(request, form, *args, **kwargs)
else:
# clone template
return redirect("/") # temp
class TemplateCreate(SuccessMessageMixin, CreateView):
model = InstanceTemplate
form_class = TemplateForm
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment