Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
51d0dbc9
authored
Feb 06, 2015
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: appliance columns for disk list
parent
2faa9566
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
5 deletions
+42
-5
circle/dashboard/tables.py
+28
-2
circle/dashboard/templates/dashboard/storage/column-appliance.html
+9
-0
circle/storage/models.py
+5
-3
No files found.
circle/dashboard/tables.py
View file @
51d0dbc9
...
@@ -21,10 +21,12 @@ from django.contrib.auth.models import Group, User
...
@@ -21,10 +21,12 @@ from django.contrib.auth.models import Group, User
from
django_tables2
import
Table
,
A
from
django_tables2
import
Table
,
A
from
django_tables2.columns
import
(
TemplateColumn
,
Column
,
LinkColumn
,
from
django_tables2.columns
import
(
TemplateColumn
,
Column
,
LinkColumn
,
BooleanColumn
)
BooleanColumn
)
from
django.utils.safestring
import
mark_safe
from
django.utils.html
import
escape
from
vm.models
import
Node
,
InstanceTemplate
,
Lease
from
vm.models
import
Node
,
InstanceTemplate
,
Lease
from
storage.models
import
Disk
from
storage.models
import
Disk
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext
from
django_sshkey.models
import
UserKey
from
django_sshkey.models
import
UserKey
from
dashboard.models
import
ConnectCommand
from
dashboard.models
import
ConnectCommand
...
@@ -37,6 +39,22 @@ class FileSizeColumn(Column):
...
@@ -37,6 +39,22 @@ class FileSizeColumn(Column):
return
size
return
size
class
ApplianceColumn
(
TemplateColumn
):
def
render
(
self
,
*
args
,
**
kwargs
):
value
=
super
(
ApplianceColumn
,
self
)
.
render
(
*
args
,
**
kwargs
)
abbr
=
'<abbr title="
%
s">
%
s</abbr>'
appliance
=
kwargs
[
'record'
]
.
get_appliance
()
if
appliance
is
None
:
return
value
elif
isinstance
(
appliance
,
InstanceTemplate
):
# Translators: [T] as Template
title
,
text
=
ugettext
(
"Template"
),
ugettext
(
"[T]"
)
else
:
# Translators: [VM] as Virtual Machine
title
,
text
=
ugettext
(
"Virtual machine"
),
ugettext
(
"[VM]"
)
return
mark_safe
(
"
%
s
%
s"
%
(
abbr
%
(
title
,
text
),
value
))
class
NodeListTable
(
Table
):
class
NodeListTable
(
Table
):
pk
=
Column
(
pk
=
Column
(
...
@@ -306,12 +324,20 @@ class ConnectCommandListTable(Table):
...
@@ -306,12 +324,20 @@ class ConnectCommandListTable(Table):
class
DiskListTable
(
Table
):
class
DiskListTable
(
Table
):
size
=
FileSizeColumn
()
size
=
FileSizeColumn
()
appliance
=
ApplianceColumn
(
template_name
=
"dashboard/storage/column-appliance.html"
,
verbose_name
=
_
(
"Appliance"
),
orderable
=
False
,
)
is_ready
=
BooleanColumn
(
verbose_name
=
_
(
"ready"
)
)
class
Meta
:
class
Meta
:
model
=
Disk
model
=
Disk
attrs
=
{
'class'
:
"table table-bordered table-striped table-hover"
,
attrs
=
{
'class'
:
"table table-bordered table-striped table-hover"
,
'id'
:
"disk-list-table"
}
'id'
:
"disk-list-table"
}
fields
=
(
"pk"
,
"
nam
e"
,
"filename"
,
"size"
,
"is_ready"
)
fields
=
(
"pk"
,
"
applianc
e"
,
"filename"
,
"size"
,
"is_ready"
)
prefix
=
"disk-"
prefix
=
"disk-"
order_by
=
(
"-pk"
,
)
order_by
=
(
"-pk"
,
)
per_page
=
65536
per_page
=
65536
circle/dashboard/templates/dashboard/storage/column-appliance.html
0 → 100644
View file @
51d0dbc9
{% load i18n %}
{% with app=record.get_appliance %}
{% if app %}
<a
href=
"{{ app.get_absolute_url }}"
>
{{ app.name }}
</a>
{% else %}
—
{% endif %}
{% endwith %}
circle/storage/models.py
View file @
51d0dbc9
...
@@ -27,6 +27,7 @@ import re
...
@@ -27,6 +27,7 @@ import re
from
celery.contrib.abortable
import
AbortableAsyncResult
from
celery.contrib.abortable
import
AbortableAsyncResult
from
django.db.models
import
(
Model
,
BooleanField
,
CharField
,
DateTimeField
,
from
django.db.models
import
(
Model
,
BooleanField
,
CharField
,
DateTimeField
,
ForeignKey
)
ForeignKey
)
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
model_utils.models
import
TimeStampedModel
from
model_utils.models
import
TimeStampedModel
...
@@ -290,9 +291,10 @@ class Disk(TimeStampedModel):
...
@@ -290,9 +291,10 @@ class Disk(TimeStampedModel):
"""
"""
from
vm.models
import
Instance
from
vm.models
import
Instance
try
:
try
:
return
self
.
instance_set
.
get
()
app
=
self
.
template_set
.
all
()
or
self
.
instance_set
.
all
()
except
Instance
.
DoesNotExist
:
return
app
.
get
()
return
self
.
template_set
.
get
()
except
ObjectDoesNotExist
:
return
None
def
get_exclusive
(
self
):
def
get_exclusive
(
self
):
"""Get an instance of the disk for exclusive usage.
"""Get an instance of the disk for exclusive usage.
...
...
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