# -*- coding: utf-8 -*-
import datetime
-from io import StringIO
+from io import BytesIO
from captcha.fields import CaptchaField
from django import forms
#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):
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(
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
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
"""
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
"""
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: