Commit 30dd7df4 by Kálmán Viktor

request: lease form and html

parent 6eef002e
...@@ -1269,3 +1269,7 @@ textarea[name="new_members"] { ...@@ -1269,3 +1269,7 @@ textarea[name="new_members"] {
background: #f9f9f9; background: #f9f9f9;
margin-top: 20px; margin-top: 20px;
} }
#vm-renew-request-lease {
display: none;
}
...@@ -223,4 +223,9 @@ $(function() { ...@@ -223,4 +223,9 @@ $(function() {
return false; return false;
}); });
$(document).on("click", "#vm-renew-request-lease-button", function(e) {
$("#vm-renew-request-lease").stop().slideToggle();
e.preventDefault()
});
}); });
{% extends "dashboard/operate.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block formbuttons %}
<div class="pull-right">
<a class="btn btn-default" href="{{object.get_absolute_url}}" data-dismiss="modal">
{% trans "Cancel" %}
</a>
<a class="btn btn-primary" id="vm-renew-request-lease-button"
href="{% url "request.views.request-lease" vm_pk=object.pk %}">
<i class="fa fa-forward"></i>
{% trans "Request longer lease" %}
</a>
<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 }}
</button>
</div>
{% endblock %}
{% block extra %}
<div class="clearfix"></div>
<div id="vm-renew-request-lease">
<hr />
{% include "request/_request-lease-form.html" with form=lease_request_form vm=object %}
</div>
{% endblock %}
...@@ -16,6 +16,7 @@ Do you want to perform the following operation on ...@@ -16,6 +16,7 @@ Do you want to perform the following operation on
{% crispy form %} {% crispy form %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block formbuttons %}
<div class="pull-right"> <div class="pull-right">
<a class="btn btn-default" href="{{object.get_absolute_url}}" <a class="btn btn-default" href="{{object.get_absolute_url}}"
data-dismiss="modal">{% trans "Cancel" %}</a> data-dismiss="modal">{% trans "Cancel" %}</a>
...@@ -23,4 +24,7 @@ Do you want to perform the following operation on ...@@ -23,4 +24,7 @@ Do you want to perform the following operation on
{% 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>
</div> </div>
{% endblock %}
</form> </form>
{% block extra %}{% endblock %}
...@@ -67,6 +67,7 @@ from ..forms import ( ...@@ -67,6 +67,7 @@ from ..forms import (
VmRemoveInterfaceForm, VmRemoveInterfaceForm,
) )
from request.models import TemplateAccessType from request.models import TemplateAccessType
from request.forms import LeaseRequestForm
from ..models import Favourite from ..models import Favourite
from manager.scheduler import has_traits from manager.scheduler import has_traits
...@@ -656,6 +657,8 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView): ...@@ -656,6 +657,8 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView):
show_in_toolbar = False show_in_toolbar = False
form_class = VmRenewForm form_class = VmRenewForm
wait_for_result = 0.5 wait_for_result = 0.5
template_name = 'dashboard/_vm-renew.html'
with_reload = True
def get_form_kwargs(self): def get_form_kwargs(self):
choices = Lease.get_objects_with_level("user", self.request.user) choices = Lease.get_objects_with_level("user", self.request.user)
...@@ -675,6 +678,11 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView): ...@@ -675,6 +678,11 @@ class VmRenewView(FormOperationMixin, TokenOperationView, VmOperationView):
instance.time_of_suspend) instance.time_of_suspend)
return extra return extra
def get_context_data(self, **kwargs):
context = super(VmRenewView, self).get_context_data(**kwargs)
context['lease_request_form'] = LeaseRequestForm()
return context
class VmStateChangeView(FormOperationMixin, VmOperationView): class VmStateChangeView(FormOperationMixin, VmOperationView):
op = 'emergency_change_state' op = 'emergency_change_state'
......
from django.forms import ModelForm, ModelChoiceField, ChoiceField, Form, CharField from django.forms import (
ModelForm, ModelChoiceField, ChoiceField, Form, CharField, RadioSelect,
)
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -6,7 +8,7 @@ from crispy_forms.helper import FormHelper ...@@ -6,7 +8,7 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit from crispy_forms.layout import Submit
from request.models import ( from request.models import (
Request, LeaseType, TemplateAccessType, TemplateAccessAction, LeaseType, TemplateAccessType, TemplateAccessAction,
) )
...@@ -39,7 +41,6 @@ class TemplateAccessTypeForm(ModelForm): ...@@ -39,7 +41,6 @@ class TemplateAccessTypeForm(ModelForm):
class Meta: class Meta:
model = TemplateAccessType model = TemplateAccessType
from django.forms import RadioSelect
class TemplateRequestForm(Form): class TemplateRequestForm(Form):
template = ModelChoiceField(TemplateAccessType.objects.all(), template = ModelChoiceField(TemplateAccessType.objects.all(),
...@@ -47,3 +48,9 @@ class TemplateRequestForm(Form): ...@@ -47,3 +48,9 @@ class TemplateRequestForm(Form):
level = ChoiceField(TemplateAccessAction.LEVELS, widget=RadioSelect, level = ChoiceField(TemplateAccessAction.LEVELS, widget=RadioSelect,
initial=TemplateAccessAction.LEVELS.user) initial=TemplateAccessAction.LEVELS.user)
reason = CharField(widget=forms.Textarea) reason = CharField(widget=forms.Textarea)
class LeaseRequestForm(Form):
lease = ModelChoiceField(LeaseType.objects.all(),
label=_("Lease"))
reason = CharField(widget=forms.Textarea)
...@@ -48,6 +48,12 @@ class Request(TimeStampedModel): ...@@ -48,6 +48,12 @@ class Request(TimeStampedModel):
class LeaseType(RequestType): class LeaseType(RequestType):
lease = ForeignKey(Lease) lease = ForeignKey(Lease)
def __unicode__(self):
return _("%(name)s (suspend: %(s)s, remove: %(r)s)") % {
'name': self.name,
's': self.lease.get_readable_suspend_time(),
'r': self.lease.get_readable_delete_time()}
def get_absolute_url(self): def get_absolute_url(self):
return reverse("request.views.lease-type-detail", return reverse("request.views.lease-type-detail",
kwargs={'pk': self.pk}) kwargs={'pk': self.pk})
......
{% load i18n %}
{% load crispy_forms_tags %}
<form action="{% url "request.views.request-lease" vm_pk=vm.pk %}" method="POST">
{% include "display-form-errors.html" %}
{% csrf_token %}
{{ form.lease|as_crispy_field }}
{{ form.reason|as_crispy_field }}
<input type="submit" class="btn btn-primary"/>
</form>
{% load i18n %} {% load i18n %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block content %}
<form action="{% url "request.views.request-template" %}" method="POST"> <form action="{% url "request.views.request-template" %}" method="POST">
{% include "display-form-errors.html" %} {% include "display-form-errors.html" %}
{% csrf_token %} {% csrf_token %}
...@@ -26,5 +24,3 @@ ...@@ -26,5 +24,3 @@
{{ form.reason|as_crispy_field }} {{ form.reason|as_crispy_field }}
<input type="submit" class="btn btn-primary"/> <input type="submit" class="btn btn-primary"/>
</form> </form>
{% endblock %}
{% extends "dashboard/base.html" %}
{% load i18n %}
{% block content %}
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="no-margin">
<i class="fa fa-puzzle-piece"></i> {% trans "Request new lease" %}
</h3>
</div>
<div class="panel-body">
<div class="form-group">
<label>{% trans "Virtual machine" %}</label>
<div class="controls">
<a href="{{ vm.get_absolute_url }}">{{ vm.name }}</a>
</div>
</div>
{% include "request/_request-lease-form.html" %}
</div>
</div>
</div>
</div>
{% endblock %}
...@@ -22,7 +22,7 @@ from .views import ( ...@@ -22,7 +22,7 @@ from .views import (
RequestList, RequestDetail, RequestTypeList, RequestList, RequestDetail, RequestTypeList,
LeaseTypeCreate, LeaseTypeDetail, LeaseTypeCreate, LeaseTypeDetail,
TemplateAccessTypeCreate, TemplateAccessTypeDetail, TemplateAccessTypeCreate, TemplateAccessTypeDetail,
TemplateRequestView, TemplateRequestView, LeaseRequestView,
) )
urlpatterns = patterns( urlpatterns = patterns(
...@@ -47,5 +47,7 @@ urlpatterns = patterns( ...@@ -47,5 +47,7 @@ urlpatterns = patterns(
name="request.views.template-type-detail"), name="request.views.template-type-detail"),
url(r'template/$', TemplateRequestView.as_view(), url(r'template/$', TemplateRequestView.as_view(),
name="request.views.request-template") name="request.views.request-template"),
url(r'lease/(?P<vm_pk>\d+)/$', LeaseRequestView.as_view(),
name="request.views.request-lease")
) )
...@@ -3,17 +3,23 @@ from __future__ import unicode_literals, absolute_import ...@@ -3,17 +3,23 @@ from __future__ import unicode_literals, absolute_import
from django.views.generic import ( from django.views.generic import (
UpdateView, TemplateView, DetailView, CreateView, FormView, UpdateView, TemplateView, DetailView, CreateView, FormView,
) )
from django.shortcuts import redirect from django.shortcuts import redirect, get_object_or_404
from django.core.exceptions import PermissionDenied
from braces.views import SuperuserRequiredMixin, LoginRequiredMixin from braces.views import SuperuserRequiredMixin, LoginRequiredMixin
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
from request.models import Request, TemplateAccessType, LeaseType from request.models import (
Request, TemplateAccessType, LeaseType, TemplateAccessAction,
# ExtendLeaseAction,
)
from vm.models import Instance
from request.tables import ( from request.tables import (
RequestTable, TemplateAccessTypeTable, LeaseTypeTable, RequestTable, TemplateAccessTypeTable, LeaseTypeTable,
) )
from request.forms import ( from request.forms import (
LeaseTypeForm, TemplateAccessTypeForm, TemplateRequestForm LeaseTypeForm, TemplateAccessTypeForm, TemplateRequestForm,
LeaseRequestForm,
) )
...@@ -87,7 +93,6 @@ class TemplateRequestView(FormView): ...@@ -87,7 +93,6 @@ class TemplateRequestView(FormView):
template_name = "request/request-template.html" template_name = "request/request-template.html"
def form_valid(self, form): def form_valid(self, form):
from request.models import TemplateAccessAction
data = form.cleaned_data data = form.cleaned_data
user = self.request.user user = self.request.user
...@@ -107,3 +112,21 @@ class TemplateRequestView(FormView): ...@@ -107,3 +112,21 @@ class TemplateRequestView(FormView):
req.save() req.save()
return redirect("/") return redirect("/")
class LeaseRequestView(FormView):
form_class = LeaseRequestForm
template_name = "request/request-lease.html"
def get_context_data(self, **kwargs):
vm = get_object_or_404(Instance, pk=self.kwargs['vm_pk'])
user = self.request.user
if not vm.has_level(user, 'operator'):
raise PermissionDenied()
context = super(LeaseRequestView, self).get_context_data(**kwargs)
context['vm'] = vm
return context
def form_valid(self, form):
pass
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