From e853124bf2825ed77589387787d8156a95fee534 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Wed, 14 Jun 2017 02:08:54 +0200 Subject: [PATCH] FIx in sessions and added resize in imagefield --- paramecio/citoplasma/sessions.py | 10 ++++++++++ paramecio/cromosoma/extrafields/imagefield.py | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/paramecio/citoplasma/sessions.py b/paramecio/citoplasma/sessions.py index b747435..b964f70 100644 --- a/paramecio/citoplasma/sessions.py +++ b/paramecio/citoplasma/sessions.py @@ -95,6 +95,16 @@ def generate_session(session={}): request.environ['session']=s return s + +def regenerate_session(): + + token=create_key(30).replace('/', '#') + + s={'token': token} + + response.set_cookie(config.cookie_name, token, path=config.session_opts['session.path']) + + return ParamecioSession(s) def get_session(): diff --git a/paramecio/cromosoma/extrafields/imagefield.py b/paramecio/cromosoma/extrafields/imagefield.py index 3e8c336..94ba07e 100644 --- a/paramecio/cromosoma/extrafields/imagefield.py +++ b/paramecio/cromosoma/extrafields/imagefield.py @@ -127,7 +127,27 @@ class ImageField(CharField): self.txt_error='Wrong size. Minimum size is '+str(self.sizes['minimum'][0])+'x'+str(self.sizes['minimum'][1]) im.close() return "" + + if 'resize' in self.sizes: + + height_t=0 + width_t=0 + + if real_height<=self.sizes['resize'][1]: + height_t=self.sizes['resize'][1] + + if real_width>self.sizes['resize'][0]: + + width_t=self.sizes['resize'][0] + + if height_t==0: + ratio=(real_width/width_t) + height_t=round(real_height/ratio) + + size=(width_t, height_t) + if width_t>0 and height_t>0: + im.thumbnail(size, self.default_quality_thumb) format_image=im.format