Skip to content

Instantly share code, notes, and snippets.

Mic mdaizovi

Block or report user

Report or block mdaizovi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mdaizovi
mdaizovi / content_extras.py
Created Jul 25, 2019
Overriding the django admin template to create Back/Forward (or Next/Previous) buttons (2 of 2)
View content_extras.py
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 Jul 25, 2019
Overriding the django admin template to create Back/Forward (or Next/Previous) buttons (1 of 2)
View pagination.html
<!-- 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 %}
View change_form.html
{% extends 'admin/change_form.html' %}
{% block submit_buttons_bottom %}
<input type="submit" value="Send Email" name="_send_email">
</div>
{{ block.super }}
{% endblock %}
View admin.py
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],
View mailforward.models.py
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."""
View mailforward.models.py
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)
You can’t perform that action at this time.