[Zope-Checkins] CVS: Zope/lib/python/Shared/DC/ZRDB - Aqueduct.py:1.53 Search.py:1.17

Michel Pelletier michel@zope.com
Wed, 31 Oct 2001 13:49:58 -0500


Update of /cvs-repository/Zope/lib/python/Shared/DC/ZRDB
In directory cvs.zope.org:/tmp/cvs-serv27799

Modified Files:
	Aqueduct.py Search.py 
Log Message:
added ZPT search interface

=== Zope/lib/python/Shared/DC/ZRDB/Aqueduct.py 1.52 => 1.53 ===
 custom_default_report_src=DocumentTemplate.File(
     os.path.join(dtml_dir,'customDefaultReport.dtml'))
+custom_default_zpt_report_src=DocumentTemplate.File(
+    os.path.join(dtml_dir,'customDefaultZPTReport.dtml'))
 
 def custom_default_report(id, result, action='', no_table=0,
                           goofy=re.compile('\W').search
@@ -315,6 +317,38 @@
 
     return custom_default_report_src(
         id=id,heading=heading,row=row,action=action,no_table=no_table)
+
+def custom_default_zpt_report(id, result, action='', no_table=0,
+                          goofy=re.compile('\W').search
+                          ):
+    columns=result._searchable_result_columns()
+    __traceback_info__=columns
+    heading=('<tr>\n%s        </tr>' %
+                 string.joinfields(
+                     map(lambda c:
+                         '          <th>%s</th>\n' % nicify(c['name']),
+                         columns),
+                     ''
+                     )
+                 )
+
+    if no_table: tr, _tr, td, _td, delim = '<p>', '</p>', '', '', ',\n'
+    else: tr, _tr, td, _td, delim = '<tr>', '</tr>', '<td>', '</td>', '\n'
+
+    row=[]
+    for c in columns:
+        n=c['name']
+# ugh! what the hell is goofy?
+#        if goofy(n) is not None:
+#            n='expr="_[\'%s]"' % (`'"'+n`[2:])
+        row.append('          %s<span tal:replace="result/%s">%s goes here</span>%s'
+                   % (td,n,n,_td))
+
+    row=('     %s\n%s\n        %s' % (tr,string.joinfields(row,delim), _tr))
+
+    return custom_default_zpt_report_src(
+        id=id, heading=heading, row=row, action=action, no_table=no_table)
+
 
 def detypify(arg):
     l=string.find(arg,':')


=== Zope/lib/python/Shared/DC/ZRDB/Search.py 1.16 => 1.17 ===
 
 from Globals import DTMLFile
-from Aqueduct import custom_default_report, nicify, Args
+from Aqueduct import custom_default_report, custom_default_zpt_report, nicify, Args
 from string import join
+from AccessControl import getSecurityManager
 
 addForm=DTMLFile('dtml/searchAdd', globals())
 def manage_addZSearch(self, report_id, report_title, report_style,
-        input_id, input_title, queries=[],
+        input_id, input_title, object_type, queries=[],
         REQUEST=None):
     'add a report'
 
@@ -109,6 +110,9 @@
     qs=map(lambda q, self=self: _getquery(self, q), queries)
     arguments={}
     keys=[]
+
+    checkPermission=getSecurityManager().checkPermission    
+
     for q in qs:
         url=q.absolute_url()
         if input_id:
@@ -127,21 +131,53 @@
                 try out the query, <a href="%s">click here</a>.
                 """ % (q.title_and_id(), url))
 
-    if input_id:
-        arguments=Args(arguments, keys)
+    if object_type == 'dtml_methods':
+
+        if not checkPermission('Add DTML Methods', self):
+            raise Unauthorized, (
+                  'You are not authorized to add DTML Methods.'
+                  )
+
+        if input_id:
+            arguments=Args(arguments, keys)
+            self.manage_addDocument(
+                input_id,input_title,
+                default_input_form(arguments, report_id))
+
         self.manage_addDocument(
-            input_id,input_title,
-            default_input_form(arguments, report_id))
+            report_id,report_title,
+            ('<dtml-var standard_html_header>\n%s\n'
+             '<dtml-var standard_html_footer>' % 
+             join(map(lambda q, report_style=report_style:
+                      custom_default_report(q.id, q, no_table=report_style), qs),
+                  '\n<hr>\n')))
+
+        if REQUEST: return self.manage_main(self,REQUEST)
+
+    elif object_type == 'page_templates':
+
+        if not checkPermission('Add Page Templates', self):
+            raise Unauthorized, (
+                  'You are not authorized to add Page Templates.'
+                  )
 
-    self.manage_addDocument(
-        report_id,report_title,
-        ('<dtml-var standard_html_header>\n%s\n'
-         '<dtml-var standard_html_footer>' % 
-         join(map(lambda q, report_style=report_style:
-                  custom_default_report(q.id, q, no_table=report_style), qs),
-              '\n<hr>\n')))
+        if input_id:
+            arguments = Args(arguments, keys)
+            self.manage_addProduct['PageTemplates'].manage_addPageTemplate(
+                input_id, input_title,
+                default_input_zpt_form(arguments, report_id))
+
+
+        self.manage_addProduct['PageTemplates'].manage_addPageTemplate(
+            report_id,report_title,
+            ('<html><body>\n%s\n'
+             '</body></html>' % 
+             join(map(lambda q, report_style=report_style:
+                      custom_default_zpt_report(q.id, q, no_table=report_style), qs),
+                  '\n<hr>\n')))
 
-    if REQUEST: return self.manage_main(self,REQUEST)
+        if REQUEST: return self.manage_main(self,REQUEST)
+        
 
 def ZQueryIds(self):
     # Note that report server configurations will expend on this
@@ -238,3 +274,64 @@
             '<dtml-var standard_html_footer>\n'
             % (tabs, action)
             )
+
+
+
+def default_input_zpt_form(arguments,action='query',
+                       tabs=''):
+    if arguments:
+        items=arguments.items()
+        return (
+            "%s\n%s%s" % (
+                '<html><body>\n%s\n'
+                '<form action="%s" method="get">\n'
+                '<h2><dtml-var document_title></h2>\n'
+                'Enter query parameters:<br>'
+                '<table>\n'
+                % (tabs,action),
+                join(
+                    map(
+                        lambda a:
+                        ('<tr><th>%s</th>\n'
+                         '    <td><input name="%s"\n'
+                         '               width=30 value="%s">'
+                         '</td></tr>'
+                         % (nicify(a[0]),
+                            (
+                                a[1].has_key('type') and
+                                ("%s:%s" % (a[0],a[1]['type'])) or
+                                a[0]
+                                ),
+                            a[1].has_key('default') and a[1]['default'] or ''
+                            ))
+                        , items
+                        ),
+                '\n'),
+                '\n<tr><td colspan=2 align=center>\n'
+                '<input type="SUBMIT" name="SUBMIT" value="Submit Query">\n'
+                '</td></tr>\n</table>\n</form>\n'
+                '</body></html>\n'
+                )
+            )
+    else:
+        return (
+            '<html><body>\n%s\n'
+            '<form action="%s" method="get">\n'
+            '<h2><dtml-var document_title></h2>\n'
+            'This query requires no input.<p>\n'
+            '<input type="SUBMIT" name="SUBMIT" value="Submit Query">\n'
+            '</td></tr>\n</table>\n</form>\n'
+            '</body></html>\n'
+            % (tabs, action)
+            )
+
+
+
+
+
+
+
+
+
+
+