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