Commit ff91b0ff by Kálmán Viktor

Merge branch 'request-fixes' into 'master'

Request fixes

Closes #403
Closes #406

See merge request !325
parents c0d9098f b5d8534d
...@@ -8,11 +8,13 @@ ...@@ -8,11 +8,13 @@
<a class="btn btn-default" href="{{object.get_absolute_url}}" data-dismiss="modal"> <a class="btn btn-default" href="{{object.get_absolute_url}}" data-dismiss="modal">
{% trans "Cancel" %} {% trans "Cancel" %}
</a> </a>
{% if lease_types %}
<a class="btn btn-primary" id="vm-renew-request-lease-button" <a class="btn btn-primary" id="vm-renew-request-lease-button"
href="{% url "request.views.request-lease" vm_pk=object.pk %}"> href="{% url "request.views.request-lease" vm_pk=object.pk %}">
<i class="fa fa-forward"></i> <i class="fa fa-forward"></i>
{% trans "Request longer lease" %} {% trans "Request longer lease" %}
</a> </a>
{% endif %}
<button class="btn btn-{{ opview.effect }} btn-op-form-send" type="submit" id="op-form-send"> <button class="btn btn-{{ opview.effect }} btn-op-form-send" type="submit" id="op-form-send">
{% if opview.icon %}<i class="fa fa-fw fa-{{opview.icon}}"></i> {% endif %}{{ op.name|capfirst }} {% if opview.icon %}<i class="fa fa-fw fa-{{opview.icon}}"></i> {% endif %}{{ op.name|capfirst }}
</button> </button>
......
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
{% if op.resources_change %} {% if op.resources_change %}
<button type="submit" class="btn btn-success btn-sm change-resources-button" <button type="submit" class="btn btn-success btn-sm change-resources-button"
id="vm-details-resources-save" data-vm="{{ instance.pk }}" id="vm-details-resources-save" data-vm="{{ instance.pk }}"
{% if op.resources_change.disabled %}disabled{% endif %}> {% if not save_resources_enabled %}disabled{% endif %}>
<i class="fa fa-floppy-o"></i> {% trans "Save resources" %} <i class="fa fa-floppy-o"></i> {% trans "Save resources" %}
</button> </button>
<span class="change-resources-help" <span class="change-resources-help"
{% if not op.resources_change.disabled %}style="display: none;"{% endif %}> {% if save_resources_enabled %}style="display: none;"{% endif %}>
{% trans "Stop your VM to change resources." %} {% trans "Stop your VM to change resources." %}
</span> </span>
{% else %} {% else %}
......
...@@ -66,7 +66,7 @@ from ..forms import ( ...@@ -66,7 +66,7 @@ from ..forms import (
VmPortRemoveForm, VmPortAddForm, VmPortRemoveForm, VmPortAddForm,
VmRemoveInterfaceForm, VmRemoveInterfaceForm,
) )
from request.models import TemplateAccessType from request.models import TemplateAccessType, LeaseType
from request.forms import LeaseRequestForm, TemplateRequestForm from request.forms import LeaseRequestForm, TemplateRequestForm
from ..models import Favourite from ..models import Favourite
from manager.scheduler import has_traits from manager.scheduler import has_traits
...@@ -173,6 +173,10 @@ class VmDetailView(GraphMixin, CheckedDetailView): ...@@ -173,6 +173,10 @@ class VmDetailView(GraphMixin, CheckedDetailView):
context['is_operator'] = is_operator context['is_operator'] = is_operator
context['is_owner'] = is_owner context['is_owner'] = is_owner
# operation also allows RUNNING (if with_shutdown is present)
context['save_resources_enabled'] = instance.status not in ("RUNNING",
"PENDING")
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
...@@ -681,6 +685,7 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView): ...@@ -681,6 +685,7 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(VmRenewView, self).get_context_data(**kwargs) context = super(VmRenewView, self).get_context_data(**kwargs)
context['lease_request_form'] = LeaseRequestForm(request=self.request) context['lease_request_form'] = LeaseRequestForm(request=self.request)
context['lease_types'] = LeaseType.objects.exists()
return context return context
......
...@@ -19,9 +19,11 @@ from __future__ import unicode_literals, absolute_import ...@@ -19,9 +19,11 @@ from __future__ import unicode_literals, absolute_import
from django.views.generic import ( from django.views.generic import (
UpdateView, TemplateView, DetailView, CreateView, FormView, DeleteView, UpdateView, TemplateView, DetailView, CreateView, FormView, DeleteView,
) )
from django.contrib.messages.views import SuccessMessageMixin
from django.shortcuts import redirect, get_object_or_404 from django.shortcuts import redirect, get_object_or_404
from django.core.exceptions import PermissionDenied, SuspiciousOperation from django.core.exceptions import PermissionDenied, SuspiciousOperation
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from braces.views import SuperuserRequiredMixin, LoginRequiredMixin from braces.views import SuperuserRequiredMixin, LoginRequiredMixin
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
...@@ -97,17 +99,19 @@ class RequestDetail(LoginRequiredMixin, DetailView): ...@@ -97,17 +99,19 @@ class RequestDetail(LoginRequiredMixin, DetailView):
class TemplateAccessTypeDetail(LoginRequiredMixin, SuperuserRequiredMixin, class TemplateAccessTypeDetail(LoginRequiredMixin, SuperuserRequiredMixin,
UpdateView): SuccessMessageMixin, UpdateView):
model = TemplateAccessType model = TemplateAccessType
template_name = "request/template-type-form.html" template_name = "request/template-type-form.html"
form_class = TemplateAccessTypeForm form_class = TemplateAccessTypeForm
success_message = _("Template access type successfully updated.")
class TemplateAccessTypeCreate(LoginRequiredMixin, SuperuserRequiredMixin, class TemplateAccessTypeCreate(LoginRequiredMixin, SuperuserRequiredMixin,
CreateView): SuccessMessageMixin, CreateView):
model = TemplateAccessType model = TemplateAccessType
template_name = "request/template-type-form.html" template_name = "request/template-type-form.html"
form_class = TemplateAccessTypeForm form_class = TemplateAccessTypeForm
success_message = _("New template access type successfully created.")
class TemplateAccessTypeDelete(LoginRequiredMixin, SuperuserRequiredMixin, class TemplateAccessTypeDelete(LoginRequiredMixin, SuperuserRequiredMixin,
...@@ -119,16 +123,20 @@ class TemplateAccessTypeDelete(LoginRequiredMixin, SuperuserRequiredMixin, ...@@ -119,16 +123,20 @@ class TemplateAccessTypeDelete(LoginRequiredMixin, SuperuserRequiredMixin,
return reverse("request.views.type-list") return reverse("request.views.type-list")
class LeaseTypeDetail(LoginRequiredMixin, SuperuserRequiredMixin, UpdateView): class LeaseTypeDetail(LoginRequiredMixin, SuperuserRequiredMixin,
SuccessMessageMixin, UpdateView):
model = LeaseType model = LeaseType
template_name = "request/lease-type-form.html" template_name = "request/lease-type-form.html"
form_class = LeaseTypeForm form_class = LeaseTypeForm
success_message = _("Lease type successfully updated.")
class LeaseTypeCreate(LoginRequiredMixin, SuperuserRequiredMixin, CreateView): class LeaseTypeCreate(LoginRequiredMixin, SuperuserRequiredMixin,
SuccessMessageMixin, CreateView):
model = LeaseType model = LeaseType
template_name = "request/lease-type-form.html" template_name = "request/lease-type-form.html"
form_class = LeaseTypeForm form_class = LeaseTypeForm
success_message = _("New lease type successfully created.")
class LeaseTypeDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView): class LeaseTypeDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
...@@ -154,7 +162,7 @@ class RequestTypeList(LoginRequiredMixin, SuperuserRequiredMixin, ...@@ -154,7 +162,7 @@ class RequestTypeList(LoginRequiredMixin, SuperuserRequiredMixin,
return context return context
class TemplateRequestView(FormView): class TemplateRequestView(LoginRequiredMixin, FormView):
form_class = TemplateRequestForm form_class = TemplateRequestForm
template_name = "request/request-template.html" template_name = "request/request-template.html"
...@@ -185,7 +193,7 @@ class TemplateRequestView(FormView): ...@@ -185,7 +193,7 @@ class TemplateRequestView(FormView):
return redirect("/") return redirect("/")
class VmRequestMixin(object): class VmRequestMixin(LoginRequiredMixin, object):
def get_vm(self): def get_vm(self):
return get_object_or_404(Instance, pk=self.kwargs['vm_pk']) return get_object_or_404(Instance, pk=self.kwargs['vm_pk'])
......
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