* жёлтым подсвечиваются поля для редактирования, сделайте по ним двойной щелчок
у этой описи нет дел
select * from rubrikator_links_sys where `item_id`=@DELO_ID and `plugins_name`='delo_list';
Исходный код модуля /home/httpd/af-web.gaspiko.ru/cgi-bin/plugins2/delo_show.pyc
# -*- coding: utf8 -*- import libs SQL = ( ("delo",""" select @DELO_ID:=D.KOD as DELO_ID,FOND_ID, O.*,DS.*,D.*,U.FIO, (select count(*) from list_nagrada LN where DS.DELO_ID=LN.DELO_ID)as count_nagrada, (select count(*) from digital_image dim where DS.DELO_ID=dim.DELO_ID)as count_dig_img from DELO D left join delo_sys DS on (D.KOD=DS.DELO_ID) left join opis O on (OPIS=O.OPIS_ID) left join users U on (uid=U.id) %(where)s limit %(offset)d,%(limit)d;"""), ("rubrikator","""select * from rubrikator_links_sys where `item_id`=@DELO_ID and `plugins_name`='delo_list';"""), ) FOUND_ROWS = False ROOT = "show_delo" ROOT_PREFIX = "" ROOT_POSTFIX= None XSL_TEMPLATE = "data/af-web.xsl" EVENT = {"L4":libs.make_str_cdata,} WHERE = ("FOND_ID", "OPIS_ID", "DELO_ID","KOD") PARAM = ("OPIS_ID", ) 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"%make_source(module.__file__) xml += "%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 (UID,HASH,REFERER,UAGENT,date,id_domen) VALUES(0,'guest-3931272041916270040','','webkit/None',now(),@id_domen)#созадём новую сессию для ананимоуса
select
@DELO_ID:=D.KOD as DELO_ID,FOND_ID, O.*,DS.*,D.*,U.FIO,
(select count(*) from list_nagrada LN where DS.DELO_ID=LN.DELO_ID)as count_nagrada,
(select count(*) from digital_image dim where DS.DELO_ID=dim.DELO_ID)as count_dig_img
from
DELO D
left join delo_sys DS on (D.KOD=DS.DELO_ID)
left join opis O on (OPIS=O.OPIS_ID)
left join users U on (uid=U.id)
WHERE `OPIS_ID`='44571'
limit 0,25;#Дело
select * from rubrikator_links_sys where `item_id`=@DELO_ID and `plugins_name`='delo_list';#Дело