From: Gael Le Mignot Date: Thu, 3 Jun 2021 08:10:46 +0000 (+0200) Subject: Fixed register form X-Git-Tag: 2.8.1-ae~47 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=93f7bcfd3e13366aa03dff01b1f04db7c13fb2e9;p=teleforma.git Fixed register form --- diff --git a/teleforma/forms.py b/teleforma/forms.py index 0b0dd225..358ca36b 100644 --- a/teleforma/forms.py +++ b/teleforma/forms.py @@ -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): diff --git a/teleforma/models/crfpa.py b/teleforma/models/crfpa.py index 3e2cbea4..01c11253 100755 --- a/teleforma/models/crfpa.py +++ b/teleforma/models/crfpa.py @@ -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( diff --git a/teleforma/views/core.py b/teleforma/views/core.py index f8bfb28f..31d41686 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -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: