Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
30dd7df4
authored
Mar 10, 2015
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
request: lease form and html
parent
6eef002e
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
134 additions
and
13 deletions
+134
-13
circle/dashboard/static/dashboard/dashboard.less
+4
-0
circle/dashboard/static/dashboard/vm-details.js
+5
-0
circle/dashboard/templates/dashboard/_vm-renew.html
+28
-0
circle/dashboard/templates/dashboard/operate.html
+4
-0
circle/dashboard/views/vm.py
+8
-0
circle/request/forms.py
+10
-3
circle/request/models.py
+6
-0
circle/request/templates/request/_request-lease-form.html
+10
-0
circle/request/templates/request/_request-template-form.html
+0
-4
circle/request/templates/request/request-lease.html
+28
-0
circle/request/urls.py
+4
-2
circle/request/views.py
+27
-4
No files found.
circle/dashboard/static/dashboard/dashboard.less
View file @
30dd7df4
...
@@ -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;
}
circle/dashboard/static/dashboard/vm-details.js
View file @
30dd7df4
...
@@ -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
()
});
});
});
circle/dashboard/templates/dashboard/_vm-renew.html
0 → 100644
View file @
30dd7df4
{% 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 %}
circle/dashboard/templates/dashboard/operate.html
View file @
30dd7df4
...
@@ -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 %}
circle/dashboard/views/vm.py
View file @
30dd7df4
...
@@ -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'
...
...
circle/request/forms.py
View file @
30dd7df4
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
)
circle/request/models.py
View file @
30dd7df4
...
@@ -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
})
...
...
circle/request/templates/request/_request-lease-form.html
0 → 100644
View file @
30dd7df4
{% 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>
circle/request/templates/request/_request-template-form.html
View file @
30dd7df4
{% 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 %}
circle/request/templates/request/request-lease.html
0 → 100644
View file @
30dd7df4
{% 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 %}
circle/request/urls.py
View file @
30dd7df4
...
@@ -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"
)
)
)
circle/request/views.py
View file @
30dd7df4
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment