Note that there are some explanatory texts on larger screens.

plurals
  1. POSend email when user creates a directory
    primarykey
    data
    text
    <p>I have an filemanager application and I want some specific admin users to be notified when "baseusers" create directories. Mails are sent to users defined in admin pages. The optimal solution would be to have a checkbox in my profile pages for getting notifications but I would like to get this to work first. Here is my simple solution:</p> <pre> from django.core.mail import send_mail, BadHeaderError from basedraft.sendmail.views import send_email from django.core.signals import request_finished @permission_required('fileman.can_fm_add') def createDir(request, path=None): if path is None: return HttpResponse(_(u"Path does not set.")) try: path = toString(path) os.mkdir(path) except Exception, msg: return raise_error(request, [str(msg)]) createHistory(request.user, "createdir", toString(path)) # Added this to history, added createdir to models # Send mail to recipients when a directory is created send_email(toString(path)) return HttpResponseRedirect('/fm/list/%s' % path) </pre> <p>Problem here is that the site hangs until the mail is sent. I tried using signals like so:</p> <pre> from django.core.mail import send_mail, BadHeaderError from basedraft.sendmail.views import send_email from django.core.signals import request_finished @permission_required('fileman.can_fm_add') def createDir(request, path=None): if path is None: return HttpResponse(_(u"Path does not set.")) try: path = toString(path) os.mkdir(path) except Exception, msg: return raise_error(request, [str(msg)]) createHistory(request.user, "createdir", toString(path)) # Added this to history, added createdir to models # Send mail to recipients when a directory is created #send_email(toString(path)) request_finished.connect(mail_callback) return HttpResponseRedirect('/fm/list/%s' % path) def mail_callback(sender, **kwargs): #path = setPath send_email('test') </pre> <p>But this just started sending alot of emails for every finished request. Any ideas how I should do this, if there is a way so that the site won't be hanging but the sending of email is done in the background?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload