Skip to content

Commit

Permalink
My services on dashboard fixes (#2877)
Browse files Browse the repository at this point in the history
* show only active services
* order by content_type_id to properly group objects (regroup require data to be sorted)
  • Loading branch information
mkurek committed Nov 30, 2016
1 parent db27453 commit a59b8bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Expand Up @@ -29,7 +29,7 @@ <h2>{% trans "My services" %}</h2>
</a>
</td>
<td>
{% regroup service_env.baseobject_set.all by content_type as content_types %}
{% regroup service_env.baseobject_set.all by content_type_id as content_types %}
{% for type in content_types %}
<ul>
<li>{% get_objects_summary service_env type.grouper type.list %}</li>
Expand Down
20 changes: 15 additions & 5 deletions src/ralph/admin/templatetags/dashboard_tags.py
Expand Up @@ -3,12 +3,13 @@
from itertools import cycle

from django.apps import apps
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db.models import Count, Sum
from django.db.models import Count, Prefetch, Sum
from django.template import Library
from django.utils.text import slugify

from ralph.assets.models.assets import Service
from ralph.assets.models import BaseObject, Service, ServiceEnvironment
from ralph.data_center.models import (
DataCenter,
DataCenterAsset,
Expand Down Expand Up @@ -116,16 +117,25 @@ def ralph_summary():
def my_services(user):
return {
'services': Service.objects.prefetch_related(
Prefetch(
'serviceenvironment_set',
queryset=ServiceEnvironment.objects.prefetch_related(
Prefetch(
'baseobject_set',
queryset=BaseObject.objects.order_by('content_type_id')
)
)
),
'serviceenvironment_set__environment',
'serviceenvironment_set__baseobject_set__content_type'
).filter(technical_owners=user),
).filter(technical_owners=user, active=True),
'user': user
}


@register.inclusion_tag('admin/templatetags/objects_summary.html')
def get_objects_summary(service_env, content_type, objects):
def get_objects_summary(service_env, content_type_id, objects):
from django.core.urlresolvers import reverse
content_type = ContentType.objects.get_for_id(content_type_id)
opts = content_type.model_class()._meta
url = reverse(
'admin:{}_{}_changelist'.format(opts.app_label, opts.model_name)
Expand Down

0 comments on commit a59b8bd

Please sign in to comment.