№ п/п |
№ | краткое название фонда | топография | описей (всего / внесено) | |||
---|---|---|---|---|---|---|---|
помещение | стеллаж | шкаф | полка | ||||
1 | П- 182 | Фракция ВКП(б) Котельничского окружного совета профсоюзов | 2 | 1 | 5 | 8 | 1 / 1 |
Исходный код модуля /home/httpd/af-web.gaspiko.ru/cgi-bin/plugins2/fond.pyc
# -*- coding: utf8 -*-
SQL = """select SQL_CALC_FOUND_ROWS * from fond %(where)s order by FKOD asc limit %(offset)d,%(limit)d;"""
#SQL = """select SQL_CALC_FOUND_ROWS * from fond_from1933 %(where)s order by FKOD asc limit %(offset)d,%(limit)d;"""
FOUND_ROWS = True
ROOT = "list_fonds"
ROOT_PREFIX = None
ROOT_POSTFIX = None
XSL_TEMPLATE = "data/af-web.xsl"
EVENT = None
WHERE = ("repository", "FL","FOND_ID", "A100", "вunks","cabinet")
PARAM = ("repository", )
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
#sys.stderr = sys.stdout
#print "Content-Type: text/html; charset=utf8\n\n"
import ffcgi
import libs
from user import user
from base import bd_sql
from xslt_proc import xml_xsl_proc
plugin_dir = "plugins2"
def load_module():
if ffcgi.cgi_check_name("plugins"):
module_name = ffcgi.cgi_value( "plugins" )
return libs.load_module_name(module_name, plugin_dir)
else:
return None
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
def exec_sql_json(module, data, sql, root):
json_data = {root: {}, }
try:
sql = sql%data
if ffcgi.cgi_check_name("SQL"):
print sql, "
"
if bd_sql.execute( sql, module.TITLE ):
json_data[root]["row"] = bd_sql.get_row()
if module.FOUND_ROWS:
if bd_sql.execute( "select found_rows() as count;" ):
json_data[root]["all_count"] = bd_sql.get_row()[0][0]
else:
json_data[root]['error-message'] = module.MESSAGE
json_data[root]['error-sql'] = sql
except Exception, e:
json_data[root]['error-message'] = module.MESSAGE
json_data[root]['error-sql'] = sql
return json_data
def main():
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,'guest1880349872576419056','','webkit/None',now(),@id_domen)#созадём новую сессию для ананимоуса
- select SQL_CALC_FOUND_ROWS * from fond WHERE `FOND_ID`='432' order by FKOD asc limit 0,25;#Список фондов
- select found_rows() as count;#
список CGI параметров
параметр | значение |
---|---|
src | show |
dbg | show |
FOND_ID | 432 |
plugins | fond |