]> git.parisson.com Git - teleforma.git/commitdiff
Fixed register form
authorGael Le Mignot <gael@pilotsystems.net>
Thu, 3 Jun 2021 08:10:46 +0000 (10:10 +0200)
committerGael Le Mignot <gael@pilotsystems.net>
Thu, 3 Jun 2021 08:10:46 +0000 (10:10 +0200)
teleforma/forms.py
teleforma/models/crfpa.py
teleforma/views/core.py

index 777faa71a91d84d50f345a7882d1b7eef35c6dfe..e979d5c1f5107a5a40c0348e417bc7663c2a37e4 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 import datetime
-from io import StringIO
+from io import BytesIO
 
 from captcha.fields import CaptchaField
 from django import forms
@@ -150,8 +150,10 @@ class UserForm(ModelForm):
         # resize image
         img = Image.open(image.file)
         new_image = img.resize((NEW_WIDTH, NEW_HEIGHT), Image.ANTIALIAS)
+        if new_image.mode == "RGBA":
+            new_image = new_image.convert("RGB")
 
-        temp = StringIO()
+        temp = BytesIO()
         new_image.save(temp, 'jpeg')
         temp.seek(0)
         return SimpleUploadedFile('temp', temp.read())
index 3ae5f7db93d877e6543cbb843b393bde08bd4bdb..612630fb8e5ad2c451286b89b230b5a3498221c3 100755 (executable)
@@ -182,8 +182,9 @@ class Student(models.Model):
         _('registration date'), auto_now_add=True, null=True, blank=True)
     date_subscribed = models.DateTimeField(
         _('subscription date'), null=True, blank=True)
-    is_subscribed = models.BooleanField(_('subscribed'))
-    confirmation_sent = models.BooleanField(_('confirmation sent'))
+    is_subscribed = models.BooleanField(_('subscribed'), default=False)
+    confirmation_sent = models.BooleanField(_('confirmation sent'),
+                                            default=False)
     level = models.CharField(_('studying level'), blank=True, max_length=100)
 
     balance = models.FloatField(
@@ -313,7 +314,7 @@ class Profile(models.Model):
     telephone = models.CharField(_('Telephone'), max_length=255, blank=True)
     expiration_date = models.DateField(
         _('Expiration_date'), blank=True, null=True)
-    init_password = models.BooleanField(_('Password initialized'))
+    init_password = models.BooleanField(_('Password initialized'), default=False)
     wifi_login = models.CharField(_('WiFi login'), max_length=255, blank=True)
     wifi_pass = models.CharField(_('WiFi pass'), max_length=255, blank=True)
     birthday = models.DateField(
index 9290b476f6ed80614827724587f219db26941b78..a4c9807816baf9372b8f93b5d5a353d9fcb74687 100644 (file)
@@ -37,7 +37,7 @@ import datetime
 import mimetypes
 import os
 from html import escape
-from io import StringIO
+from io import BytesIO
 from teleforma.utils import guess_mimetypes
 
 from django.conf import settings
@@ -195,7 +195,7 @@ def content_to_pdf(content, dest, encoding='utf-8', **kwargs):
     Write into *dest* file object the given html *content*.
     Return True if the operation completed successfully.
     """
-    src = StringIO(content.encode(encoding))
+    src = BytesIO(content.encode(encoding))
     pdf = pisa.pisaDocument(src, dest, encoding=encoding, **kwargs)
     return not pdf.err
 
@@ -204,7 +204,7 @@ def content_to_response(content, filename=None):
     """
     Return a pdf response using given *content*.
     """
-    response = HttpResponse(content, mimetype='application/pdf')
+    response = HttpResponse(content, content_type='application/pdf')
     if filename is not None:
         response['Content-Disposition'] = 'attachment; filename=%s' % filename
     return response
@@ -215,11 +215,8 @@ def render_to_pdf(request, template, context, filename=None, encoding='utf-8',
     """
     Render a pdf response using given *request*, *template* and *context*.
     """
-    if not isinstance(context, Context):
-        context = RequestContext(request, context)
-
-    content = loader.render_to_string(template, context)
-    buffer = StringIO()
+    content = loader.render_to_string(template, context, request = request)
+    buffer = BytesIO()
 
     succeed = content_to_pdf(content, buffer, encoding, **kwargs)
     if succeed: