]> 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)
committerYoan Le Clanche <yoanl@pilotsystems.net>
Wed, 12 Apr 2023 09:45:56 +0000 (11:45 +0200)
teleforma/forms.py
teleforma/models/crfpa.py
teleforma/views/core.py

index 0b0dd2259f2063f2aba22d670723b8e42ba71379..358ca36b0060349fdb901cdf52ed0109eaa69ec7 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
@@ -139,14 +139,16 @@ if settings.TELEFORMA_E_LEARNING_TYPE != 'AE':
             #if width < NEW_WIDTH or height < NEW_HEIGHT:
             #    raise ValidationError({'portrait': "L'image est trop petite. Elle doit faire au moins %spx de large et %spx de hauteur." % (NEW_WIDTH, NEW_HEIGHT)})
 
-            # resize image
-            img = Image.open(image.file)
-            new_image = img.resize((NEW_WIDTH, NEW_HEIGHT), Image.ANTIALIAS)
+        # 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()
-            new_image.save(temp, 'jpeg')
-            temp.seek(0)
-            return SimpleUploadedFile('temp', temp.read())
+        temp = BytesIO()
+        new_image.save(temp, 'jpeg')
+        temp.seek(0)
+        return SimpleUploadedFile('temp', temp.read())
 
         def save(self, commit=True):
 
index 3e2cbea42ac1daf47d81d300e13db17d37b53913..01c112536028007c8ae9c788e69dfca2a8f2c42f 100755 (executable)
@@ -211,7 +211,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 f8bfb28fc189cfb00d77766be0896be67b541669..31d416869f5a598b493b7a2380a132e894daeaff 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 jsonrpc import jsonrpc_method
@@ -211,7 +211,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
 
@@ -220,7 +220,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
@@ -231,11 +231,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: