Skip to content

Instantly share code, notes, and snippets.

@mdaizovi
mdaizovi / content_extras.py
Created July 25, 2019 19:57
Overriding the django admin template to create Back/Forward (or Next/Previous) buttons (2 of 2)
from django import template
from django.contrib.admin.views.main import PAGE_VAR
from django.utils.html import format_html
register = template.Library()
DOT = "."
@register.simple_tag
@mdaizovi
mdaizovi / pagination.html
Last active July 25, 2019 19:55
Overriding the django admin template to create Back/Forward (or Next/Previous) buttons (1 of 2)
<!-- templates/admin/pagination.html -->
{% load admin_list %}
{% load i18n %}
{% load content_extras %}
<p class="paginator">
{% if pagination_required %}
{% for i in page_range %}
{% if forloop.first %}
{% back_url cl i %}
{% extends 'admin/change_form.html' %}
{% block submit_buttons_bottom %}
<input type="submit" value="Send Email" name="_send_email">
</div>
{{ block.super }}
{% endblock %}
@mdaizovi
mdaizovi / admin.py
Last active January 12, 2019 19:55
class MessageEventAdmin(admin.ModelAdmin):
#...
def response_change(self, request, obj):
if "_send_email" in request.POST:
message_text = str(obj.msg_text)
if obj.msg_html:
email = EmailMultiAlternatives(
subject=obj.msg_subject,
body=message_text,
to=[obj.msg_envelope_recipient],
from django.conf import settings
from django.core.mail import EmailMessage
from django.dispatch import receiver
from django.utils import timezone
from anymail.signals import inbound
@receiver(inbound)
def handle_inbound(sender, event, esp_name, **kwargs):
"""Very basic mail forwarding. Ignores attachments."""
class MessageEvent(models.Model):
"""Wrapper around Anymail's inbound events, for sending and forwarding messages.
Assumes you've already installed anymail.
Ignores attachments.
"""
# event_... will only have values if was received by ESP, and even then, probably not.
event_event_id = models.CharField(max_length=100, null=True, blank=True)
event_timestamp = models.DateTimeField(null=True, blank=True)
event_esp_event = models.CharField(max_length=100, null=True, blank=True)