* жёлтым подсвечиваются поля для редактирования, сделайте по ним двойной щелчок
Исходный код модуля /home/httpd/af-web.gaspiko.ru/cgi-bin/plugins2/fond_show.pyc
# -*- coding: utf8 -*- import libs SQL = """select *, (select count(*) from OPIS o where o.FOND=F.KOD)as count_opis from fond_sys f left join FOND F on(F.KOD=f.FOND_ID) %(where)s limit %(offset)d,%(limit)d;""" FOUND_ROWS = False ROOT = "show_fond" ROOT_PREFIX = None ROOT_POSTFIX= None XSL_TEMPLATE = "data/af-web.xsl" EVENT = {"A109":libs.make_str_cdata, "A110":libs.make_str_cdata, "A111":libs.make_str_cdata } WHERE = ("FOND_ID", ) PARAM = None TITLE="Фонд" MESSAGE="нет фонда по вашему запросу" ORDER = None
Исходный код модуля /home/httpd/af-web.gaspiko.ru/cgi-bin/app2.py
#!/usr/bin/env python # # app2.py # # Copyright 2010 Basmanov Illya # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import sys import config
def load_env(): data, page, limit = {}, 0, int(config.limit) if ffcgi.cgi_check_name("p"): page = int(ffcgi.cgi_value("p")) if ffcgi.cgi_check_name("l"): limit = int(ffcgi.cgi_value("l")) if ffcgi.cgi_check_name("plugins"): data["plugins"] = ffcgi.cgi_value( "plugins" ) if ffcgi.cgi_value("ORDER_DIRECTION") in ("DESC", "ASC"): data["direction"] = ffcgi.cgi_value("ORDER_DIRECTION") else: data["direction"] = "DESC" data["page"] = page data["limit"] = limit data["offset"] = page * limit xml = user[3] +"%(page)d%(limit)d%(offset)d%(plugins)s%(direction)s"%data return data, xml
def make_order(cgi_param): if cgi_param is not None: order = [] direction = "DESC" if ffcgi.cgi_value("ORDER_DIRECTION") in ("DESC", "ASC"): direction = ffcgi.cgi_value("ORDER_DIRECTION") for param in cgi_param: if ffcgi.cgi_value("ORDER") == param: value = param if type(value) == list: order.append( ", ".join(["`%s`"%v for v in value]) ) elif type(value) == str: order.append( "`%s`"%value ) return " ORDER BY %s %s"%(",".join(order), direction) return ""
def make_where(cgi_param, IF_ID_DOMEN=None): if cgi_param is None: return "" where = [] where_like = [] if IF_ID_DOMEN is not None: where.append(IF_ID_DOMEN) if ffcgi.cgi_check_name("WHERE_LIKE"): where_like = ffcgi.cgi_value("WHERE_LIKE") for param in cgi_param: if ffcgi.cgi_check_name(param): value = ffcgi.cgi_value(param) if type(value) == list: param = param.replace('.','`.`') if ffcgi.cgi_check_name("BETWEEN") and len(value)==2: where.append( "`%s` BETWEEN %s AND %s"%(param, value[0], value[1] )) else: where.append( "`%s` IN (%s)"%(param, ", ".join(["'%s'"%v for v in value])) ) elif type(value) == str or type(value) == int : if param in where_like: param = param.replace('.','`.`') where.append( "`%s` LIKE '%%%s%%'"%(param, str(value)) ) else: param = param.replace('.','`.`') where.append( "`%s`='%s'"%(param, str(value)) ) else: pass if len(where): where = " AND ".join(where) return "WHERE "+where return ""
def list_to_xml(listtx): txml = "" if listtx: for lx in listtx: txml += "%s"%lx return txml
def exec_sql(module, data, sql, root): xml = "" try: sql = sql%data if ffcgi.cgi_check_name("SQL"): print sql, " " if bd_sql.execute( sql, module.TITLE ): txml = bd_sql.get_xml( event = module.EVENT) if module.FOUND_ROWS: if bd_sql.execute( "select found_rows() as count;" ): txml += bd_sql.get_xml("all_count") xml = "<%s>%s%s>"%(root, txml, root) else: if module.ROOT_POSTFIX: xml += module.ROOT_POSTFIX xml += libs.make_message( "%s"%libs.make_cdata(module.MESSAGE) + "%s"%libs.make_cdata(sql) ) except Exception, e: xml += libs.make_message( "%s: %s"%libs.make_cdata(module.MESSAGE, e) ) return xml
module = load_module() if module: data, xml = load_env() xml += ffcgi.cgi_xml() + "%s"%list_to_xml(module.WHERE) if_id_domen = None if "IF_ID_DOMEN" in dir(module): if_id_domen = module.IF_ID_DOMEN data["where"] = make_where(module.WHERE, if_id_domen) data["order"] = make_order(module.ORDER) xml += "%s"%module.TITLE
if module.PARAM: txml = "" for param in module.PARAM: if ffcgi.cgi_check_name(param): value = ffcgi.cgi_value(param) if type(value) == list: for v in value: data[param] = v txml += "<%s>%s%s>"%(param, libs.make_str_cdata( v ), param) elif type(value) == str: data[param] = value txml += "<%s>%s%s>"%(param, libs.make_str_cdata(value), param) xml += "%s"%txml
if module.ROOT_PREFIX: xml += module.ROOT_PREFIX
if ffcgi.cgi_check_name("cmd") and ffcgi.cgi_value("cmd")=="add": xml += "<%s />"%module.ROOT elif ffcgi.cgi_check_name("format"): # output format JSON try: from json import dumps except: from simplejson import dumps json_data = {module.ROOT: [exec_sql_json(module, data, sql = module.SQL[i][1], root = module.SQL[i][0]) for i in range(0, len(module.SQL))][0]} print dumps( json_data ) return else: if type(module.SQL)==str: xml += exec_sql(module, data, module.SQL, module.ROOT) else: xml += "<%s>%s%s>"%(module.ROOT, "\n\t\t".join([exec_sql(module, data, sql = module.SQL[i][1], root = module.SQL[i][0]) for i in range(0, len(module.SQL))]), module.ROOT)
if ffcgi.cgi_check_name("dbg"): xml += bd_sql.history()
if ffcgi.cgi_check_name("src"): def make_source(filename): return filename, libs.make_str_cdata(open(".".join(filename.split('.')[:-1])+".py").read().replace(" "," ")) xml += "%s%s"%make_source(module.__file__) xml += "%s%s"%make_source(__file__)
xml = "%s"%xml.replace('\0','') libs.save_xml(xml, module.__file__ )
try: print xml_xsl_proc(xml,fxsl=module.XSL_TEMPLATE) except Exception, e: print e
else: print "no define module" return 0
if __name__ == '__main__': try: main() except Exception, e: print e
Отладочная информация
список sql запросов страницы
INSERT INTO session (`HASH`,`UID`,`UAGENT`,`date`,`id_domen`) VALUES('Басманов7275468867129897984','1','webkit/None',now(),@id_domen)#созадём новую сессию
select *, (select count(*) from OPIS o where o.FOND=F.KOD)as count_opis from fond_sys f left join FOND F on(F.KOD=f.FOND_ID) WHERE `FOND_ID`='1723' limit 0,25;#Фонд