Minor fixes.
[wolnelektury.git] / src / contact / forms.py
index ff1687a..8fe0070 100644 (file)
@@ -1,3 +1,7 @@
+# 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
 from django.core.files.uploadedfile import UploadedFile
 from django.contrib.sites.models import Site
 from django.core.exceptions import ValidationError
 from django.core.files.uploadedfile import UploadedFile
@@ -25,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')
@@ -56,7 +59,7 @@ class ContactForm(forms.Form):
                     body.setdefault(f.form_tag, []).append(sub_body)
 
         contact = Contact.objects.create(
                     body.setdefault(f.form_tag, []).append(sub_body)
 
         contact = Contact.objects.create(
-            body=body,
+            body=json.dumps(body),
             ip=request.META['REMOTE_ADDR'],
             contact=self.cleaned_data['contact'],
             form_tag=self.form_tag)
             ip=request.META['REMOTE_ADDR'],
             contact=self.cleaned_data['contact'],
             form_tag=self.form_tag)
@@ -73,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:
@@ -92,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