urls and tags list views

This commit is contained in:
Kenneth Love
2012-02-28 14:25:28 -08:00
parent 7612856b72
commit 38a80e2b95
6 changed files with 295 additions and 30 deletions

View File

@@ -2,12 +2,17 @@ from django.contrib import admin
from djrill.views import (DjrillIndexView, DjrillSendersListView, from djrill.views import (DjrillIndexView, DjrillSendersListView,
DjrillDisableSenderView, DjrillVerifySenderView, DjrillDisableSenderView, DjrillVerifySenderView,
DjrillAddSenderView) DjrillAddSenderView, DjrillTagListView,
DjrillUrlListView)
admin.site.register_view("djrill/senders/", DjrillSendersListView.as_view(), admin.site.register_view("djrill/senders/", DjrillSendersListView.as_view(),
"djrill_senders", "senders") "djrill_senders", "senders")
admin.site.register_view("djrill/status/", DjrillIndexView.as_view(), admin.site.register_view("djrill/status/", DjrillIndexView.as_view(),
"djrill_status", "status") "djrill_status", "status")
admin.site.register_view("djrill/tags/", DjrillTagListView.as_view(),
"djrill_tags", "tags")
admin.site.register_view("djrill/urls/", DjrillUrlListView.as_view(),
"djrill_urls", "urls")
admin.site.register_url("djrill/disable/sender/", admin.site.register_url("djrill/disable/sender/",
DjrillDisableSenderView.as_view(), "djrill_disable_sender") DjrillDisableSenderView.as_view(), "djrill_disable_sender")

View File

@@ -0,0 +1,9 @@
<div id="changelist-filter">
<h2>Tools &amp; Info</h2>
<h3>Status</h3>
{% if status %}
<p>Mandrill is <strong>UP</strong></p>
{% else %}
<p>Mandrill is <strong>DOWN</strong></p>
{% endif %}
</div>

View File

@@ -17,6 +17,8 @@
{{ media.js }} {{ media.js }}
{% endblock %} {% endblock %}
{% block title %} Djrill Senders | {% trans "Django site admin" %}{% endblock %}
{% block bodyclass %}change-list{% endblock %} {% block bodyclass %}change-list{% endblock %}
{% if not is_popup %} {% if not is_popup %}
@@ -26,9 +28,7 @@
{% trans "Home" %} {% trans "Home" %}
</a> </a>
&rsaquo; &rsaquo;
<a href="../">
Djrill Djrill
</a>
&rsaquo; &rsaquo;
Senders Senders
</div> </div>
@@ -68,15 +68,7 @@
{% block date_hierarchy %}{% endblock %} {% block date_hierarchy %}{% endblock %}
{% block filters %} {% block filters %}
<div id="changelist-filter"> {% include "djrill/_status.html" %}
<h2>Tools &amp; Info</h2>
<h3>Status</h3>
{% if status %}
<p>Mandrill is <strong>UP</strong></p>
{% else %}
<p>Mandrill is <strong>DOWN</strong></p>
{% endif %}
</div>
{% endblock %} {% endblock %}
{% block result_list %} {% block result_list %}

View File

