Permalink
Browse files

Ack, shouldnt have uploaded pycs

  • Loading branch information...
jj
jj committed Sep 20, 2009
1 parent 36ee0f8 commit ea4723638872085b4b0a44753336e6046b5eb3ba
View
@@ -114,15 +114,16 @@ Regular clicks record
Simply add these lines to your admin file
from external_links.admin import LinkClickAdmin
- admin.register(LinkClickAdmin)
+ from external_links.models import LinkClick
+ admin.register(LinkClick, LinkClickAdmin)
Top clicked links
-----------------
There is also an included view to display the top 15 clicked links. To
install it simply add the following urlconf:
- # Note that it has to be before the regular admin urlconf
- url(r'^admin/', include('external_links.admin.urls')),
- url(r'^admin/(.*)', admin.root),
+ url(r'^admin/', include(admin.site.urls)),
+
+ Now you can access /admin/external_links/linkclick/top/ and will display
+ the top clicked links. You'll find a link to this on the LinkClick change_list
- Now you can access /admin/top/ and will display the top clicked links
View
Binary file not shown.
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from django.contrib import admin
+from django.db.models import Count
+from django.conf.urls.defaults import patterns, url
+from django.views.generic.list_detail import object_list
from external_links.models import LinkClick
@@ -9,3 +12,28 @@ class LinkClickAdmin(admin.ModelAdmin):
date_hierarchy = 'date'
list_filter = ('site', )
list_display = ('link', 'referer', 'ip_addr', 'date', 'time')
+
+ change_list_template = 'external_links/change_list.html'
+
+ def top_links(self, request):
+ """
+ This view shows the top clicked external links
+ """
+ summary = LinkClick.objects.values('link').annotate(
+ Count('link')).order_by('-link__count')
+
+ return object_list(request, summary,
+ template_name='external_links/top_links.html')
+
+
+ def get_urls(self):
+ urls = super(LinkClickAdmin, self).get_urls()
+ my_urls = patterns('',
+ url(r'^top/$',
+ self.admin_site.admin_view(self.top_links),
+ name='external_link_top_clicks')
+ )
+
+ return my_urls + urls
+
+
Binary file not shown.
View
Binary file not shown.
@@ -62,7 +62,7 @@
<div class="module" id="top-links">
<table>
<caption>{% trans "Top clicked links"%}</caption>
- <tbody><tr><th><a href="{% url external_link_top_links %}" title="{% trans "Top clicked links"%}">{% trans "Top clicked links"%}</a></th><td></td><td></td></tr></tbody>
+ <tbody><tr><th><a href="top/" title="{% trans "Top clicked links"%}">{% trans "Top clicked links"%}</a></th><td></td><td></td></tr></tbody>
</table>
</div>
Binary file not shown.
@@ -18,6 +18,10 @@ def external(link):
"""
Replaces an external link with a redirect to
keep track of the clicked link
+
+ To be used as:
+ {% external "http://google.com/" %}
+
"""
redirect_endpoint = reverse('external_link')
params = urlencode({'link': link})
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit ea47236

Please sign in to comment.