- {% trans "ID" %} |
- {% trans "Name" %} |
- {% trans "State" %} |
- {% trans "Owner" %} |
- {% if user.is_superuser %}{% trans "Node" %} | {% endif %}
+
+ {% trans "ID" as t %}
+ {% include "dashboard/vm-list/header-link.html" with name=t sort="pk" %}
+ |
+
+ {% trans "Name" as t %}
+ {% include "dashboard/vm-list/header-link.html" with name=t sort="name" %}
+ |
+
+ {% trans "State" as t %}
+ {% include "dashboard/vm-list/header-link.html" with name=t sort="status" %}
+ |
+
+ {% trans "Owner" as t %}
+ {% include "dashboard/vm-list/header-link.html" with name=t sort="owner" %}
+ |
+ {% if user.is_superuser %}
+ {% trans "Node" as t %}
+ {% include "dashboard/vm-list/header-link.html" with name=t sort="node" %}
+ | {% endif %}
{% for i in object_list %}
-
+
{{i.pk}} |
{{ i.name }} |
{{ i.get_status_display }} |
{{ i.owner }} |
- {% if user.is_superuser %}{{ i.node.name|default:"-" }} | {% endif %}
+ {% if user.is_superuser %}
+ {{ i.node.name|default:"-" }} |
+ {% endif %}
{% empty %}
- {% trans "You have no virtual machines." %} |
+ {% trans "You have no virtual machines." %} |
{% endfor %}
@@ -92,4 +113,5 @@
{% block extra_js %}
+
{% endblock %}
diff --git a/circle/dashboard/templates/dashboard/vm-list/header-link.html b/circle/dashboard/templates/dashboard/vm-list/header-link.html
new file mode 100644
index 0000000..79d10c5
--- /dev/null
+++ b/circle/dashboard/templates/dashboard/vm-list/header-link.html
@@ -0,0 +1 @@
+
{{ name }}
diff --git a/circle/dashboard/views.py b/circle/dashboard/views.py
index 0e96058..b793e50 100644
--- a/circle/dashboard/views.py
+++ b/circle/dashboard/views.py
@@ -1053,7 +1053,8 @@ class TemplateList(LoginRequiredMixin, SingleTableView):
def get_context_data(self, *args, **kwargs):
context = super(TemplateList, self).get_context_data(*args, **kwargs)
- context['lease_table'] = LeaseListTable(Lease.objects.all())
+ context['lease_table'] = LeaseListTable(Lease.objects.all(),
+ request=self.request)
return context
def get_queryset(self):
@@ -1126,6 +1127,14 @@ class VmList(LoginRequiredMixin, ListView):
s = self.request.GET.get("s")
if s:
queryset = queryset.filter(name__icontains=s)
+
+ sort = self.request.GET.get("sort")
+ # remove "-" that means descending order
+ # also check if the column name is valid
+ if (sort and
+ (sort[1:] if sort[0] == "-" else sort)
+ in [i.name for i in Instance._meta.fields] + ["pk"]):
+ queryset = queryset.order_by(sort)
return queryset.select_related('owner', 'node')