Minor fixes.
[wolnelektury.git] / src / contact / forms.py
index ee44e4b..8fe0070 100644 (file)
@@ -1,3 +1,6 @@
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
 import json
 from django.contrib.sites.models import Site
 from django.core.exceptions import ValidationError
 import json
 from django.contrib.sites.models import Site
 from django.core.exceptions import ValidationError
@@ -26,9 +29,8 @@ class ContactFormMeta(forms.Form.__class__):
         return model
 
 
         return model
 
 
-class ContactForm(forms.Form):
+class ContactForm(forms.Form, metaclass=ContactFormMeta):
     """Subclass and define some fields."""
     """Subclass and define some fields."""
-    __metaclass__ = ContactFormMeta
 
     form_tag = None
     form_title = _('Contact form')
 
     form_tag = None
     form_title = _('Contact form')
@@ -74,15 +76,14 @@ class ContactForm(forms.Form):
             'site_domain': getattr(self, 'site_domain', site.domain),
             'contact': contact,
         }
             'site_domain': getattr(self, 'site_domain', site.domain),
             'contact': contact,
         }
-        context = RequestContext(request)
         mail_managers_subject = render_to_string([
                 'contact/%s/mail_managers_subject.txt' % self.form_tag,
                 'contact/mail_managers_subject.txt', 
         mail_managers_subject = render_to_string([
                 'contact/%s/mail_managers_subject.txt' % self.form_tag,
                 'contact/mail_managers_subject.txt', 
-            ], dictionary, context).strip()
+            ], dictionary, request).strip()
         mail_managers_body = render_to_string([
                 'contact/%s/mail_managers_body.txt' % self.form_tag,
                 'contact/mail_managers_body.txt', 
         mail_managers_body = render_to_string([
                 'contact/%s/mail_managers_body.txt' % self.form_tag,
                 'contact/mail_managers_body.txt', 
-            ], dictionary, context)
+            ], dictionary, request)
         mail_managers(mail_managers_subject, mail_managers_body, fail_silently=True)
 
         try:
         mail_managers(mail_managers_subject, mail_managers_body, fail_silently=True)
 
         try:
@@ -93,19 +94,19 @@ class ContactForm(forms.Form):
             mail_subject = render_to_string([
                     'contact/%s/mail_subject.txt' % self.form_tag,
                     'contact/mail_subject.txt', 
             mail_subject = render_to_string([
                     'contact/%s/mail_subject.txt' % self.form_tag,
                     'contact/mail_subject.txt', 
-                ], dictionary, context).strip()
+                ], dictionary, request).strip()
             if self.result_page:
                 mail_body = render_to_string(
                     'contact/%s/results_email.txt' % contact.form_tag,
                     {
                         'contact': contact,
                         'results': self.results(contact),
             if self.result_page:
                 mail_body = render_to_string(
                     'contact/%s/results_email.txt' % contact.form_tag,
                     {
                         'contact': contact,
                         'results': self.results(contact),
-                    }, context)
+                    }, request)
             else:
                 mail_body = render_to_string([
                         'contact/%s/mail_body.txt' % self.form_tag,
                         'contact/mail_body.txt',
             else:
                 mail_body = render_to_string([
                         'contact/%s/mail_body.txt' % self.form_tag,
                         'contact/mail_body.txt',
-                    ], dictionary, context)
+                    ], dictionary, request)
             send_mail(mail_subject, mail_body, 'no-reply@%s' % site.domain, [contact.contact], fail_silently=True)
 
         return contact
             send_mail(mail_subject, mail_body, 'no-reply@%s' % site.domain, [contact.contact], fail_silently=True)
 
         return contact