From e23bd6cf370bf8ccfaa1ef09daeb5c5046677072 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Fri, 1 Apr 2016 14:56:33 +0200 Subject: [PATCH] Fix in foreignkeyfield, sessions and more --- paramecio/citoplasma/i18n.py | 6 ++---- paramecio/cromosoma/corefields.py | 9 +++++++++ paramecio/index.py | 6 ++++++ paramecio/modules/admin/index.py | 4 +++- paramecio/modules/lang/index.py | 4 +++- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/paramecio/citoplasma/i18n.py b/paramecio/citoplasma/i18n.py index 6e65d8c..446029f 100644 --- a/paramecio/citoplasma/i18n.py +++ b/paramecio/citoplasma/i18n.py @@ -41,12 +41,10 @@ class I18n: s=get_session() if s==None: - - s={} - s['lang']=s.get('lang', I18n.default_lang) + s={'lang': lang} - lang=s['lang'] + lang=s.get('lang', lang) return lang diff --git a/paramecio/cromosoma/corefields.py b/paramecio/cromosoma/corefields.py index 2feae0c..05051cd 100644 --- a/paramecio/cromosoma/corefields.py +++ b/paramecio/cromosoma/corefields.py @@ -104,6 +104,15 @@ class ForeignKeyField(IntegerField): self.change_form(coreforms.SelectModelForm, [related_table, self.named_field, self.identifier_field]) + def check(self, value): + + value=super().check(value) + + if value=='0' or value==0: + value='NULL' + + return value + def get_type_sql(self): return 'INT NULL' diff --git a/paramecio/index.py b/paramecio/index.py index d2aa32b..49d962b 100644 --- a/paramecio/index.py +++ b/paramecio/index.py @@ -45,6 +45,10 @@ else: pass """ +def print_cookie(): + pass + #print(request.cookies) + routes={} module_loaded=None @@ -113,6 +117,8 @@ if config.ssl==True: app = application = default_app() +app.add_hook('before_request', print_cookie) + if config.session_enabled==True: #Create dir for sessions diff --git a/paramecio/modules/admin/index.py b/paramecio/modules/admin/index.py index 3bceb4b..e024e25 100644 --- a/paramecio/modules/admin/index.py +++ b/paramecio/modules/admin/index.py @@ -64,6 +64,8 @@ def home(module='', submodule=''): if s['lang']!=None: lang_selected=s['lang'] + else: + s['lang']=I18n.default_lang user_admin.conditions=['WHERE id=%s', [s['id']]] @@ -235,7 +237,7 @@ def login(): response.set_cookie('remember_login', random_text, expires=timestamp, secret=key_encrypt) #else: #print(user_admin.query_error) - + s.save() return {'error': 0} else: diff --git a/paramecio/modules/lang/index.py b/paramecio/modules/lang/index.py index 02e36ad..9f8f214 100644 --- a/paramecio/modules/lang/index.py +++ b/paramecio/modules/lang/index.py @@ -12,6 +12,8 @@ def index(lang): s['lang']=lang + s.save() + redirect_url=request.headers.get('Referer') if redirect_url!=None: @@ -20,4 +22,4 @@ def index(lang): redirect(redirect_url) - return "" \ No newline at end of file + return ""