Skip to content

Commit

Permalink
Break out organisation counts by approved content
Browse files Browse the repository at this point in the history
Includes organisations that have no approved content.

Closes gh-343
[Fixes #116086631]
  • Loading branch information
bennylope committed Mar 31, 2016
1 parent 51c8e32 commit 7f34b37
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 13 additions & 3 deletions orb/analytics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.contrib.auth.models import User
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.db.models import Count
from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
Expand All @@ -25,6 +26,7 @@
def home_view(request):
start_date = timezone.now() - datetime.timedelta(days=31)
end_date = timezone.now()

pending_crt_resources = Resource.objects.filter(
status=Resource.PENDING_CRT).order_by('create_date')
pending_mep_resources = Resource.objects.filter(
Expand All @@ -35,8 +37,15 @@ def home_view(request):
'resource', 'resource__slug', 'resource__title', 'resource__id').annotate(total_hits=Count('id')).order_by('-total_hits')[:10]
popular_tags = TagTracker.objects.filter(access_date__gte=start_date).values(
'tag', 'tag__slug', 'tag__name').annotate(total_hits=Count('id')).order_by('-total_hits')[:10]
organisations = Tag.objects.filter(category__slug='organisation', resourcetag__isnull=False).annotate(
total_resources=Count('resourcetag__id')).order_by('name')

organisations_approved = Tag.objects.filter(
category__slug='organisation',
resourcetag__isnull=False,
resourcetag__resource__status='Approved').annotate(
total_resources=Count('resourcetag__id')).order_by('name')

organisations_unapproved = Tag.objects.filter(category__slug='organisation').exclude(
resourcetag__resource__status='Approved').order_by('name')

snor = timezone.now() - datetime.timedelta(days=90)
searches_no_results = SearchTracker.objects.filter(access_date__gte=snor, no_results=0).values(
Expand Down Expand Up @@ -92,7 +101,8 @@ def home_view(request):
'popular_searches': popular_searches,
'popular_tags': popular_tags,
'popular_resources': popular_resources,
'organisations': organisations,
'organisations_approved': organisations_approved,
'organisations_unapproved': organisations_unapproved,
'recent_activity': recent_activity,
'searches_no_results': searches_no_results,
'user_registrations': user_registrations,
Expand Down
10 changes: 9 additions & 1 deletion orb/templates/orb/analytics/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,20 @@ <h3>{% trans 'Searches with no results (last 3 months)' %}</h3>

<a name="o" class="named-anchor"></a>
<h3>{% trans 'Organisations' %}</h3>
<h4>{% trans 'Organizations with Approved Resources' %}</h4>
<p>({% trans 'Approved content count in parentheses.' %})</p>
<ul>
{% for o in organisations %}
{% for o in organisations_approved %}
<li><a href="{% url 'orb_analytics_tag' o.id %}">{{ o.name }}
({{ o.total_resources }})</a></li>
{% endfor %}
</ul>
<h4>{% trans 'Organizations without Approved Resources' %}</h4>
<ul>
{% for o in organisations_unapproved %}
<li><a href="{% url 'orb_analytics_tag' o.id %}">{{ o.name }}</a></li>
{% endfor %}
</ul>

<a name="am" class="named-anchor"></a>
<h3>{% trans 'Activity Map' %}</h3>
Expand Down

0 comments on commit 7f34b37

Please sign in to comment.