Beispiel #1
0
def email_template_create(request):
    if request.method == 'POST':
        form = EMailTemplateForm(request.POST)
        if form.is_valid():
            et = EMailTemplate()
            et.name = form.cleaned_data['name']
            et.open_for_import = form.cleaned_data['open_for_import']
            et.save()
            logging.info('new email template: %s'%et)
            return redirect('..')
    else:
        form = EMailTemplateForm()
 
    return render_to_response('emails/email_template_create.html', RequestContext(request, { 'form' : form }))
Beispiel #2
0
def email_template_test_send(request, template_id):
    et = EMailTemplate.get_by_id(int(template_id))
    if et  is None:
        raise Http404

    if request.method == 'POST':
        form = EMailAddressForm(request.POST)
        if form.is_valid():
            to_a = form.cleaned_data['address']
            logging.info('test send template id %d, to: %s', et.key().id(), to_a)
            
            try:
                email = EmailMessage(et.data)
                email.sender = getConfig('DEFAULT_SENDER')
                email.to = to_a
                email.check_initialized()

                if getConfigBool("ENABLE_MAIL_TEST",False):
                    logging.info('sending...')
                    email.send()
                else:
                    logging.info('disabled')
        

            except:
                logging.info("can't init email! %s"%sys.exc_info()[1])
                return HttpResponse("can't init email - %s"%sys.exc_info()[1])


            return redirect('..')
    else:
        form = EMailAddressForm()
 
    return render_to_response('emails/email_template_test_send.html', RequestContext(request, { 'form' : form, 'et':et}))
Beispiel #3
0
def email_job_create(request):
    email_groups = EMailList.all()
    email_templates = EMailTemplate.all()


    if request.method == 'POST':
        form = EMailJobCreateForm(request.POST,email_groups=email_groups, email_templates=email_templates)
        if form.is_valid():
            logging.info('creating new job request')
            el = EMailList.get(form.cleaned_data['email_group_id'])
            if el is None:
                raise Http404
            et = EMailTemplate.get(form.cleaned_data['email_template_id'])
            if et is None:
                raise Http404

            job = EMailJob()
            job.name = "'%s' -> '%s'"%(et.name,el.name)
            job.save()

            job_data = EMailJobData(parent=job)             
            job_data.sender = getConfig('DEFAULT_SENDER')
            job_data.split_count = getConfigInt('MAIL_SPLIT_COUNT',10)
            job_data.emails = el.emails
            job_data.data =  et.data

            job_data.save()
            job.data_ref = job_data.key()
            job.save()

            logging.info('new job: %s'%job)

            taskqueue.add(url='/tasks/prepare_email_job/%d/'%job.key().id(), method='GET')

            return redirect('..')
    else:
        form = EMailJobCreateForm(email_groups=email_groups, email_templates=email_templates)

    return render_to_response('emails/email_job_create.html', RequestContext(request, { 'form': form}))
Beispiel #4
0
def email_template_edit(request, template_id):
    et = EMailTemplate.get_by_id(int(template_id))
    if et  is None:
        raise Http404
    
    if request.method == 'POST':
        form = EMailTemplateForm(request.POST)
        if form.is_valid():
            et.name = form.cleaned_data['name']
            et.open_for_import = form.cleaned_data['open_for_import']
            et.save()
            return redirect('../..')
    else:
        form = EMailTemplateForm(instance=et)
    return render_to_response('emails/email_template_edit.html', RequestContext(request, { 'form' : form}))
Beispiel #5
0
def process_incoming_email_template(template_id, data):
    logging.info('processing incoming email template')
    et = EMailTemplate.get_by_id(int(template_id))
    if et is None:
        logging.info('template not found')
        return

    if not et.open_for_import:
        logging.info('template is not open')
        return

    et.data = data
    et.open_for_import = False

    et.save()

    logging.info('template updated and closed')
Beispiel #6
0
def email_template_show(request, template_id):
    et = EMailTemplate.get_by_id(int(template_id))
    if et is None:
        raise Http404
    return render_to_response('emails/email_template_show.html', RequestContext(request, { 'et': et}))