Commit 4444e2b1 by Szabolcs Gelencser

Implement favorite vms on index page

parent ebb4929a
No preview for this file type
......@@ -37,7 +37,7 @@
<small class="text-muted index-vm-list-host">
{{ i.short_hostname }}
</small>
<div class="pull-right dashboard-vm-favourite" data-vm="{{ i.pk }}">
<div class="pull-right dashboard-vm-favourite" data-vm="{{ i.id }}">
{% if i.fav %}
<i class="fa fa-star text-primary title-favourite" title="{% trans "Unfavourite" %}"></i>
{% else %}
......
......@@ -20,7 +20,7 @@ import logging
import openstack_api
from braces.views import LoginRequiredMixin
from dashboard.models import GroupProfile
from dashboard.models import GroupProfile, Favourite
from django.conf import settings
from django.contrib.auth.models import Group, User
from django.core.cache import cache
......@@ -44,24 +44,21 @@ class IndexView(LoginRequiredMixin, TemplateView):
instances = openstack_api.nova.server_list(self.request)[0] #TODO: flatten?
quotas = openstack_api.nova.tenant_quota_get(self.request, user.project_id)
# instances
favs = [f.instance for f in Favourite.objects.filter(user=user.id)]
fav_instances = [
i for i in instances if i.id in favs
]
display = list(fav_instances) + list(set(instances) - set(fav_instances))
for d in display:
d.fav = True if d in fav_instances else False
context.update({
'instances': instances[:5],
'instances': display[:5],
'more_instances': len(instances) - len(instances[:5]),
'max_instances': quotas.get("instances").limit
})
# instances
# favs = Instance.objects.filter(favourite__user=self.request.user)
# instances = Instance.get_objects_with_level(
# 'user', user, disregard_superuser=True).filter(destroyed_at=None)
# display = list(favs) + list(set(instances) - set(favs))
# for d in display:
# d.fav = True if d in favs else False
# context.update({
# 'instances': display[:5],
# 'more_instances': instances.count() - len(instances[:5])
# })
running = [i for i in instances if i.status == "ACTIVE"]
stopped = [i for i in instances if i.status != "ACTIVE"]
......
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