Commit 3b4b53ee by Kálmán Viktor

dashboard: create lease

parent 699d1f07
......@@ -446,9 +446,13 @@ class LeaseForm(forms.ModelForm):
intervals = ["hours", "days", "weeks", "months"]
methods = ["suspend", "delete"]
# feels redundant but these lines are so long
s = (self.instance.suspend_interval.total_seconds()
if self.instance.pk else 0)
d = (self.instance.delete_interval.total_seconds()
if self.instance.pk else 0)
seconds = {
'suspend': self.instance.suspend_interval.total_seconds(),
'delete': self.instance.delete_interval.total_seconds()
'suspend': s,
'delete': d
}
initial = {
'suspend': self.get_intervals(int(seconds['suspend'])),
......@@ -487,8 +491,8 @@ class LeaseForm(forms.ModelForm):
helper = FormHelper()
helper.layout = Layout(
Field('name'),
Field("suspend_interval_seconds", type="hidden"),
Field("delete_interval_seconds", type="hidden"),
Field("suspend_interval_seconds", type="hidden", value="0"),
Field("delete_interval_seconds", type="hidden", value="0"),
Div(
Div(
HTML(_("Suspend in")),
......
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% 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-desktop"></i> {% trans "Create lease" %}</h3>
</div>
<div class="panel-body">
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
</div>
</div>
</div>
</div>
{% endblock %}
......@@ -7,8 +7,8 @@
<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" %}">Back</a>
<h3 class="no-margin"><i class="icon-desktop"></i> Edit lease</h3>
<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-desktop"></i> {% trans "Edit lease" %}</h3>
</div>
<div class="panel-body">
{% with form=form %}
......
......@@ -5,7 +5,7 @@ from .views import (
IndexView, VmDetailView, VmList, VmCreate, TemplateDetail, AclUpdateView,
VmDelete, VmMassDelete, vm_activity, NodeList, NodeDetailView, PortDelete,
TransferOwnershipView, TransferOwnershipConfirmView, NodeDelete,
TemplateList, LeaseDetail, NodeCreate,
TemplateList, LeaseDetail, NodeCreate, LeaseCreate, TemplateCreate,
)
urlpatterns = patterns(
......@@ -13,6 +13,8 @@ urlpatterns = patterns(
url(r'^$', IndexView.as_view(), name="dashboard.index"),
url(r'^lease/(?P<pk>\d+)/$', LeaseDetail.as_view(),
name="dashboard.views.lease-detail"),
url(r'^lease/create/$', LeaseCreate.as_view(),
name="dashboard.views.lease-create"),
url(r'^template/(?P<pk>\d+)/$', TemplateDetail.as_view(),
name='dashboard.views.template-detail'),
url(r"^template/list/$", TemplateList.as_view(),
......
......@@ -15,7 +15,7 @@ from django.shortcuts import redirect, render
from django.views.decorators.http import require_POST
from django.views.generic.detail import SingleObjectMixin
from django.views.generic import (TemplateView, DetailView, View, DeleteView,
UpdateView)
UpdateView, CreateView)
from django.contrib import messages
from django.utils.translation import ugettext as _
......@@ -737,6 +737,16 @@ class VmMassDelete(View):
return redirect(next if next else reverse_lazy('dashboard.index'))
class LeaseCreate(SuccessMessageMixin, CreateView):
model = Lease
form_class = LeaseForm
template_name = "dashboard/lease-create.html"
success_message = _("Successfully created a new lease!")
def get_success_url(self):
return reverse_lazy("dashboard.views.template-list")
class LeaseDetail(SuccessMessageMixin, UpdateView):
model = Lease
form_class = LeaseForm
......
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