Login

Send information mails to related staff members.

Author:
sleytr
Posted:
June 15, 2007
Language:
Python
Version:
.96
Score:
0 (after 0 ratings)

You can use this method to send information mails to the related staff members about section specific site activity. All users which explicitly permitted to 'change' given object will be informed about activity.

If you defined get_absolute_url in your model then you can simply use it like this;

` obj=form.save()

mail2perm(obj) `

Or you can define your custom urls ;

from util.mail2perm import mail2perm,domain reply=get_object_or_404(Reply,user=request.user,pk=id) mail2perm(reply,url='http://%s/admin/support/show/?id=%s'%(domain,reply.id))

 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. Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
  5. Help text hyperlinks by sa2812 11 months, 3 weeks ago

Comments

Please login first before commenting.