@@ -0,0 +1,102 @@
{% extends "admin/base_site.html" %}
{% load adminmedia admin_list i18n %}
{% load url from future %}
{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" />
{{ media.css }}
{% if not actions_on_top and not actions_on_bottom %}
<style>
#changelist table thead th:first-child {width: inherit}
</style>
{% endif %}
{% endblock %}
{% block extrahead %}
{{ block.super }}
{{ media.js }}
{% endblock %}
{% block title %} Djrill Tags | {% trans "Django site admin" %}{% endblock %}
{% block bodyclass %}change-list{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="../../">
{% trans "Home" %}
</a>
&rsaquo;
Djrill
&rsaquo;
Tags
</div>
{% endblock %}
{% endif %}
{% block coltype %}flex{% endblock %}
{% block content %}
<div id="content-main">
{% block object-tools %}
{% if has_add_permission %}
<ul class="object-tools">
{% block object-tools-items %}
<li>
<a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">
{% blocktrans %}Add sender{% endblocktrans %}
</a>
</li>
{% endblock %}
</ul>
{% endif %}
{% endblock %}
<div class="module filtered" id="changelist">
{% block search %} {% endblock %}
{% block date_hierarchy %}{% endblock %}
{% block filters %}
{% include "djrill/_status.html" %}
{% endblock %}
{% block result_list %}
{% if objects %}
<div class="results">
<table cellspacing="0" id="result_list">
<thead>
<tr>
<th scope="col">Tag</th>
<th scope="col">ID</th>
<th scope="col">Sent</th>
<th scope="col">Opens</th>
<th scope="col">Clicks</th>
<th scope="col">Rejects</th>
<th scope="col">Bounces</th>
<th scope="col">Complaints</th>
</tr>
</thead>
<tbody>
{% for result in objects %}
<tr class="{% cycle 'row1' 'row2' %}">
<td>{{ result.tag }}</td>
<td>{{ result.id }}</td>
<td>{{ result.sent }}</td>
<td>{{ result.opens }}</td>
<td>{{ result.clicks }}</td>
<td>{{ result.rejects }}</td>
<td>{{ result.bounces }}</td>
<td>{{ result.complaints }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% endblock %}
{% block pagination %}{% endblock %}
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,108 @@
{% extends "admin/base_site.html" %}
{% load adminmedia admin_list i18n %}
{% load url from future %}
{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" />
{{ media.css }}
{% if not actions_on_top and not actions_on_bottom %}
<style>
#changelist table thead th:first-child {width: inherit}
</style>
{% endif %}
{% endblock %}
{% block extrahead %}
{{ block.super }}
{{ media.js }}
{% endblock %}
{% block title %} Djrill URLs | {% trans "Django site admin" %}{% endblock %}
{% block bodyclass %}change-list{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="../../">
{% trans "Home" %}
</a>
&rsaquo;
Djrill
&rsaquo;
URLs
</div>
{% endblock %}
{% endif %}
{% block coltype %}flex{% endblock %}
{% block content %}
<div id="content-main">
{% block object-tools %}
{% if has_add_permission %}
<ul class="object-tools">
{% block object-tools-items %}
<li>
<a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">
{% blocktrans %}Add sender{% endblocktrans %}
</a>
</li>
{% endblock %}
</ul>
{% endif %}
{% endblock %}
<div class="module filtered" id="changelist">
{% block search %}{% endblock %}
{% block date_hierarchy %}{% endblock %}
{% block filters %}
{% include "djrill/_status.html" %}
{% endblock %}
{% block result_list %}
{% if objects %}
<div class="results">
<table cellspacing="0" id="result_list">
<thead>
<tr>
{% for header in objects.0.keys %}
<th scope="col">{{ header|capfirst }}</th>
{% endfor %}
<th></th>
</tr>
</thead>
<tbody>
{% for result in objects %}
<tr class="{% cycle 'row1' 'row2' %}">
{% for item in result.values %}
<td>{{ item }}</td>
{% endfor %}
<td>
{% if result.is_enabled and result.approved_at %}
<form method="POST" action="{% url "admin:djrill_disable_sender" %}">
{% else %}
<form method="POST" action="{% url "admin:djrill_verify_sender" %}">
{% endif %}
<input type="hidden" name="email" value="{{ result.address }}">
{% csrf_token %}
{% if result.is_enabled and result.approved_at %}
<button>disable</buton>
{% else %}
<button>enable</buton>
{% endif %}
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% endblock %}
{% block pagination %}{% endblock %}
</div>
</div>
{% endblock %}

View File

@@ -39,6 +39,18 @@ class DjrillApiMixin(object):
raise ImproperlyConfigured("You have not added the Mandrill api " raise ImproperlyConfigured("You have not added the Mandrill api "
"url to your settings.py") "url to your settings.py")
def get_context_data(self, **kwargs):
kwargs = super(DjrillApiMixin, self).get_context_data(**kwargs)
status = False
req = requests.post("%s/%s" % (self.api_url, "users/ping.json"),
data={"key": self.api_key})
if req.status_code == 200:
status = True
kwargs.update({"status": status})
return kwargs
class DjrillApiJsonObjectsMixin(object): class DjrillApiJsonObjectsMixin(object):
""" """
@@ -46,13 +58,24 @@ class DjrillApiJsonObjectsMixin(object):
""" """
api_uri = None api_uri = None
def get_json_objects(self): def get_api_uri(self):
payload = json.dumps({"key": self.api_key}) if self.api_uri is None:
req = requests.post("%s/%s" % (self.api_url, self.api_uri), raise ImproperlyConfigured(u"%(cls)s is missing an api_uri. Define "
u"%(cls)s.api_uri or override %(cls)s.get_api_uri()." % {
"cls": self.__class__.__name__
})
def get_json_objects(self, extra_dict=None, extra_api_uri=None):
request_dict = {"key": self.api_key}
if extra_dict:
request_dict.update(extra_dict)
payload = json.dumps(request_dict)
api_uri = extra_api_uri or self.api_uri
req = requests.post("%s/%s" % (self.api_url, api_uri),
data=payload) data=payload)
if req.status_code == 200: if req.status_code == 200:
return req.content return req.content
raise Exception("OH GOD, NO!") raise Exception("Mandrill did not return a 200.")
class DjrillIndexView(DjrillApiMixin, TemplateView): class DjrillIndexView(DjrillApiMixin, TemplateView):
@@ -75,20 +98,15 @@ class DjrillSendersListView(DjrillAdminMedia, DjrillApiMixin,
def get(self, request): def get(self, request):
form = CreateSenderForm() form = CreateSenderForm()
objects = self.get_json_objects() objects = self.get_json_objects()
context = self.get_context_data()
status = False context.update({
req = requests.post("%s/%s" % (self.api_url, "users/ping.json"),
data={"key": self.api_key})
if req.status_code == 200:
status = True
return self.render_to_response({
"objects": json.loads(objects), "objects": json.loads(objects),
"media": self.media, "media": self.media,
"form": form, "form": form
"status": status
}) })
return self.render_to_response(context)
class DjrillSenderView(DjrillApiMixin, View): class DjrillSenderView(DjrillApiMixin, View):
api_action = None api_action = None
@@ -130,3 +148,34 @@ class DjrillVerifySenderView(DjrillSenderView):
class DjrillAddSenderView(DjrillVerifySenderView): class DjrillAddSenderView(DjrillVerifySenderView):
error_message = "Sender was not added." error_message = "Sender was not added."
success_message = "Sender was added." success_message = "Sender was added."
class DjrillTagListView(DjrillAdminMedia, DjrillApiMixin,
DjrillApiJsonObjectsMixin, TemplateView):
api_uri = "tags/list.json"
template_name = "djrill/tags_list.html"
def get(self, request):
objects = self.get_json_objects()
context = self.get_context_data()
context.update({
"objects": json.loads(objects),
"media": self.media,
})
return self.render_to_response(context)
class DjrillUrlListView(DjrillAdminMedia, DjrillApiMixin,
DjrillApiJsonObjectsMixin, TemplateView):
api_uri = "urls/list.json"
template_name = "djrill/urls_list.html"
def get(self, request):
objects = self.get_json_objects()
context = self.get_context_data()
context.update({
"objects": json.loads(objects),
"media": self.media
})
return self.render_to_response(context)