mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
awesomesauce
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from djrill.views import DjrillIndexView
|
||||
from djrill.views import DjrillIndexView, DjrillSendersListView
|
||||
|
||||
|
||||
admin.site.register_view("djrill", DjrillIndexView.as_view(), "Djrill")
|
||||
admin.site.register_view("djrill/senders/list", DjrillSendersListView.as_view())
|
||||
|
||||
@@ -2,7 +2,7 @@ from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.http import HttpResponse
|
||||
from django.utils import simplejson as json
|
||||
from django.views.generic import View
|
||||
from django.views.generic import View, TemplateView
|
||||
|
||||
try:
|
||||
import requests
|
||||
@@ -26,6 +26,20 @@ class DjrillApiMixin(object):
|
||||
"url to your settings.py")
|
||||
|
||||
|
||||
class DjrillApiJsonObjectsMixin(object):
|
||||
"""
|
||||
Mixin to grab json objects from the api.
|
||||
"""
|
||||
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), data=payload)
|
||||
if req.status_code == 200:
|
||||
return req.content
|
||||
raise Exception("OH GOD, NO!")
|
||||
|
||||
|
||||
class DjrillIndexView(DjrillApiMixin, View):
|
||||
|
||||
def get(self, request):
|
||||
@@ -34,3 +48,14 @@ class DjrillIndexView(DjrillApiMixin, View):
|
||||
r = requests.post("%s/users/info.json" % self.api_url, data=payload)
|
||||
|
||||
return HttpResponse(r.content)
|
||||
|
||||
|
||||
class DjrillSendersListView(DjrillApiMixin, DjrillApiJsonObjectsMixin,
|
||||
TemplateView):
|
||||
|
||||
api_uri = "users/senders.json"
|
||||
template_name = "djrill/senders_list.html"
|
||||
|
||||
def get(self, request):
|
||||
objects = self.get_json_objects()
|
||||
return self.render_to_response({"objects": objects})
|
||||
|
||||
Reference in New Issue
Block a user