Ejemplo n.º 1
0
def reply(request, message):
    message = get_object_or_404(Message, id=message)
    if message.recipient != request.user:
        return http.HttpResponseForbidden(_("Can't send email"))
    if request.method == 'POST':
        form = forms.ComposeForm(data=request.POST,
                                 sender=request.user.get_profile())
        if form.is_valid():
            form.save(sender=request.user)
            messages.success(request, _('Message successfully sent.'))
            return http.HttpResponseRedirect(reverse('drumbeatmail_inbox'))
        else:
            messages.error(
                request,
                _('There was an error sending your message'
                  '. Please try again.'))
    else:
        if not message.subject.startswith('Re: '):
            subject = 'Re: %s' % (message.subject, )
        else:
            subject = message.subject
        form = forms.ComposeForm(
            initial={
                'recipient': message.sender.get_profile().username,
                'subject': subject,
            })
    return render_to_response('drumbeatmail/reply.html', {
        'form': form,
        'message': message,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def compose(request, username=None):
    kwargs = {}
    if username:
        kwargs['sender'] = get_object_or_404(UserProfile, username=username)
    if request.method == 'POST':
        form = forms.ComposeForm(data=request.POST,
                                 sender=request.user.get_profile())
        if form.is_valid():
            form.save(sender=request.user)
            messages.success(request, _('Message successfully sent.'))
            return http.HttpResponseRedirect(reverse('drumbeatmail_inbox'))
        else:
            messages.error(request, _('There was an error sending your message'
                                      '. Please try again.'))
    else:
        form = forms.ComposeForm(initial={'recipient': username})
    kwargs['form'] = form
    return render_to_response('drumbeatmail/compose.html', kwargs,
                              context_instance=RequestContext(request))