mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
urls and tags list views
This commit is contained in:
@@ -2,12 +2,17 @@ from django.contrib import admin
|
||||
|
||||
from djrill.views import (DjrillIndexView, DjrillSendersListView,
|
||||
DjrillDisableSenderView, DjrillVerifySenderView,
|
||||
DjrillAddSenderView)
|
||||
DjrillAddSenderView, DjrillTagListView,
|
||||
DjrillUrlListView)
|
||||
|
||||
admin.site.register_view("djrill/senders/", DjrillSendersListView.as_view(),
|
||||
"djrill_senders", "senders")
|
||||
admin.site.register_view("djrill/status/", DjrillIndexView.as_view(),
|
||||
"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/",
|
||||
DjrillDisableSenderView.as_view(), "djrill_disable_sender")
|
||||
|
||||
9
djrill/templates/djrill/_status.html
Normal file
9
djrill/templates/djrill/_status.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<div id="changelist-filter">
|
||||
<h2>Tools & Info</h2>
|
||||
<h3>Status</h3>
|
||||
{% if status %}
|
||||
<p>Mandrill is <strong>UP</strong></p>
|
||||
{% else %}
|
||||
<p>Mandrill is <strong>DOWN</strong></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -17,6 +17,8 @@
|
||||
{{ media.js }}
|
||||
{% endblock %}
|
||||
|
||||
{% block title %} Djrill Senders | {% trans "Django site admin" %}{% endblock %}
|
||||
|
||||
{% block bodyclass %}change-list{% endblock %}
|
||||
|
||||
{% if not is_popup %}
|
||||
@@ -26,9 +28,7 @@
|
||||
{% trans "Home" %}
|
||||
</a>
|
||||
›
|
||||
<a href="../">
|
||||
Djrill
|
||||
</a>
|
||||
›
|
||||
Senders
|
||||
</div>
|
||||
@@ -56,27 +56,19 @@
|
||||
<div class="module filtered" id="changelist">
|
||||
{% block search %}
|
||||
<div id="toolbar">
|
||||
<form action="{% url "admin:djrill_add_sender" %}" method="POST">
|
||||
<form action="{% url "admin:djrill_add_sender" %}" method="POST">
|
||||
<label for="id_email" class="addlink">Add a new sender</label>
|
||||
<input type="email" placeholder="E-mail address" name="email" id="id_email">
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block date_hierarchy %}{% endblock %}
|
||||
|
||||
{% block filters %}
|
||||
<div id="changelist-filter">
|
||||
<h2>Tools & Info</h2>
|
||||
<h3>Status</h3>
|
||||
{% if status %}
|
||||
<p>Mandrill is <strong>UP</strong></p>
|
||||
{% else %}
|
||||
<p>Mandrill is <strong>DOWN</strong></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% include "djrill/_status.html" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block result_list %}
|
||||
|
||||
102
djrill/templates/djrill/tags_list.html
Normal file
102
djrill/templates/djrill/tags_list.html
Normal 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>
|
||||
›
|
||||
Djrill
|
||||
›
|
||||
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 %}
|
||||
108
djrill/templates/djrill/urls_list.html
Normal file
108
djrill/templates/djrill/urls_list.html
Normal 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>
|
||||
›
|
||||
Djrill
|
||||
›
|
||||
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 %}
|
||||
@@ -39,6 +39,18 @@ class DjrillApiMixin(object):
|
||||
raise ImproperlyConfigured("You have not added the Mandrill api "
|
||||
"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):
|
||||
"""
|
||||
@@ -46,13 +58,24 @@ class DjrillApiJsonObjectsMixin(object):
|
||||
"""
|
||||
api_uri = None
|
||||
|
||||
def get_json_objects(self):
|
||||
payload = json.dumps({"key": self.api_key})
|
||||
req = requests.post("%s/%s" % (self.api_url, self.api_uri),
|
||||
def get_api_uri(self):
|
||||
if self.api_uri is None:
|
||||
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)
|
||||
if req.status_code == 200:
|
||||
return req.content
|
||||
raise Exception("OH GOD, NO!")
|
||||
raise Exception("Mandrill did not return a 200.")
|
||||
|
||||
|
||||
class DjrillIndexView(DjrillApiMixin, TemplateView):
|
||||
@@ -75,20 +98,15 @@ class DjrillSendersListView(DjrillAdminMedia, DjrillApiMixin,
|
||||
def get(self, request):
|
||||
form = CreateSenderForm()
|
||||
objects = self.get_json_objects()
|
||||
|
||||
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
|
||||
|
||||
return self.render_to_response({
|
||||
context = self.get_context_data()
|
||||
context.update({
|
||||
"objects": json.loads(objects),
|
||||
"media": self.media,
|
||||
"form": form,
|
||||
"status": status
|
||||
"form": form
|
||||
})
|
||||
|
||||
return self.render_to_response(context)
|
||||
|
||||
|
||||
class DjrillSenderView(DjrillApiMixin, View):
|
||||
api_action = None
|
||||
@@ -130,3 +148,34 @@ class DjrillVerifySenderView(DjrillSenderView):
|
||||
class DjrillAddSenderView(DjrillVerifySenderView):
|
||||
error_message = "Sender was not 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)
|
||||
|
||||
Reference in New Issue
Block a user