00001 from django.template import Context, loader 00002 00003 __copyright__ = """\ 00004 (c). Copyright 1990-2008, Vyper Logix Corp., All Rights Reserved. 00005 00006 Published under Creative Commons License 00007 (http://creativecommons.org/licenses/by-nc/3.0/) 00008 restricted to non-commercial educational use only., 00009 00010 See also: http://www.VyperLogix.com and http://www.pypi.info for details. 00011 00012 THE AUTHOR VYPER LOGIX CORP DISCLAIMS ALL WARRANTIES WITH REGARD TO 00013 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 00014 FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00015 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00016 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00017 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00018 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE ! 00019 00020 USE AT YOUR OWN RISK. 00021 """ 00022 00023 def head(url): 00024 toks = url.split('/') 00025 url = '/'.join(toks[0:-1 if (toks[-1] == '') else len(toks)]) 00026 html=''' 00027 <link href="{{ url }}/css/flexigrid/flexigrid.css" rel="stylesheet" type="text/css" /> 00028 <script src="{{ url }}/lib/jquery/jquery.js" type="text/javascript"></script> 00029 <script src="{{ url }}/flexigrid.pack.js" type="text/javascript"></script> 00030 ''' 00031 tplate = loader.get_template_from_string(html) 00032 content = tplate.render(Context({'url': url})) 00033 return content 00034 00035 def head_list(url): 00036 return [item for item in head(url).split('\n') if (len(item.strip()) > 0)] 00037 00038 ## 00039 # 00040 # name is the name of the DOM object 00041 # width is usually something like 700 00042 # 00043 def script_content(name,width=700): 00044 from vyperlogix import misc 00045 width = 700 if (not str(width).isdigit()) else width 00046 name = 'table_grid' if (not misc.isString(name)) else name 00047 t = '''<table id="{{ name }}" width="{{ width }}" align="left"></table>''' 00048 tplate = loader.get_template_from_string(t) 00049 content = tplate.render(Context({'name': name, 'width': width})) 00050 return content 00051 00052 ## 00053 # 00054 # name is the name of the DOM object 00055 # url is something like http://127.0.0.1:8888/grid/ 00056 # dataType is something like json 00057 # colModel is something like this: 00058 # {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'left'}, 00059 # {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, 00060 # {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, 00061 # {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, 00062 # {display: 'Numcode', name : 'numcode', width : 120, sortable : true, align: 'left'}, 00063 # searchitems is something like this: 00064 # {display: 'Name', name : 'name'}, 00065 # {display: 'ISO', name : 'iso'} 00066 # sortorder is either asc or desc 00067 # usepager is either True or False as a bool 00068 # title is something that makes sense as a title 00069 # useRp is either True or False as a bool 00070 # rp is a number of items per page 00071 # showTableToggleBtn is either True of False as a bool 00072 # width is usually something like 700 00073 # height is usually something like 500 00074 # 00075 def script_head(name,url,title,colModel,searchitems,sortname,sortorder,dataType='json',usepager=True,useRp=True,rp=10,showTableToggleBtn=False,width=700,height=450): 00076 from vyperlogix import misc 00077 name = 'table_grid' if (not misc.isString(name)) else name 00078 sortorder = 'asc' if (sortorder not in ['asc','desc']) else sortorder 00079 usepager = 'true' if (usepager not in ['true','false']) else usepager 00080 useRp = 'true' if (useRp not in ['true','false']) else useRp 00081 rp = 15 if (not str(rp).isdigit()) else rp 00082 showTableToggleBtn = 'true' if (sortorder not in ['true','false']) else showTableToggleBtn 00083 width = 700 if (not str(width).isdigit()) else width 00084 height = 450 if (not str(height).isdigit()) else height 00085 js = ''' 00086 <script type="text/javascript"> 00087 $("#{{ name }}").flexigrid 00088 ( 00089 { 00090 url: '{{ url }}', 00091 dataType: '{{ dataType }}', 00092 colModel : [ {{ colModel }} ], 00093 searchitems : [ {{ searchitems }} ], 00094 sortname: "{{ sortname }}", 00095 sortorder: "{{ sortorder }}", 00096 usepager: {{ usepager }}, 00097 title: '{{ title }}', 00098 useRp: {{ useRp }}, 00099 rp: {{ rp }}, 00100 showTableToggleBtn: {{ showTableToggleBtn }}, 00101 width: {{ width }}, 00102 height: {{ height }} 00103 } 00104 ); 00105 </script> 00106 ''' 00107 tplate = loader.get_template_from_string(js) 00108 content = tplate.render(Context({'name': name, 'url': url, 'dataType': dataType, 'colModel': colModel, 'searchitems':searchitems, 'sortname':sortname, 'sortorder':sortorder, 'usepager':usepager, 'title':title, 'useRp':useRp, 'rp':rp, 'showTableToggleBtn': showTableToggleBtn, 'width': width, 'height': height})) 00109 return content 00110 00111 ## 00112 # 00113 # name is the name of the DOM object 00114 # url is something like http://127.0.0.1:8888/grid/ 00115 # dataType is something like json 00116 # colModel is something like this: 00117 # {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'left'}, 00118 # {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, 00119 # {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, 00120 # {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, 00121 # {display: 'Numcode', name : 'numcode', width : 120, sortable : true, align: 'left'}, 00122 # searchitems is something like this: 00123 # {display: 'Name', name : 'name'}, 00124 # {display: 'ISO', name : 'iso'} 00125 # sortorder is either asc or desc 00126 # usepager is either True or False as a bool 00127 # title is something that makes sense as a title 00128 # useRp is either True or False as a bool 00129 # rp is a number of items per page 00130 # showTableToggleBtn is either True of False as a bool 00131 # width is usually something like 700 00132 # height is usually something like 500 00133 # 00134 def script(name,url,title,colModel,searchitems,sortname,sortorder,dataType='json',usepager=True,useRp=True,rp=10,showTableToggleBtn=False,width=700,height=450): 00135 js = ''' 00136 {{ SCRIPT_CONTENT }} 00137 {{ SCRIPT_HEAD }} 00138 ''' 00139 tplate = loader.get_template_from_string(js) 00140 content = tplate.render(Context({'name': name, 'url': url, 'dataType': dataType, 'colModel': colModel, 'searchitems':searchitems, 'sortname':sortname, 'sortorder':sortorder, 'usepager':usepager, 'title':title, 'useRp':useRp, 'rp':rp, 'showTableToggleBtn': showTableToggleBtn, 'width': width, 'height': height, 'SCRIPT_CONTENT':script_content(name,width=width), 'SCRIPT_HEAD':script_head(name,url,title,colModel,searchitems,sortname,sortorder,dataType=dataType,usepager=usepager,useRp=useRp,rp=rp,showTableToggleBtn=showTableToggleBtn,width=width,height=height)})) 00141 return ''.join(content.split('\n')) 00142 00143 if (__name__ == '__main__'): 00144 import sys 00145 print >>sys.stdout, __copyright__ 00146 print >>sys.stderr, __copyright__ 00147 00148 00149
© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."
Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.
122,241 lines of code and growing...