示例#1
0
def send(request):
    """
    Send the email to the current in-cache query, and redirect out
    """
    if request.method == 'POST':
        form = EmailForm(request.POST)

        if form.is_valid():  # should always be true..!!!

            sender = '"%s" <%s>' % (form.cleaned_data['sendername'],
                                    form.cleaned_data['senderemail'])

            terms = request.session.get('profilequery', [])
            recipients = build_profile_query(terms)

            emails = []
            for r in recipients:
                emails.append(r.user.email)

            send_mail(subject=form.cleaned_data['subject'],
                      txtMessage=None,
                      htmlMessage=form.cleaned_data['body'],
                      fromemail=sender,
                      recipients=emails,
                      use_template=False)

            request.user.message_set.create(message='Email sent')
            return HttpResponseRedirect(reverse('profile_query'))

    else:
        return Http404()
示例#2
0
def preview(request):
    """
    Preview email - including HTML body, and ability to edit email
    """
    if request.method == 'POST':
        form = EmailForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data
        else:
            data = None

        terms = request.session.get('profilequery', [])
        parsed_terms = []
        for id, term in enumerate(terms):
            # parse to human-readable format
            parsed_terms.append(parse_profile_term(term, id))

        recipients = build_profile_query(terms).count()

        return render_to_response("profile_query/email_preview.html", {
            'form': form,
            'terms': parsed_terms,
            'data': data,
            'recipients': recipients
        },
                                  context_instance=RequestContext(request))

    else:
        return Http404()
示例#3
0
文件: email.py 项目: adamfk/myewb2
def send(request):
    """
    Send the email to the current in-cache query, and redirect out
    """
    if request.method == 'POST':
        form = EmailForm(request.POST)
        
        if form.is_valid():     # should always be true..!!!
            
            sender = '"%s" <%s>' % (form.cleaned_data['sendername'],
                                    form.cleaned_data['senderemail'])
    
            terms = request.session.get('profilequery', [])
            recipients = build_profile_query(terms)
            
            emails = []
            for r in recipients:
                emails.append(r.user.email)

            send_mail(subject=form.cleaned_data['subject'],
                      txtMessage=None,
                      htmlMessage=form.cleaned_data['body'],
                      fromemail=sender,
                      recipients=emails,
                      use_template=False)

            request.user.message_set.create(message='Email sent')
            return HttpResponseRedirect(reverse('profile_query'))
        
    else:
        return Http404()
示例#4
0
文件: email.py 项目: adamfk/myewb2
def preview(request):
    """
    Preview email - including HTML body, and ability to edit email
    """
    if request.method == 'POST':
        form = EmailForm(request.POST)
        
        if form.is_valid():
            data = form.cleaned_data
        else:
            data = None
            
        terms = request.session.get('profilequery', [])
        parsed_terms = []
        for id, term in enumerate(terms):
            # parse to human-readable format
            parsed_terms.append(parse_profile_term(term, id))
            
        recipients = build_profile_query(terms).count()

        return render_to_response("profile_query/email_preview.html",
                                  {'form': form,
                                   'terms': parsed_terms,
                                   'data': data,
                                   'recipients': recipients},
                                   context_instance=RequestContext(request))
            
        
    else:
        return Http404()
示例#5
0
def compose(request):
    """
    Display new email form
    """
    if request.method == 'POST':
        form = EmailForm(request.POST)
    else:
        form = EmailForm()

    terms = request.session.get('profilequery', [])
    parsed_terms = []
    for id, term in enumerate(terms):
        # parse to human-readable format
        parsed_terms.append(parse_profile_term(term, id))

    return render_to_response("profile_query/email_compose.html", {
        'form': form,
        'terms': parsed_terms
    },
                              context_instance=RequestContext(request))