From ab7d40c9315717e5a5659b14b9990cfab8d80968 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 13 Aug 2018 15:48:55 +0200 Subject: [PATCH] Little fixes and cleaned code --- paramecio/citoplasma/datetime.py | 3 - paramecio/citoplasma/generate_admin_class.py | 4 +- paramecio/citoplasma/plugins.py | 101 ++++++++++-------- paramecio/cromosoma/extrafields/imagefield.py | 2 +- paramecio/modules/welcome/index.py | 7 +- 5 files changed, 60 insertions(+), 57 deletions(-) diff --git a/paramecio/citoplasma/datetime.py b/paramecio/citoplasma/datetime.py index 0ed7880..596cf05 100644 --- a/paramecio/citoplasma/datetime.py +++ b/paramecio/citoplasma/datetime.py @@ -3,7 +3,6 @@ from datetime import date, datetime, tzinfo import arrow # from babel.dates import format_date, format_datetime, format_time, get_timezone, UTC from settings import config -from bottle import hook from paramecio.citoplasma.sessions import get_session from os import environ @@ -25,8 +24,6 @@ if hasattr(config, 'format_time'): if hasattr(config, 'timezone'): timezone=config.timezone -#@hook('before_request') - def set_timezone(): environ['TZ']=environ.get('TZ', timezone) diff --git a/paramecio/citoplasma/generate_admin_class.py b/paramecio/citoplasma/generate_admin_class.py index d9af2d1..12dbd18 100644 --- a/paramecio/citoplasma/generate_admin_class.py +++ b/paramecio/citoplasma/generate_admin_class.py @@ -95,7 +95,7 @@ class GenerateAdminClass: url_action=add_get_parameters(self.url, op_admin=2, id=getpostfiles.get['id']) form=show_form(post, edit_forms, self.t, False, pass_value) - + return self.t.render_template(self.template_insert, admin=self, title_edit=title_edit, form=form, model=self.model, id=getpostfiles.get['id'], url_action=url_action, enctype=self.model.enctype) elif getpostfiles.get['op_admin']=='2': @@ -262,7 +262,7 @@ class GenerateConfigClass: return self.t.render_template(self.template_insert, admin=self, title_edit=title_edit, form=form, model=self.model, id='0', url_action=url_action, enctype=self.model.enctype) else: - form_values=self.model.select_a_row_where() + form_values=self.model.select_a_row_where([], True) pass_values=True diff --git a/paramecio/citoplasma/plugins.py b/paramecio/citoplasma/plugins.py index 9d9981b..bd8a801 100644 --- a/paramecio/citoplasma/plugins.py +++ b/paramecio/citoplasma/plugins.py @@ -2,6 +2,7 @@ from paramecio.modules.admin.models.admin import UserAdmin from bottle import request from paramecio.citoplasma.sessions import get_session from paramecio.citoplasma.urls import redirect, make_url +from paramecio.cromosoma.webmodel import WebModel import inspect class LoginPlugin(object): @@ -32,23 +33,15 @@ class LoginPlugin(object): keyword = conf.get('keyword', self.keyword) args = inspect.getfullargspec(context.callback)[0] - + if keyword not in args: return callback def wrapper(*args, **kwargs): - + s=get_session() if 'login' in s: - """ - if not s.get('usertpv_confirmed_email', 0): - redirect('check_email') - else: - """ - #s.save() - - #conn.close() rv = callback(*args, **kwargs) @@ -57,45 +50,59 @@ class LoginPlugin(object): else: #Check if remember_login cookie #, secret=config.key_encrypt - """ - remember_cookie=request.get_cookie("remember_me") - - if remember_cookie: - - if remember_cookie!='': - - conn=WebModel.connection() - - user=UserAdmin(conn) - - arr_user=user.set_conditions('WHERE token_login=%s', [remember_cookie]).select_a_row_where() - error=True - - if arr_user: - - tz=arr_user['timezone'] - - try: - timezone(tz) - - except: - tz='Europe/Madrid' - - - s['usertpv_timezone']=tz - - error=False - - s.save() - - conn.close() - - if not error: - redirect(config.base_url[:len(config.base_url)-1]+request.path) - - """ redirect(make_url('login')) # Replace the route callback with the wrapped one. return wrapper + + +class DbPlugin(object): + + name = 'login' + api = 2 + + def __init__(self, keyword='db'): + + self.keyword=keyword + + + def setup(self, app): + ''' Make sure that other installed plugins don't affect the same keyword argument.''' + for other in app.plugins: + if not isinstance(other, LoginPlugin): continue + if other.keyword == self.keyword: + raise PluginError("Found another login plugin with "\ + "conflicting settings (non-unique keyword).") + + def apply(self, callback, context): + + # Test if the original callback accepts a 'db' keyword. + # Ignore it if it does not need a login handle. + + conf = context.config.get('db') or {} + + keyword = conf.get('keyword', self.keyword) + + args = inspect.getfullargspec(context.callback)[0] + + if keyword not in args: + return callback + + def wrapper(*args, **kwargs): + + kwargs['db']=WebModel.connection() + + rv = callback(*args, **kwargs) + + kwargs['db'].close() + + return rv + + return wrapper + + + + + + diff --git a/paramecio/cromosoma/extrafields/imagefield.py b/paramecio/cromosoma/extrafields/imagefield.py index 1ee0446..9d8c70d 100644 --- a/paramecio/cromosoma/extrafields/imagefield.py +++ b/paramecio/cromosoma/extrafields/imagefield.py @@ -154,7 +154,7 @@ class ImageField(CharField): size=(width_t, height_t) if width_t>0 and height_t>0: - im.thumbnail(size, self.default_quality_thumb) + im.thumbnail(size, 3) format_image=im.format diff --git a/paramecio/modules/welcome/index.py b/paramecio/modules/welcome/index.py index d8b9b21..64b0274 100644 --- a/paramecio/modules/welcome/index.py +++ b/paramecio/modules/welcome/index.py @@ -4,7 +4,6 @@ from paramecio.citoplasma.mtemplates import PTemplate, env_theme from paramecio.citoplasma.urls import make_url from paramecio.wsgiapp import app from settings import config -from bottle import request #t=ptemplate(__file__) env=env_theme(__file__) @@ -20,10 +19,10 @@ def home(): def page(id): return t.render_template('index.html', title="A simple example of a page", id=id, value=request.query.value) -@app.route('/welcome/test/') -def test(id): +@app.route('/welcome/test/') +def test(int_id): - return make_url('welcome/test/5', {'ohmygod': 'This is gooood', 'shutup':'Shut up!!'}) + return make_url('welcome/test/'+int_id, {'ohmygod': 'This is gooood', 'shutup':'Shut up!!'}) if config.default_module=="welcome":