Many fixes and improvenments
This commit is contained in:
parent
5474134f74
commit
87177ccdb5
7 changed files with 180 additions and 66 deletions
|
|
@ -73,10 +73,16 @@ def generate_session():
|
||||||
|
|
||||||
def get_session():
|
def get_session():
|
||||||
|
|
||||||
if config.cookie_name in request.environ:
|
try:
|
||||||
|
|
||||||
|
if config.cookie_name in request.environ:
|
||||||
|
|
||||||
|
return ParamecioSession()
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
except:
|
||||||
|
|
||||||
return ParamecioSession()
|
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,39 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import pymysql.cursors
|
import pymysql
|
||||||
|
pymysql.install_as_MySQLdb()
|
||||||
|
|
||||||
class SqlClass:
|
class SqlClass:
|
||||||
|
|
||||||
error_connection=""
|
def __init__(self):
|
||||||
connection={}
|
|
||||||
|
self.error_connection=""
|
||||||
|
self.connection={}
|
||||||
|
self.connected=False
|
||||||
|
self.connection_method=self.connect_to_db_sql
|
||||||
|
|
||||||
def dummy_connect(self, connection, name_connection="default"):
|
def dummy_connect(self, connection, name_connection="default"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def connect_to_db(self, connection, name_connection="default"):
|
def connect_to_db(self, connection, name_connection="default"):
|
||||||
|
|
||||||
|
self.connection_method(connection, name_connection)
|
||||||
|
|
||||||
|
self.connection_method=self.dummy_connect
|
||||||
|
|
||||||
|
def connect_to_db_sql(self, connection, name_connection="default"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
self.connection[name_connection] = pymysql.connect(connection['host'],
|
self.connection[name_connection] = pymysql.connect(connection['host'],
|
||||||
user=connection['user'],
|
user=connection['user'],
|
||||||
password=connection['password'],
|
passwd=connection['password'],
|
||||||
db=connection['db'],
|
db=connection['db'],
|
||||||
charset='utf8mb4',
|
charset='utf8mb4',
|
||||||
cursorclass=pymysql.cursors.DictCursor)
|
cursorclass=pymysql.cursors.DictCursor)
|
||||||
|
|
||||||
|
self.connected=True
|
||||||
|
|
||||||
except:
|
except:
|
||||||
e = sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
|
|
@ -65,10 +77,20 @@ class SqlClass:
|
||||||
#def fetch(self, cursor):
|
#def fetch(self, cursor):
|
||||||
|
|
||||||
#return cursor.fetchone()
|
#return cursor.fetchone()
|
||||||
|
"""
|
||||||
|
def __del__(self):
|
||||||
|
|
||||||
|
for key in self.connection:
|
||||||
|
|
||||||
|
self.close(self.connection)
|
||||||
|
"""
|
||||||
|
|
||||||
def close(self, name_connection="default"):
|
def close(self, name_connection="default"):
|
||||||
|
|
||||||
self.connection[name_connection].close()
|
if self.connection[name_connection]:
|
||||||
|
|
||||||
|
self.connection[name_connection].close()
|
||||||
|
self.connection[name_connection]=False
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,15 @@ import re
|
||||||
import uuid
|
import uuid
|
||||||
from importlib import import_module, reload
|
from importlib import import_module, reload
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from paramecio.cromosoma.databases.mysql import SqlClass
|
from paramecio.cromosoma.databases.mysqldb import SqlClass
|
||||||
from paramecio.cromosoma.coreforms import BaseForm, HiddenForm
|
from paramecio.cromosoma.coreforms import BaseForm, HiddenForm
|
||||||
|
|
||||||
# The most important class for the framework
|
# The most important class for the framework
|
||||||
#
|
#
|
||||||
# Webmodel is a class for create objects that represent models. This models are a mirage of SQL tables. You can create fields, add indexes, foreign keys, and more.
|
# Webmodel is a class for create objects that represent models. This models are a mirage of SQL tables. You can create fields, add indexes, foreign keys, and more.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
class WebModel:
|
class WebModel:
|
||||||
|
|
||||||
|
|
@ -23,8 +24,7 @@ class WebModel:
|
||||||
arr_sql_unique={}
|
arr_sql_unique={}
|
||||||
arr_sql_set_unique={}
|
arr_sql_set_unique={}
|
||||||
last_query=""
|
last_query=""
|
||||||
|
connection_pool=[]
|
||||||
make_connection=SqlClass.connect_to_db
|
|
||||||
|
|
||||||
#A dictionary for add models here
|
#A dictionary for add models here
|
||||||
|
|
||||||
|
|
@ -36,9 +36,18 @@ class WebModel:
|
||||||
|
|
||||||
webmodel=True
|
webmodel=True
|
||||||
|
|
||||||
|
#sqlclass=SqlClass()
|
||||||
|
|
||||||
|
#make_connection=sqlclass.connect_to_db
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def connection():
|
||||||
|
|
||||||
|
return SqlClass()
|
||||||
|
|
||||||
# Init the class
|
# Init the class
|
||||||
|
|
||||||
def __init__(self, name_field_id="id"):
|
def __init__(self, sqlclass, name_field_id="id"):
|
||||||
|
|
||||||
#The name of the table
|
#The name of the table
|
||||||
|
|
||||||
|
|
@ -108,6 +117,8 @@ class WebModel:
|
||||||
# A simple dictionary that save the fields that have files related. If i delete the row in database i need delete the files related
|
# A simple dictionary that save the fields that have files related. If i delete the row in database i need delete the files related
|
||||||
|
|
||||||
self.files_delete={}
|
self.files_delete={}
|
||||||
|
|
||||||
|
self.sqlclass=sqlclass
|
||||||
|
|
||||||
# A method where create the new fields of this model
|
# A method where create the new fields of this model
|
||||||
|
|
||||||
|
|
@ -134,23 +145,34 @@ class WebModel:
|
||||||
def create_id_field(self, field_name="id"):
|
def create_id_field(self, field_name="id"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# A method for select rows from a database.
|
# A method for connect to database
|
||||||
|
|
||||||
def connect_to_db(self):
|
def connect_to_db(self):
|
||||||
|
|
||||||
if WebModel.make_connection(SqlClass, self.connections[self.connection_id])==False:
|
#if WebModel.make_connection(self.connections[self.connection_id])==False:
|
||||||
raise NameError(SqlClass.error_connection)
|
#raise NameError(sqlclass.error_connection)
|
||||||
|
|
||||||
WebModel.make_connection=SqlClass.dummy_connect
|
#self.connection_pool.append(True)
|
||||||
|
"""
|
||||||
|
if not sqlclass.connected:
|
||||||
|
if WebModel.make_connection(self.connections[self.connection_id])==False:
|
||||||
|
raise NameError(sqlclass.error_connection)
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.sqlclass.connect_to_db(self.connections[self.connection_id])==False:
|
||||||
|
raise NameError(sqlclass.error_connection)
|
||||||
|
|
||||||
|
#WebModel.make_connection=sqlclass.dummy_connect
|
||||||
|
|
||||||
def dummy_connect(self, connection):
|
def dummy_connect(self, connection):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Static method for make queries
|
# Static method for make queries
|
||||||
@staticmethod
|
|
||||||
def query(WebModel, str_query, args=[], connection_id='default'):
|
def query(self, str_query, args=[], connection_id='default'):
|
||||||
WebModel.connect_to_db(WebModel)
|
|
||||||
return SqlClass.query(SqlClass, str_query, args, connection_id)
|
self.connect_to_db()
|
||||||
|
return self.sqlclass.query(str_query, args, connection_id)
|
||||||
|
|
||||||
# Insert method, for insert a row in database.using a dictionary
|
# Insert method, for insert a row in database.using a dictionary
|
||||||
# External agent define if the update is in code or from external source, how a form.
|
# External agent define if the update is in code or from external source, how a form.
|
||||||
|
|
@ -178,7 +200,7 @@ class WebModel:
|
||||||
|
|
||||||
sql="insert into `"+self.name+"` (`"+"`, `".join(fields)+"`) VALUES ("+", ".join(values)+")"
|
sql="insert into `"+self.name+"` (`"+"`, `".join(fields)+"`) VALUES ("+", ".join(values)+")"
|
||||||
|
|
||||||
cursor=SqlClass.query(SqlClass, sql, self.conditions[1], self.connection_id)
|
cursor=self.sqlclass.query(sql, self.conditions[1], self.connection_id)
|
||||||
|
|
||||||
if cursor.rowcount>0:
|
if cursor.rowcount>0:
|
||||||
|
|
||||||
|
|
@ -223,7 +245,7 @@ class WebModel:
|
||||||
|
|
||||||
sql="update `"+self.name+"` SET "+", ".join(update_values)+" "+self.conditions[0]
|
sql="update `"+self.name+"` SET "+", ".join(update_values)+" "+self.conditions[0]
|
||||||
|
|
||||||
cursor=SqlClass.query(SqlClass, sql, self.conditions[1], self.connection_id)
|
cursor=self.sqlclass.query(sql, self.conditions[1], self.connection_id)
|
||||||
|
|
||||||
if self.yes_reset_conditions:
|
if self.yes_reset_conditions:
|
||||||
self.reset_conditions()
|
self.reset_conditions()
|
||||||
|
|
@ -249,7 +271,7 @@ class WebModel:
|
||||||
"""
|
"""
|
||||||
except:
|
except:
|
||||||
|
|
||||||
#self.query_error=SqlClass.error_connection
|
#self.query_error=sqlclass.error_connection
|
||||||
e = sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
v = sys.exc_info()[1]
|
v = sys.exc_info()[1]
|
||||||
|
|
||||||
|
|
@ -342,10 +364,10 @@ class WebModel:
|
||||||
if self.yes_reset_conditions:
|
if self.yes_reset_conditions:
|
||||||
self.reset_conditions()
|
self.reset_conditions()
|
||||||
|
|
||||||
cursor=SqlClass.query(SqlClass, sql, conditions[1], self.connection_id)
|
cursor=self.sqlclass.query(sql, conditions[1], self.connection_id)
|
||||||
|
|
||||||
if cursor==False:
|
if cursor==False:
|
||||||
self.query_error=SqlClass.error_connection
|
self.query_error=self.sqlclass.error_connection
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
|
@ -474,7 +496,7 @@ class WebModel:
|
||||||
|
|
||||||
sql= "select count(`"+field_to_count+"`) from "+", ".join(tables_to_select)+conditions[0]
|
sql= "select count(`"+field_to_count+"`) from "+", ".join(tables_to_select)+conditions[0]
|
||||||
|
|
||||||
cursor=SqlClass.query(SqlClass, sql, conditions[1], self.connection_id)
|
cursor=self.sqlclass.query(sql, conditions[1], self.connection_id)
|
||||||
|
|
||||||
count=list(cursor.fetchone().values())[0]
|
count=list(cursor.fetchone().values())[0]
|
||||||
|
|
||||||
|
|
@ -497,7 +519,7 @@ class WebModel:
|
||||||
|
|
||||||
sql="delete from `"+self.name+"` "+self.conditions[0]
|
sql="delete from `"+self.name+"` "+self.conditions[0]
|
||||||
|
|
||||||
result=SqlClass.query(SqlClass, sql, self.conditions[1], self.connection_id)
|
result=self.sqlclass.query(sql, self.conditions[1], self.connection_id)
|
||||||
|
|
||||||
if self.yes_reset_conditions:
|
if self.yes_reset_conditions:
|
||||||
self.reset_conditions()
|
self.reset_conditions()
|
||||||
|
|
@ -591,40 +613,40 @@ class WebModel:
|
||||||
|
|
||||||
print("---Deleting index from "+field+" in "+self.name)
|
print("---Deleting index from "+field+" in "+self.name)
|
||||||
|
|
||||||
WebModel.query(WebModel, 'DROP INDEX `index_'+self.name+'_'+field+'` ON '+self.name, [], self.connection_id)
|
self.query('DROP INDEX `index_'+self.name+'_'+field+'` ON '+self.name, [], self.connection_id)
|
||||||
|
|
||||||
for field in fields_to_delete_unique:
|
for field in fields_to_delete_unique:
|
||||||
|
|
||||||
print("---Deleting unique from "+field+" in "+self.name)
|
print("---Deleting unique from "+field+" in "+self.name)
|
||||||
|
|
||||||
WebModel.query(WebModel, 'DROP INDEX `'+field+'` ON '+self.name, [], self.connection_id)
|
self.query('DROP INDEX `'+field+'` ON '+self.name, [], self.connection_id)
|
||||||
|
|
||||||
for field in fields_to_delete_constraint:
|
for field in fields_to_delete_constraint:
|
||||||
|
|
||||||
print("---Deleting foreignkey from "+field+" in "+self.name)
|
print("---Deleting foreignkey from "+field+" in "+self.name)
|
||||||
|
|
||||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` DROP FOREIGN KEY '+field+'_'+self.name+'IDX', [], self.connection_id)
|
self.query('ALTER TABLE `'+self.name+'` DROP FOREIGN KEY '+field+'_'+self.name+'IDX', [], self.connection_id)
|
||||||
|
|
||||||
for field in fields_to_delete:
|
for field in fields_to_delete:
|
||||||
|
|
||||||
print("---Deleting "+field+" from "+self.name)
|
print("---Deleting "+field+" from "+self.name)
|
||||||
|
|
||||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` DROP `'+field+'`', [], self.connection_id)
|
self.query('ALTER TABLE `'+self.name+'` DROP `'+field+'`', [], self.connection_id)
|
||||||
#Deleting indexes and constraints.
|
#Deleting indexes and constraints.
|
||||||
|
|
||||||
#Obtain new fields
|
#Obtain new fields
|
||||||
|
|
||||||
for field in fields_to_modify:
|
for field in fields_to_modify:
|
||||||
print("---Updating "+field+" in "+self.name)
|
print("---Updating "+field+" in "+self.name)
|
||||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` MODIFY `'+field+'` '+self.fields[field].get_type_sql(), [], self.connection_id)
|
self.query('ALTER TABLE `'+self.name+'` MODIFY `'+field+'` '+self.fields[field].get_type_sql(), [], self.connection_id)
|
||||||
|
|
||||||
for field in fields_to_add:
|
for field in fields_to_add:
|
||||||
print("---Adding "+field+" in "+self.name)
|
print("---Adding "+field+" in "+self.name)
|
||||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` ADD `'+field+'` '+self.fields[field].get_type_sql(), [], self.connection_id)
|
self.query('ALTER TABLE `'+self.name+'` ADD `'+field+'` '+self.fields[field].get_type_sql(), [], self.connection_id)
|
||||||
|
|
||||||
for field in fields_to_add_index:
|
for field in fields_to_add_index:
|
||||||
print("---Adding index to "+field+" in "+self.name)
|
print("---Adding index to "+field+" in "+self.name)
|
||||||
WebModel.query(WebModel, 'CREATE INDEX `index_'+self.name+'_'+field+'` ON '+self.name+' (`'+field+'`);', [], self.connection_id)
|
self.query('CREATE INDEX `index_'+self.name+'_'+field+'` ON '+self.name+' (`'+field+'`);', [], self.connection_id)
|
||||||
|
|
||||||
for field in fields_to_add_constraint:
|
for field in fields_to_add_constraint:
|
||||||
|
|
||||||
|
|
@ -634,20 +656,20 @@ class WebModel:
|
||||||
|
|
||||||
id_table_related=self.fields[field].table_id
|
id_table_related=self.fields[field].table_id
|
||||||
|
|
||||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` ADD CONSTRAINT `'+field+'_'+self.name+'IDX` FOREIGN KEY ( `'+field+'` ) REFERENCES `'+table_related+'` (`'+id_table_related+'`) ON DELETE RESTRICT ON UPDATE RESTRICT;', [], self.connection_id)
|
self.query('ALTER TABLE `'+self.name+'` ADD CONSTRAINT `'+field+'_'+self.name+'IDX` FOREIGN KEY ( `'+field+'` ) REFERENCES `'+table_related+'` (`'+id_table_related+'`) ON DELETE RESTRICT ON UPDATE RESTRICT;', [], self.connection_id)
|
||||||
|
|
||||||
for field in fields_to_add_unique:
|
for field in fields_to_add_unique:
|
||||||
|
|
||||||
print("---Adding unique to "+field+" in "+self.name)
|
print("---Adding unique to "+field+" in "+self.name)
|
||||||
|
|
||||||
WebModel.query(WebModel, 'ALTER TABLE `'+self.name+'` ADD UNIQUE (`'+field+'`)', [], self.connection_id)
|
self.query('ALTER TABLE `'+self.name+'` ADD UNIQUE (`'+field+'`)', [], self.connection_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Method for drop sql tables and related
|
# Method for drop sql tables and related
|
||||||
|
|
||||||
def drop(self):
|
def drop(self):
|
||||||
return WebModel.query(WebModel, 'DROP TABLE '+self.name, [], self.connection_id)
|
return self.query('DROP TABLE '+self.name, [], self.connection_id)
|
||||||
|
|
||||||
#Return an array with all fields
|
#Return an array with all fields
|
||||||
|
|
||||||
|
|
@ -839,29 +861,33 @@ class WebModel:
|
||||||
|
|
||||||
return error_txt
|
return error_txt
|
||||||
|
|
||||||
@staticmethod
|
def close(self):
|
||||||
def close():
|
|
||||||
|
|
||||||
connection_to_delete=[]
|
self.sqlclass.close()
|
||||||
|
|
||||||
WebModel.make_connection=SqlClass.connect_to_db
|
#connection_to_delete=[]
|
||||||
|
|
||||||
for key in SqlClass.connection:
|
#WebModel.make_connection=self.sqlclass.connect_to_db
|
||||||
SqlClass.close(SqlClass, key)
|
|
||||||
|
#for key in self.sqlclass.connection:
|
||||||
|
#self.sqlclass.close(key)
|
||||||
#connection_to_delete.append(key)
|
#connection_to_delete.append(key)
|
||||||
|
|
||||||
SqlClass.connection={}
|
#self.sqlclass.connection={}
|
||||||
|
|
||||||
#for key in connection_to_delete:
|
#for key in connection_to_delete:
|
||||||
#del SqlClass.connection[key]
|
#del sqlclass.connection[key]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def escape_sql(value):
|
def escape_sql(value):
|
||||||
|
|
||||||
value=str(value)
|
value=str(value)
|
||||||
|
|
||||||
return value.replace("'","\\'").strip()
|
return value.replace("'","\\'").strip()
|
||||||
|
"""
|
||||||
|
def __del__(self):
|
||||||
|
|
||||||
|
self.close()
|
||||||
|
"""
|
||||||
|
|
||||||
class PhangoField:
|
class PhangoField:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,13 @@ from paramecio.citoplasma.i18n import I18n
|
||||||
from paramecio.cromosoma.coreforms import SelectForm
|
from paramecio.cromosoma.coreforms import SelectForm
|
||||||
from settings import config
|
from settings import config
|
||||||
|
|
||||||
def admin(t):
|
def admin(**args):
|
||||||
|
|
||||||
user_admin=UserAdmin()
|
|
||||||
|
t=args['t']
|
||||||
|
connection=args['connection']
|
||||||
|
|
||||||
|
user_admin=UserAdmin(connection)
|
||||||
|
|
||||||
user_admin.fields['privileges'].name_form=SelectForm
|
user_admin.fields['privileges'].name_form=SelectForm
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ from paramecio.citoplasma.generate_admin_class import GenerateAdminClass
|
||||||
from paramecio.citoplasma.httputils import GetPostFiles
|
from paramecio.citoplasma.httputils import GetPostFiles
|
||||||
from paramecio.cromosoma.formsutils import show_form, pass_values_to_form, set_extra_forms_user
|
from paramecio.cromosoma.formsutils import show_form, pass_values_to_form, set_extra_forms_user
|
||||||
from paramecio.cromosoma.coreforms import PasswordForm
|
from paramecio.cromosoma.coreforms import PasswordForm
|
||||||
|
from paramecio.cromosoma.webmodel import WebModel
|
||||||
from importlib import import_module, reload
|
from importlib import import_module, reload
|
||||||
from bottle import redirect
|
from bottle import redirect
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
@ -40,7 +41,7 @@ t=ptemplate(__file__)
|
||||||
def home(module='', submodule=''):
|
def home(module='', submodule=''):
|
||||||
|
|
||||||
# A simple boolean used for show or not the code of admin module in standard template
|
# A simple boolean used for show or not the code of admin module in standard template
|
||||||
|
connection=WebModel.connection()
|
||||||
ptemplate.show_basic_template=True
|
ptemplate.show_basic_template=True
|
||||||
|
|
||||||
if submodule!='':
|
if submodule!='':
|
||||||
|
|
@ -50,7 +51,7 @@ def home(module='', submodule=''):
|
||||||
|
|
||||||
#check if login
|
#check if login
|
||||||
|
|
||||||
user_admin=UserAdmin()
|
user_admin=UserAdmin(connection)
|
||||||
|
|
||||||
s=get_session()
|
s=get_session()
|
||||||
|
|
||||||
|
|
@ -114,7 +115,9 @@ def home(module='', submodule=''):
|
||||||
|
|
||||||
return "No exists admin module"
|
return "No exists admin module"
|
||||||
|
|
||||||
content_index=new_module.admin(t)
|
#args={'t': t, 'connection': connection}
|
||||||
|
|
||||||
|
content_index=new_module.admin(t=t, connection=connection)
|
||||||
|
|
||||||
if ptemplate.show_basic_template==True:
|
if ptemplate.show_basic_template==True:
|
||||||
|
|
||||||
|
|
@ -161,6 +164,7 @@ def home(module='', submodule=''):
|
||||||
redirect('/'+config.admin_folder)
|
redirect('/'+config.admin_folder)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
post={}
|
post={}
|
||||||
|
|
||||||
user_admin.yes_repeat_password=False
|
user_admin.yes_repeat_password=False
|
||||||
|
|
@ -171,6 +175,8 @@ def home(module='', submodule=''):
|
||||||
|
|
||||||
forms=show_form(post, user_admin.forms, t, yes_error=False)
|
forms=show_form(post, user_admin.forms, t, yes_error=False)
|
||||||
|
|
||||||
|
#connection.close()
|
||||||
|
|
||||||
return t.load_template('admin/login.phtml', forms=forms)
|
return t.load_template('admin/login.phtml', forms=forms)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
@ -186,7 +192,9 @@ def home(module='', submodule=''):
|
||||||
@post('/'+config.admin_folder+'/login')
|
@post('/'+config.admin_folder+'/login')
|
||||||
def login():
|
def login():
|
||||||
|
|
||||||
user_admin=UserAdmin()
|
connection=WebModel.connection()
|
||||||
|
|
||||||
|
user_admin=UserAdmin(connection)
|
||||||
|
|
||||||
GetPostFiles.obtain_post()
|
GetPostFiles.obtain_post()
|
||||||
|
|
||||||
|
|
@ -253,7 +261,9 @@ def login():
|
||||||
@post('/'+config.admin_folder+'/register')
|
@post('/'+config.admin_folder+'/register')
|
||||||
def register():
|
def register():
|
||||||
|
|
||||||
user_admin=UserAdmin()
|
connection=WebModel.connection()
|
||||||
|
|
||||||
|
user_admin=UserAdmin(connection)
|
||||||
|
|
||||||
user_admin.conditions=['WHERE privileges=%s', 2]
|
user_admin.conditions=['WHERE privileges=%s', 2]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ class PrivilegesField(corefields.IntegerField):
|
||||||
class UserAdmin(UserModel):
|
class UserAdmin(UserModel):
|
||||||
|
|
||||||
#def create_fields(self):
|
#def create_fields(self):
|
||||||
def __init__(self):
|
def __init__(self, connection):
|
||||||
|
|
||||||
super().__init__()
|
super().__init__(connection)
|
||||||
|
|
||||||
# I can change other fields here, how the name.
|
# I can change other fields here, how the name.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,44 @@ from settings import config
|
||||||
from paramecio.cromosoma.webmodel import WebModel
|
from paramecio.cromosoma.webmodel import WebModel
|
||||||
from paramecio.cromosoma import corefields
|
from paramecio.cromosoma import corefields
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
# Create TestWebModelMethods
|
# Create TestWebModelMethods
|
||||||
|
|
||||||
class ExampleModel(WebModel):
|
class ExampleModel(WebModel):
|
||||||
|
|
||||||
def create_fields(self):
|
def __init__(self, connection):
|
||||||
|
|
||||||
|
super().__init__(connection)
|
||||||
|
|
||||||
|
# I can change other fields here, how the name.
|
||||||
|
|
||||||
|
self.register(corefields.CharField('title'))
|
||||||
|
self.register(corefields.CharField('content'))
|
||||||
|
|
||||||
|
class ExampleModel2(WebModel):
|
||||||
|
|
||||||
|
def __init__(self, connection):
|
||||||
|
|
||||||
|
super().__init__(connection)
|
||||||
|
|
||||||
# I can change other fields here, how the name.
|
# I can change other fields here, how the name.
|
||||||
|
|
||||||
self.register(corefields.CharField('title'))
|
self.register(corefields.CharField('title'))
|
||||||
self.register(corefields.CharField('content'))
|
self.register(corefields.CharField('content'))
|
||||||
|
|
||||||
model=ExampleModel()
|
|
||||||
|
|
||||||
class TestWebModelMethods(unittest.TestCase):
|
class TestWebModelMethods(unittest.TestCase):
|
||||||
|
|
||||||
def test_test_table(self):
|
def test_test_table(self):
|
||||||
|
|
||||||
|
connection=WebModel.connection()
|
||||||
|
model=ExampleModel(connection)
|
||||||
|
|
||||||
|
|
||||||
sql=model.create_table()
|
sql=model.create_table()
|
||||||
|
|
||||||
print('Creating table')
|
print('Creating table')
|
||||||
|
|
||||||
self.assertTrue(WebModel.query(WebModel, sql))
|
self.assertTrue(model.query(sql))
|
||||||
|
|
||||||
|
|
||||||
post={'title': 'Example title', 'content': 'New content'}
|
post={'title': 'Example title', 'content': 'New content'}
|
||||||
|
|
||||||
|
|
@ -98,14 +112,21 @@ class TestWebModelMethods(unittest.TestCase):
|
||||||
print('Check delete table')
|
print('Check delete table')
|
||||||
|
|
||||||
self.assertTrue(model.drop())
|
self.assertTrue(model.drop())
|
||||||
|
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
def test_update_table(self):
|
def test_update_table(self):
|
||||||
|
|
||||||
|
connection=WebModel.connection()
|
||||||
|
model=ExampleModel(connection)
|
||||||
|
|
||||||
|
|
||||||
print('Check modifications in table')
|
print('Check modifications in table')
|
||||||
|
|
||||||
sql=model.create_table()
|
sql=model.create_table()
|
||||||
|
|
||||||
self.assertTrue(WebModel.query(WebModel, sql))
|
self.assertTrue(model.query(sql))
|
||||||
|
|
||||||
fields_to_modify=[]
|
fields_to_modify=[]
|
||||||
fields_to_add_index=[]
|
fields_to_add_index=[]
|
||||||
|
|
@ -127,7 +148,32 @@ class TestWebModelMethods(unittest.TestCase):
|
||||||
model.update_table([], fields_to_modify, fields_to_add_index, fields_to_add_constraint, fields_to_add_unique, ['description'], ['description'], fields_to_delete_constraint, ['description'])
|
model.update_table([], fields_to_modify, fields_to_add_index, fields_to_add_constraint, fields_to_add_unique, ['description'], ['description'], fields_to_delete_constraint, ['description'])
|
||||||
|
|
||||||
self.assertTrue(model.drop())
|
self.assertTrue(model.drop())
|
||||||
|
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
def test_zcheck_connections(self):
|
||||||
|
|
||||||
|
print('Check connection of models...')
|
||||||
|
|
||||||
|
connection=WebModel.connection()
|
||||||
|
model=ExampleModel(connection)
|
||||||
|
|
||||||
|
model2=ExampleModel2(connection)
|
||||||
|
|
||||||
|
sql=model.create_table()
|
||||||
|
sql2=model2.create_table()
|
||||||
|
#print(sql)
|
||||||
|
|
||||||
|
self.assertTrue(model.query(sql))
|
||||||
|
self.assertTrue(model2.query(sql2))
|
||||||
|
|
||||||
|
self.assertTrue(model.drop())
|
||||||
|
self.assertTrue(model2.drop())
|
||||||
|
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue