示例#1
0
    def manage_test(self, query, REQUEST=None):
        "Executes the SQL in parameter 'query' and returns results"
        dbc=self()      #get our connection
        res=dbc.query(query)

        if type(res) is type(''):
            f=StringIO()
            f.write(res)
            f.seek(0)
            result=RDB.File(f)
        else:
            result=Results(res)

        if REQUEST is None:
            return result       #return unadulterated result objects

        if result._searchable_result_columns():
            r=custom_default_report(self.id, result)
        else:
            r='This statement returned no results.'

        report=DocumentTemplate.HTML(
            '<html><body bgcolor="#ffffff" link="#000099" vlink="#555555">\n'
            '<dtml-var name="manage_tabs">\n<hr>\n%s\n\n'
            '<hr><h4>SQL Used:</strong><br>\n<pre>\n%s\n</pre>\n<hr>\n'
            '</body></html>'
            % (r, query))

        report=apply(report,(self,REQUEST),{self.id:result})

        return report
示例#2
0
    def manage_test(self, query, REQUEST=None):
        "Executes the SQL in parameter 'query' and returns results"
        dbc = self()  #get our connection
        res = dbc.query(query)

        if type(res) is type(''):
            f = StringIO()
            f.write(res)
            f.seek(0)
            result = RDB.File(f)
        else:
            result = Results(res)

        if REQUEST is None:
            return result  #return unadulterated result objects

        if result._searchable_result_columns():
            r = custom_default_report(self.id, result)
        else:
            r = 'This statement returned no results.'

        report = HTML(
            '<html><body bgcolor="#ffffff" link="#000099" vlink="#555555">\n'
            '<dtml-var name="manage_tabs">\n<hr>\n%s\n\n'
            '<hr><h4>SQL Used:</strong><br>\n<pre>\n%s\n</pre>\n<hr>\n'
            '</body></html>' % (r, query))

        report = apply(report, (self, REQUEST), {self.id: result})

        return report
示例#3
0
文件: DA.py 项目: bendavis78/zope
    def manage_test(self, REQUEST):
        """Test an SQL method."""
        # Try to render the query template first so that the rendered
        # source will be available for the error message in case some
        # error occurs...
        try:
            src = self(REQUEST, src__=1)
        except:
            src = "Could not render the query template!"
        result = ()
        t = v = tb = None
        try:
            try:
                src, result = self(REQUEST, test__=1)
                if string.find(src, '\0'):
                    src = string.join(string.split(src, '\0'),
                                      '\n' + '-' * 60 + '\n')
                if result._searchable_result_columns():
                    r = custom_default_report(self.id, result)
                else:
                    r = 'This statement returned no results.'
            except:
                t, v, tb = sys.exc_info()
                r = '<strong>Error, <em>%s</em>:</strong> %s' % (t, v)

            report = HTML(
                '<html>\n'
                '<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">\n'
                '<dtml-var manage_tabs>\n<hr>\n%s\n\n'
                '<hr><strong>SQL used:</strong><br>\n<pre>\n%s\n</pre>\n<hr>\n'
                '</body></html>' % (r, html_quote(src)))

            report = apply(report, (self, REQUEST), {self.id: result})

            if tb is not None:
                self.raise_standardErrorMessage(None, REQUEST, t, v, tb, None,
                                                report)

            return report

        finally:
            tb = None
示例#4
0
文件: DA.py 项目: wpjunior/proled
    def manage_test(self, REQUEST):
        """Test an SQL method."""
        # Try to render the query template first so that the rendered
        # source will be available for the error message in case some
        # error occurs...
        try:
            src = self(REQUEST, src__=1)
        except:
            src = "Could not render the query template!"
        result = ()
        t = v = tb = None
        try:
            try:
                src, result = self(REQUEST, test__=1)
                if find(src, "\0"):
                    src = join(split(src, "\0"), "\n" + "-" * 60 + "\n")
                if result._searchable_result_columns():
                    r = custom_default_report(self.id, result)
                else:
                    r = "This statement returned no results."
            except:
                t, v, tb = sys.exc_info()
                r = "<strong>Error, <em>%s</em>:</strong> %s" % (t, v)

            report = DocumentTemplate.HTML(
                "<html>\n"
                '<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">\n'
                "<dtml-var manage_tabs>\n<hr>\n%s\n\n"
                "<hr><strong>SQL used:</strong><br>\n<pre>\n%s\n</pre>\n<hr>\n"
                "</body></html>" % (r, html_quote(src))
            )

            report = apply(report, (self, REQUEST), {self.id: result})

            if tb is not None:
                self.raise_standardErrorMessage(None, REQUEST, t, v, tb, None, report)

            return report

        finally:
            tb = None
示例#5
0
def manage_addZSearch(self, report_id, report_title, report_style,
        input_id, input_title, object_type, queries=[],
        REQUEST=None):
    'add a report'

    if not queries: raise ValueError, (
        'No <em>searchable objects</em> were selected')

    if not report_id: raise ValueError, (
        'No <em>report id</em> were specified')

    if input_title and not input_id: raise ValueError, (
        'No <em>input id</em> were specified')

    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:
            for name, arg in q._searchable_arguments().items():
                if len(qs) > 1: key="%s/%s" % (id,name)
                else: key=name
                arguments[key]=arg
                keys.append(key)
        if q._searchable_result_columns() is None:
            raise 'Unusable Searchable Error',(
                """The input searchable object, <em>%s</em>,
                has not been tested.  Until it has been tested,
                it\'s output schema is unknown, and a report
                cannot be generated.  Before creating a report
                from this query, you must try out the query.  To
                try out the query, <a href="%s">click here</a>.
                """ % (q.title_and_id(), url))

    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(
            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.'
                  )

        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)
示例#6
0
文件: Search.py 项目: bendavis78/zope
def manage_addZSearch(self,
                      report_id,
                      report_title,
                      report_style,
                      input_id,
                      input_title,
                      object_type,
                      queries=[],
                      REQUEST=None):
    'add a report'

    if not queries:
        raise ValueError, ('No <em>searchable objects</em> were selected')

    if not report_id:
        raise ValueError, ('No <em>report id</em> were specified')

    if input_title and not input_id:
        raise ValueError, ('No <em>input id</em> were specified')

    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:
            for name, arg in q._searchable_arguments().items():
                if len(qs) > 1: key = "%s/%s" % (id, name)
                else: key = name
                arguments[key] = arg
                keys.append(key)
        if q._searchable_result_columns() is None:
            raise ValueError, ("""The input searchable object, <em>%s</em>,
                has not been tested.  Until it has been tested,
                it\'s output schema is unknown, and a report
                cannot be generated.  Before creating a report
                from this query, you must try out the query.  To
                try out the query, <a href="%s">click here</a>.
                """ % (escape(q.title_and_id()), escape(url, 1)))

    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(
            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.')

        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)