1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-09 22:38:19 +02:00
django-mailbox/django_mailbox/admin.py

71 lines
2.1 KiB
Python
Raw Normal View History

import logging
2012-06-27 20:45:01 -07:00
from django.conf import settings
from django.contrib import admin
2013-01-15 12:21:49 +00:00
from django_mailbox.models import MessageAttachment, Message, Mailbox
from django_mailbox.signals import message_received
logger = logging.getLogger(__name__)
2012-06-27 20:45:01 -07:00
def get_new_mail(mailbox_admin, request, queryset):
for mailbox in queryset.all():
logger.debug('Receiving mail for %s' % mailbox)
2012-06-27 20:45:01 -07:00
mailbox.get_new_mail()
get_new_mail.short_description = 'Get new mail'
def resend_message_received_signal(message_admin, request, queryset):
for message in queryset.all():
logger.debug('Resending \'message_received\' signal for %s' % message)
message_received.send(sender=message_admin, message=message)
resend_message_received_signal.short_description = 'Re-send message received signal'
2012-06-27 20:45:01 -07:00
class MailboxAdmin(admin.ModelAdmin):
list_display = (
'name',
'uri',
'from_email',
'active',
2012-06-27 20:45:01 -07:00
)
actions = [get_new_mail]
2013-01-15 12:21:49 +00:00
class MessageAttachmentAdmin(admin.ModelAdmin):
raw_id_fields = ('message', )
list_display = ('message', 'document',)
class MessageAttachmentInline(admin.TabularInline):
model = MessageAttachment
extra = 0
2013-01-15 12:21:49 +00:00
2012-06-27 20:45:01 -07:00
class MessageAdmin(admin.ModelAdmin):
def attachment_count(self, msg):
return msg.attachments.count()
inlines = [
MessageAttachmentInline,
]
2012-06-27 20:45:01 -07:00
list_display = (
'subject',
'processed',
'read',
2012-06-27 20:45:01 -07:00
'mailbox',
'outgoing',
'attachment_count',
)
ordering = ['-processed']
list_filter = (
'mailbox',
'outgoing',
'processed',
'read',
)
raw_id_fields = (
'in_reply_to',
2012-06-27 20:45:01 -07:00
)
actions = [resend_message_received_signal]
2012-06-27 20:45:01 -07:00
if getattr(settings, 'DJANGO_MAILBOX_ADMIN_ENABLED', True):
admin.site.register(Message, MessageAdmin)
admin.site.register(MessageAttachment, MessageAttachmentAdmin)
2012-06-27 20:45:01 -07:00
admin.site.register(Mailbox, MailboxAdmin)