FIxes in fields and query builder
This commit is contained in:
parent
28172e86d7
commit
8c462b2693
3 changed files with 51 additions and 2 deletions
|
|
@ -29,6 +29,8 @@ def run_cherrypy_server():
|
||||||
# Instantiate a new server object
|
# Instantiate a new server object
|
||||||
server = cherrypy._cpserver.Server()
|
server = cherrypy._cpserver.Server()
|
||||||
|
|
||||||
|
server.thread_pool=30
|
||||||
|
|
||||||
# Configure the server object
|
# Configure the server object
|
||||||
server.socket_host=config.host
|
server.socket_host=config.host
|
||||||
server.socket_port=config.port
|
server.socket_port=config.port
|
||||||
|
|
@ -52,8 +54,6 @@ def run_cherrypy_server():
|
||||||
server.ssl_private_key=config.ssl_private_key
|
server.ssl_private_key=config.ssl_private_key
|
||||||
server.ssl_certificate_chain=config.certificate_chain
|
server.ssl_certificate_chain=config.certificate_chain
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Subscribe this server
|
# Subscribe this server
|
||||||
server.subscribe()
|
server.subscribe()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,16 @@ class TextField(PhangoField):
|
||||||
|
|
||||||
return 'TEXT NOT NULL'
|
return 'TEXT NOT NULL'
|
||||||
|
|
||||||
|
class HTMLField(TextField):
|
||||||
|
|
||||||
|
def __init__(self, name, required=False):
|
||||||
|
super().__init__(name, required)
|
||||||
|
|
||||||
|
def check(self, value):
|
||||||
|
|
||||||
|
return re.sub('<.*?script?>', '', value)
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeyField(IntegerField):
|
class ForeignKeyField(IntegerField):
|
||||||
|
|
||||||
def __init__(self, name, related_table, size=11, required=False, identifier_field='id', named_field="id", select_fields=[]):
|
def __init__(self, name, related_table, size=11, required=False, identifier_field='id', named_field="id", select_fields=[]):
|
||||||
|
|
|
||||||
|
|
@ -267,3 +267,42 @@ def select_a_row_where(model, conditions=['', []], fields_selected=[], raw_query
|
||||||
|
|
||||||
return row
|
return row
|
||||||
|
|
||||||
|
# A method por count num rows affected for sql conditions
|
||||||
|
|
||||||
|
def select_count(model, conditions=['', []], field_to_count='id', raw_query=True):
|
||||||
|
|
||||||
|
|
||||||
|
#First table selecction
|
||||||
|
|
||||||
|
tables_to_select=['`'+model.name+'`']
|
||||||
|
|
||||||
|
fields=list(model.fields.keys())
|
||||||
|
|
||||||
|
#Creating the fields
|
||||||
|
|
||||||
|
for field in fields:
|
||||||
|
|
||||||
|
#Check if foreignkeyfield
|
||||||
|
|
||||||
|
if type(model.fields[field]).__name__=="ForeignKeyField" and raw_query==False:
|
||||||
|
|
||||||
|
table_name=model.fields[field].table_name
|
||||||
|
|
||||||
|
tables_to_select.append('`'+table_name+'`')
|
||||||
|
|
||||||
|
# Add a condition to sql query for join the two tables.
|
||||||
|
|
||||||
|
conditions[0]+=" AND `"+table_name+"`.`"+model.fields[field].identifier_field+"`=`"+model.name+"`.`"+field+"`"
|
||||||
|
|
||||||
|
sql= "select count(`"+field_to_count+"`) from "+", ".join(tables_to_select)+' '+conditions[0]
|
||||||
|
|
||||||
|
count=0
|
||||||
|
|
||||||
|
with model.query(sql, conditions[1], model.connection_id) as cursor:
|
||||||
|
count=list(cursor.fetchone().values())[0]
|
||||||
|
|
||||||
|
if model.yes_reset_conditions:
|
||||||
|
model.reset_conditions()
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue