Skip to content

make compatible with django 1.5 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions external_links/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-

from django.conf.urls import patterns, url
from django.contrib import admin
from django.db.models import Count
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils.translation import ugettext as _

from external_links.models import LinkClick

class LinkClickAdmin(admin.ModelAdmin):
search_fields = ('link', 'referer', 'ip_addr' )
date_hierarchy = 'date'
list_filter = ('site', )
list_display = ('link', 'referer', 'ip_addr', 'date', 'time')

change_list_template = 'external_links/change_list.html'

def has_add_permission(self, request):
return False

def top_links(self, request):
"""
This view shows the top clicked external links
"""
context = {
'objects': LinkClick.objects.values('link').annotate(Count('link')).order_by('-link__count'),
'title': _('Top clicked links'),
'app_label': self.model._meta.app_label,
'model_label': self.model._meta.verbose_name_plural,
}
return render_to_response('external_links/top_links.html',
context,
context_instance=RequestContext(request))

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
admin.site.register(LinkClick, LinkClickAdmin)

39 changes: 0 additions & 39 deletions external_links/admin/__init__.py

This file was deleted.

103 changes: 8 additions & 95 deletions external_links/templates/external_links/change_list.html
Original file line number Diff line number Diff line change
@@ -1,96 +1,9 @@
{% extends "admin/base_site.html" %}
{% load adminmedia admin_list i18n %}

{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" />
{% if cl.formset %}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />
<script type="text/javascript" src="../../jsi18n/"></script>
{% endif %}
{{ media }}
{% if not actions_on_top and not actions_on_bottom %}
<style>
#changelist table thead th:first-child {width: inherit}
</style>
{% endif %}
<style>
#top-links table { width:100% !important; }
</style>
{% endblock %}

{% block bodyclass %}change-list{% endblock %}

{% if not is_popup %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="../../">
{% trans "Home" %}
</a>
&rsaquo;
<a href="../">
{{ app_label|capfirst }}
</a>
&rsaquo;
{{ cl.opts.verbose_name_plural|capfirst }}
</div>
{% endblock %}
{% endif %}

{% block coltype %}flex{% endblock %}

{% block content %}
<div id="content-main">
{% block object-tools %}
{% if has_add_permission %}
<ul class="object-tools">
<li>
<a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
</a>
</li>
</ul>
{% endif %}
{% endblock %}
{% if cl.formset.errors %}
<p class="errornote">
{% blocktrans count cl.formset.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
</p>
<ul class="errorlist">{% for error in cl.formset.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
{% endif %}

<div class="module" id="top-links">
<table>
<caption>{% trans "Top clicked links"%}</caption>
<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>

<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
{% block search %}{% search_form cl %}{% endblock %}
{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}

{% block filters %}
{% if cl.has_filters %}
<div id="changelist-filter">
<h2>{% trans 'Filter' %}</h2>
{% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
</div>
{% endif %}
{% endblock %}

<form action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %}>
{% if cl.formset %}
{{ cl.formset.management_form }}
{% endif %}

{% block result_list %}
{% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %}
{% result_list cl %}
{% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %}
{% endblock %}
{% block pagination %}{% pagination cl %}{% endblock %}
</form>
</div>
</div>
{% extends "admin/change_list.html" %}
{% load i18n %}
{% block object-tools %}
<ul class="object-tools">
<li>
<a href="{% url 'admin:external_link_top_clicks' %}" title="{% trans "Top clicked links"%}">{% trans "Top clicked links"%}</a>
</li>
</ul>
{% endblock %}
87 changes: 30 additions & 57 deletions external_links/templates/external_links/top_links.html
Original file line number Diff line number Diff line change
@@ -1,63 +1,36 @@
{% extends "admin/base_site.html" %}
{% load adminmedia admin_list i18n %}
{% block title %}
{% trans "Top clicked links" %} {{block.super}}
{% endblock %}

{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" />
{% if cl.formset %}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />
<script type="text/javascript" src="../../jsi18n/"></script>
{% endif %}
{{ media }}
{% if not actions_on_top and not actions_on_bottom %}
<style>
#changelist table thead th:first-child {width: inherit}
</style>
{% endif %}
{% endblock %}

{% block bodyclass %}change-list{% endblock %}
{% extends "admin/change_list.html" %}
{% load i18n %}

{% if not is_popup %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="../../../">Home</a> &rsaquo;
<a href="../../">External_Links</a> &rsaquo;
<a href="../">Link clicks</a> &rsaquo;
Top links
</div>
{% endblock %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
&rsaquo; <a href="{% url 'admin:app_list' app_label=app_label %}">{{ app_label|capfirst|escape }}</a>
&rsaquo; <a href="../">{{ model_label|capfirst }}</a>
&rsaquo; {{ title }}
</div>
{% endblock %}
{% endif %}

{% block coltype %}flex{% endblock %}

{% block content %}

<h1>{% trans "Top clicked links" %}</h1>

<div id="content-main">
<div id="changelist" class="module">
<table cellspacing="0">
<thead>
<tr><th>Link</th><th>Count</th></tr>
</thead>
<tbody>

{% for link in object_list %}
<tr class="row{%cycle 1,2%}"><th><a href="../?q={{link.link|urlencode}}" title="View click
details for &quot;{{link.link}}&quot;">{{link.link}}</a></th><td>{{link.link__count}}</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% if pagination_required %}
{# how to paginate a valuesqueryset?? #}
<p class="paginator">
</p>
{% endif %}

<div id="content-main">
<div class="module">
<table id="result_list">
<thead>
<tr>
<th scope="col"><div class="text"><span>Click</span></div></th>
<th scope="col"><div class="text"><span>Link</span></div></th>
</tr>
</thead>
<tbody>
{% for obj in objects %}
<tr class="{% cycle 'row1' 'row2' %}">
<td>{{ obj.link__count }}</td>
<td><a href="../?q={{obj.link|urlencode}}" title="View click details for &quot;{{obj.link}}&quot;">{{ obj.link }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion external_links/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from django.conf.urls.defaults import url, patterns
from django.conf.urls import url, patterns

urlpatterns = patterns('external_links.views',
url(r'^$',
Expand Down