Ejemplo n.º 1
0
    def form_valid(self, form):
        try:
            self.send_email(form)
        except EmailThrottled:
            errors = form._errors.setdefault('__all__', ErrorList())
            errors.append(ugettext("You are only allowed to send {0} messages"
                                   " per minute and {1} per hour.")
                .format(self.messages_per_minute, self.messages_per_hour))
            log = ContactLog(date=datetime.now(), status='T',
                ip=self.request.META.get('REMOTE_ADDR', '0.0.0.0'))
            log.save()
            return self.form_invalid(form)

        return super(ContactView, self).form_valid(form)
Ejemplo n.º 2
0
    def send_email(self, form):
        if not self.sending_allowed(form):
            raise EmailThrottled

        connection = get_connection(fail_silently=False)

        email = EmailMessage(
            subject=self.get_subject(form),
            body=self.get_body(form),
            from_email=self.get_from_email(form),
            to=self.get_recipients(form),
            headers=self.get_headers(form),
            connection=connection
        )
        sent = email.send()

        if sent:
            log = ContactLog(date=datetime.now(), status='S',
                ip=self.request.META.get('REMOTE_ADDR', '0.0.0.0'))
            log.save()