Send information mails to related staff members.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -*- coding: utf-8 -*-

from django.conf import settings
from django.contrib.auth.models import Permission
from django.contrib.sites.models import Site
from django.core.mail import send_mail

domain=Site.objects.filter(pk=1).values('domain')[0]['domain']

def mail2perm(obj, url='', pre='', msg='', perm='change', sender=settings.DEFAULT_FROM_EMAIL, sbj=''):
   if not msg:
      if not url:
         try: url=obj.get_absolute_url()
         except: pass
      if url:url='\n\nClick on the link to see details:\n\n http://%s%s' % (domain,url)
      msg='%s%s'  % ( (pre or sbj) , url )

   perm=Permission.objects.filter(codename='%s_%s'%(perm,obj._meta.module_name), content_type__app_label=obj._meta.app_label).get()

   recips=[]
   for user in perm.user_set.all():
      if user.email: recips.append(user.email)

   send_mail((sbj or 'New '+ obj._meta.verbose_name), msg, sender, recips)

More like this

  1. Sending html emails with images using Django templates by sleytr 5 years, 11 months ago
  2. simple DomainsAliasMiddleware by matrix 4 years, 1 month ago
  3. Url filter middleware by limodou 6 years, 2 months ago
  4. staff_or_404 Decorator by bkeating 1 year, 6 months ago
  5. Add site info to request context by bthomas 4 years, 6 months ago

Comments

(Forgotten your password?)