예제 #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 = 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 __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
     """Render the DTML"""
     security = getSecurityManager()
     security.addContext(self)
     try:
         return HTML.__call__(self, client, REQUEST, **kw)
     finally:
         security.removeContext(self)
예제 #3
0
 def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
     """Render the DTML"""
     security = getSecurityManager()
     security.addContext(self)
     try:
         return HTML.__call__(self, client, REQUEST, **kw)
     finally:
         security.removeContext(self)
def fs_dtml_cooker(self, descriptor, object):

    if object.meta_type.startswith('Filesystem'):
        object._updateFromFS()
    
    security = getSecurityManager()
    security.addContext(object)

    portal = getToolByName(object, 'portal_url').getPortalObject()

    try:
        r = HTML.__call__(object, None, portal)
        descriptor.setRendered(r)
    finally:
        security.removeContext(object)
예제 #5
0
def test4():
    h = HTML("""
        <!--#if expr="level==1"-->
        level was 1
        <!--#elif expr="level==2"-->
        level was 2
        <!--#elif expr="level==3"-->
        level was 3
        <!--#else-->
        level was something else
        <!--#endif-->
        """)

    for i in range(4):
        print('-' * 77)
        print('%s%s' % (i, h(level=i)))
    print('-' * 77)
예제 #6
0
    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 Exception:
            src = 'Could not render the query template!'

        result = ()
        t = v = tb = None
        try:
            try:
                src, result = self(REQUEST, test__=1)
                if src.find('\0'):
                    src = ('\n' + '-' * 60 + '\n').join(src.split('\0'))
                if result._searchable_result_columns():
                    r = custom_default_report(self.id, result)
                else:
                    r = 'This statement returned no results.'
            except Exception:
                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 = 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
예제 #7
0
파일: DTML.py 프로젝트: SmartTeleMax/ppa
 def compileString(self, source, template_name, get_template):
     program = HTML(source)
     program.cook()
     return program
예제 #8
0
def test3():
    print(HTML('area code=<!--#var expr="phone*1000"-->')(phone='7035551212'))
예제 #9
0
def test2():
    print(
        HTML('area code=<!--#var expr="phone.number"-->')(phone='7035551212'))
예제 #10
0
def test1():
    print(HTML('area code=<!--#var expr="phone[:3]"-->')(phone='7035551212'))
예제 #11
0
파일: DA.py 프로젝트: bendavis78/zope
 def manage_testForm(self, REQUEST):
     " "
     input_src = default_input_form(self.title_or_id(), self._arg,
                                    'manage_test', '<dtml-var manage_tabs>')
     return HTML(input_src)(self, REQUEST, HTTP_REFERER='')
예제 #12
0
    def manage_test(self, REQUEST):
        'Perform an actual query'

        result = self(REQUEST)
        report = HTML(custom_default_report(self.id, result))
        return report(*(self, REQUEST), **{self.id: result})
예제 #13
0
 def manage_testForm(self, REQUEST):
     """Provide testing interface"""
     input_src = default_input_form(self.title_or_id(),
                                    self._searchable_arguments(),
                                    'manage_test')
     return HTML(input_src)(self, REQUEST)
예제 #14
0
# ? the ramifications of when and where this dtml gets executed are
# not yet clear ...

# would like to move these to separate files.. how do I define
# these in such a way that "<dtml-var id>" will work at runtime ?
#
# also would prefer not to inline the header in editform & backlinks
#
#default_wiki_page =   HTMLFile('default_wiki_page', globals())
#default_wiki_header = HTMLFile('default_wiki_header', globals())
#default_wiki_footer = HTMLFile('default_wiki_footer', globals())
#default_editform =    HTMLFile('default_editform', globals())
#default_backlinks =   HTMLFile('default_backlinks', globals())

#####################################################################
default_wiki_page = HTML(source_string='''Describe <dtml-var page> here
''')
#####################################################################
default_wiki_header = HTML(source_string='''<dtml-if standard_html_header>
  <dtml-var standard_html_header>
<dtml-else>
  <HTML>
  <HEAD>
  <TITLE><dtml-var titleprefix missing> <dtml-var id> of 
         <dtml-with aq_parent><dtml-var id></dtml-with>
         <dtml-var id></TITLE>
  </HEAD>
  <BODY BGCOLOR="#FFFFFF">
</dtml-if>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td> <small>
예제 #15
0
    d(name='chessie',age=2),
    )

html="""
<!--#in data mapping-->
  <!--#var name-->, <!--#var age-->
<!--#else-->
  <!--#in xxx    -->
    <!--#var name-->
  <!--#/in-->
  Sorry, no data
<!--#/in-->
"""

print '='*74
print HTML(html)(data=data, xxx=xxx)
print '='*74
print HTML(html)(xxx=xxx)
print '='*74

s="""
%(in data mapping)[
  %(name)s, %(age)s
%(else)[
  %(in xxx)[
    %(name)s
  %(in)]
  Sorry, no data
%(in)]
"""