Beispiel #1
0
    def send(self):
        ctx = {
            'message': escape_html(self.cleaned_data['body']),
            'profile': self.request.profile,
            'hide_signature': True,
        }

        if not self.request.profile:
            ctx['name'] = self.cleaned_data['name']
            ctx['email'] = self.cleaned_data['email']

        send_email(None, u'[ОБРАТНАЯ СВЯЗЬ]', 'letters/feedback.html', ctx, 'feedback', 'noreply')
Beispiel #2
0
@authenticated_ajax_post
def send_message(request):
    form = MessageForm(request.POST)

    # TODO: what happens if title in post data is longer than model field max_length?
    if not form.is_valid():
        # TODO: show error messages u'Необходимо указать тему письма', u'Сообщение не должно быть пустым'
        return HttpResponse('Форма заполнена неверно')

    try:
        recipient_id = int(request.POST.get('id', ''))
        recipient = Profile.objects.select_related('user').get(id=recipient_id)
    except ValueError, Profile.DoesNotExist:
        return HttpResponse(u'Получатель указан неверно')

    title = escape_html(form.cleaned_data['title'])
    body = escape_html(form.cleaned_data['body'])
    show_email = form.cleaned_data['show_email']

    subject = u'Пользователь %s написал вам сообщение' % unicode(request.profile)
    ctx = {
        'title': title,
        'body': body,
        'show_email': show_email,
        'sender': request.profile,
    }
    send_email(recipient, subject, 'letters/message.html', ctx, 'message', 'noreply',
            reply_to=request.profile.user.email if show_email else None)

    Message.objects.create(sender=request.profile, receiver=recipient, title=title,
            body=body, show_email=show_email)