Login

Send information mails to related staff members.

Author:
sleytr
Posted:
June 15, 2007
Language:
Python
Version:
.96
Tags:
mail permission
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. Mail logged errors to administrators by jmillikin 6 years, 11 months ago
  2. staff_or_404 Decorator by bkeating 3 years, 6 months ago
  3. Add site info to request context by bthomas 6 years, 6 months ago
  4. Sending html emails with images using Django templates by sleytr 7 years, 11 months ago
  5. Amazon's CloudFront streaming signed urls by sayane 4 years, 9 months ago

Comments

Please login first before commenting.