[Zope3-checkins] CVS: Zope3/src/zope/products/codecontent/browser - __init__.py:1.1.2.1 configure.zcml:1.1.2.1 dtml.gif:1.1.2.1 dtmlpageeval.py:1.1.2.1 preview.pt:1.1.2.1 sql.py:1.1.2.1 sqladd.pt:1.1.2.1 sqledit.pt:1.1.2.1 sqltest.pt:1.1.2.1 sqltestresults.pt:1.1.2.1 zpt.gif:1.1.2.1 zpt.py:1.1.2.1 zpt_inlinecode.pt:1.1.2.1

Philipp von Weitershausen philikon at philikon.de
Sun Feb 8 09:03:44 EST 2004


Update of /cvs-repository/Zope3/src/zope/products/codecontent/browser
In directory cvs.zope.org:/tmp/cvs-serv10229/products/codecontent/browser

Added Files:
      Tag: philikon-movecontent-branch
	__init__.py configure.zcml dtml.gif dtmlpageeval.py preview.pt 
	sql.py sqladd.pt sqledit.pt sqltest.pt sqltestresults.pt 
	zpt.gif zpt.py zpt_inlinecode.pt 
Log Message:
Move zope.app.content,
     zope.app.interfaces.content,
 and zope.app.browser.content
to zope.products.content and zope.products.codecontent, respectively.


=== Added File Zope3/src/zope/products/codecontent/browser/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/products/codecontent/browser/configure.zcml ===
<zope:configure
   xmlns="http://namespaces.zope.org/browser"
   xmlns:zope="http://namespaces.zope.org/zope"
   xmlns:help="http://namespaces.zope.org/help">


  <!-- SQL Script View Directives -->
  
  <addform
      schema="zope.products.codecontent.interfaces.sql.ISQLScript"
      label="Add a SQL Script"
      content_factory="zope.products.codecontent.sql.SQLScript"
      keyword_arguments="connectionName source arguments"
      name="zope.products.codecontent.sql"
      permission="zope.ManageContent"
      template="sqladd.pt"
      class=".sql.SQLScriptAdd"
      /> 
      
  <editform
      schema="zope.products.codecontent.interfaces.sql.ISQLScript"
      name="edit.html"
      menu="zmi_views"
      label="Edit an SQL script"
      permission="zope.ManageContent"
      template="sqledit.pt"
      class=".sql.SQLScriptEdit" 
      />

  <pages
      for="zope.products.codecontent.interfaces.sql.ISQLScript"
      permission="zope.View"
      class="zope.products.codecontent.browser.sql.SQLScriptTest" >

    <page
        name="test.html"
        template="sqltest.pt" 
        menu="zmi_views"
        title="[test-page-title] Test"
        />
    <page
        name="testResults.html"
        template="sqltestresults.pt"
        />

  </pages>
  
  <addMenuItem
      title="SQLScript"
      class="zope.products.codecontent.sql.SQLScript"
      permission="zope.ManageContent"   
      view="zope.products.codecontent.sql" /> 

<!-- DTML Page View Directives -->

  <page
      name="index.html"
      for="zope.products.codecontent.dtmlpage.IDTMLPage"
      permission="zope.View"
      class="zope.products.codecontent.browser.dtmlpageeval.DTMLPageEval"
      attribute="index" />

  <editform
      schema="zope.products.codecontent.dtmlpage.IDTMLPage"
      name="edit.html"
      menu="zmi_views"
      label="Edit a DTML page"
      permission="zope.ManageContent" />

  <page
      for="zope.products.codecontent.dtmlpage.IDTMLPage"
      name="preview.html"
      menu="zmi_views" title="Preview"
      template="preview.pt"
      permission="zope.ManageContent" />

  <icon
      name="zmi_icon"
      for="zope.products.codecontent.dtmlpage.IDTMLPage"
      file="dtml.gif" />

  <addform
      schema="zope.products.codecontent.interfaces.dtmlpage.IDTMLPage"
      label="Add a DTML Page"
      content_factory="zope.products.codecontent.dtmlpage.DTMLPage"
      name="zope.products.codecontent.dtmlpage.DTMLPage"
      permission="zope.ManageContent"
      />

  <addMenuItem
      class="zope.products.codecontent.dtmlpage.DTMLPage"
      title="DTML Page"
      view="zope.products.codecontent.dtmlpage.DTMLPage"
      permission="zope.ManageContent"
      />


<!-- ZPT Page View Directives -->

  <page
      name="index.html"
      for="zope.products.codecontent.zpt.IZPTPage"
      class="zope.products.codecontent.browser.zpt.ZPTPageEval"
      attribute="index"
      permission="zope.View" />

  <page
      name="source.html"
      for="zope.products.codecontent.zpt.IZPTPage"
      class="zope.products.codecontent.zpt.ZPTSourceView"
      attribute="__call__"
      permission="zope.ManageContent" />

  <addMenuItem
      class="zope.products.codecontent.zpt.ZPTPage"
      title="Templated Page"
      permission="zope.ManageContent"
      view="zope.products.codecontent.zpt.ZPTPage"
      />

  <addform
      schema="zope.products.codecontent.interfaces.zpt.IZPTPage"
      label="Add a ZPT Page"
      content_factory="zope.products.codecontent.zpt.ZPTPage"
      name="zope.products.codecontent.zpt.ZPTPage"
      permission="zope.ManageContent"
      />

  <editform
      for="zope.products.codecontent.zpt.IZPTPage"
      schema="zope.products.codecontent.zpt.IZPTPage"
      name="edit.html"
      label="Edit a ZPT page"
      fields="source expand"
      permission="zope.ManageContent" 
      menu="zmi_views" title="Edit"
      />

  <editform
      for="zope.products.codecontent.zpt.IZPTPage"
      schema="zope.products.codecontent.zpt.IZPTPage"
      name="inlineCode.html"
      label="Inline Code"
      fields="evaluateInlineCode"
      template="zpt_inlinecode.pt"
      permission="zope.ManageContent" 
      menu="zmi_views" title="Inline Code"
      />

  <page
      for="zope.products.codecontent.zpt.IZPTPage"
      name="preview.html"
      menu="zmi_views" title="Preview"
      template="preview.pt"
      permission="zope.ManageContent"
      />

  <icon 
      name="zmi_icon"
      for="zope.products.codecontent.zpt.IZPTPage" 
      file="zpt.gif"
      />

</zope:configure>


=== Added File Zope3/src/zope/products/codecontent/browser/dtml.gif ===
  <Binary-ish file>

=== Added File Zope3/src/zope/products/codecontent/browser/dtmlpageeval.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Define view component for ZPT page eval results.

$Id: dtmlpageeval.py,v 1.1.2.1 2004/02/08 14:03:41 philikon Exp $
"""
__metaclass__ = type

class DTMLPageEval:

    def index(self, REQUEST=None, **kw):
        """Call a Page Template"""

        template = self.context
        return template.render(REQUEST, **kw)


=== Added File Zope3/src/zope/products/codecontent/browser/preview.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>
<div metal:fill-slot="body">

  <iframe src="." height="98%" width="98%"></iframe>

</div>
</body>
</html>


=== Added File Zope3/src/zope/products/codecontent/browser/sql.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""SQL Script Views

$Id: sql.py,v 1.1.2.1 2004/02/08 14:03:41 philikon Exp $
"""

from zope.app.browser.form.add import AddView
from zope.app.browser.form.submit import Update
from zope.app.interfaces.rdb import DatabaseException
from zope.app.interfaces.container import IAdding
from zope.app import zapi

from zope.products.codecontent.interfaces.sql import ISQLScript
from zope.products.codecontent.sql import SQLScript

class SQLScriptTest(object):
    """Test the SQL inside the SQL Script
    """

    __used_for__ = ISQLScript

    error = None

    def getArguments(self):
        form = self.request.form
        arguments = {}

        for argname, argvalue in self.context.getArguments().items():
            value = form.get(argname)
            if value is None:
                value = argvalue.get('default')
            if value is not None:
                arguments[argname.encode('UTF-8')] = value
        return arguments

    def getTestResults(self):
        try:
            return self.context(**self.getArguments())
        except (DatabaseException, AttributeError, Exception), error:
            self.error = error
            return []

    def getFormattedError(self):
        error = str(self.error)
        return error

    def getRenderedSQL(self):
        return self.context.getTemplate()(**self.getArguments())


class SQLScriptAdd(object):
    """Provide interface to add SQL Script
    """
    
    def update(self):
        """ Set the Update variable for Add and Test
        >>> from zope.publisher.browser import TestRequest
        
        >>> rqst = TestRequest()
        >>> class Base(object):
        ...     def __init__(self, request):
        ...         self.request = request
        ...     def update(self):
        ...         self.updated = 1
         
        >>> class V(SQLScriptAdd, Base):
        ...     pass
        
        >>> dc = V(rqst)
        >>> res = 0
        >>> dc.update()
        >>> dc.updated
        1
        >>> 'UPDATE_SUBMIT' in rqst
        False
        >>> d = {'add_test':1}
        >>> rqst1 = TestRequest(form = d)
        >>> dc1 = V(rqst1)
        >>> dc1.update()
        >>> 'UPDATE_SUBMIT' in rqst1
        True
        """
        if 'add_test' in self.request:
            self.request.form[Update] = ''
            
        return super(SQLScriptAdd, self).update()
        
              
    def nextURL(self):
        """
        >>> from zope.publisher.browser import TestRequest
        >>> from zope.app.tests.placelesssetup import setUp, tearDown
        >>> setUp()
        >>> rqst = TestRequest()
        >>> class Base(object):
        ...     def __init__(self, request):
        ...         self.request = request
        ...         self.context = self
        ...         self.contentName = 'new srcipt'
        ...     def __getitem__(self, key):
        ...         return None
        ...     def nextURL(self):
        ...         return "www.zeomega.com"
        
        >>> class V(SQLScriptAdd, Base):
        ...     pass
        >>> 
        >>> rqst = TestRequest()
        >>> dc = V(rqst)
        >>> dc.nextURL()
        'www.zeomega.com'
        >>> d = {'add_test':1}
        >>> rqst1 = TestRequest(form = d)
        >>> dc1 = V(rqst1)
        >>> dc1.nextURL()
        'http://127.0.0.1/test.html'

        """


        if 'add_test' in self.request:
            name = self.context.contentName
            container = self.context.context
            obj = container[name]
            url = zapi.getView(obj, 'absolute_url', self.request)()
            url = '%s/test.html' % url
            return url
        else:
            return super(SQLScriptAdd, self).nextURL()
       
        
        

# *********** Edit ************

class SQLScriptEdit(object):
    """Provide interface to Edit and Test  SQL Script """
     

        
    def update(self):

        """ Set the Update variable for Change and Test
        >>> from zope.publisher.browser import TestRequest
        
        >>> rqst = TestRequest()
        >>> class Base(object):
        ...     def __init__(self, request):
        ...         self.request = request
        ...         self.errors  = ('no errors')
        ...     def update(self):
        ...         self.updated = 1
        ...         return "update returned"
        
         
        >>> class V(SQLScriptEdit, Base):
        ...     pass
        
        >>> dc = V(rqst)
        >>> res = 0
        >>> dc.update()
        'update returned'
        >>> dc.updated
        1
        >>> 'UPDATE_SUBMIT' in rqst
        False
        >>>
        

        >>> d = {'change_test':1}
        >>> rqst1 = TestRequest(form = d)
        >>> dc1 = V(rqst1)
        >>> dc1.errors = ()
        >>> dc1.update()
        'update returned'
        >>> 'UPDATE_SUBMIT' in rqst1
        True
        >>> dc1.updated
        1
        >>> rqst1.response.getHeader('location')
        'test.html'
        >>> rqst1.response.getStatus()
        302
           
        >>> d = {'change_test':1}
        >>> rqst2 = TestRequest(form = d)
        >>> dc2 = V(rqst2)
        >>> dc2.errors = ('errorname',1234)
        >>> dc2.update()
        'update returned'
        >>> 'UPDATE_SUBMIT' in rqst2
        True
        >>> rqst2.response.getHeader('location')
        
        >>> rqst2.response.getStatus()
        599

        """
        
       
        if 'change_test' in self.request:
            self.request.form[Update] = ''
            super(SQLScriptEdit, self).update()
            if not self.errors:
                url = 'test.html'
                self.request.response.redirect(url)
        return super(SQLScriptEdit, self).update()


=== Added File Zope3/src/zope/products/codecontent/browser/sqladd.pt ===
<html metal:use-macro="context/@@standard_macros/page">

  <head>
    <title>SQL Script</title>
  </head>
  <body>
 
    <div metal:fill-slot="body">
        
       <div metal:use-macro="view/generated_form/macros/body">
            <input type="submit" value="Add And Test" 
                  metal:fill-slot="extra_buttons" name="add_test" />
       </div>
   </div>
  </body>

</html>


=== Added File Zope3/src/zope/products/codecontent/browser/sqledit.pt ===
<html metal:use-macro="context/@@standard_macros/page">

  <head>
    <title>SQL Script</title>
  </head>
  <body>
 
    <div metal:fill-slot="body">
        
       <div metal:use-macro="view/generated_form/macros/body">
            <input type="submit" value="Change And Test" 
                  metal:fill-slot="extra_buttons" name="change_test" />
       </div>
   </div>
  </body>

</html>


=== Added File Zope3/src/zope/products/codecontent/browser/sqltest.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>

<div metal:fill-slot="body">
<form action="." method="post">

  <pre tal:content="context/source" />

  <table border="1"
      tal:define="args context/getArguments"
      tal:condition="args">
    <tbody>
      <tr>
        <th i18n:translate="">Argument Name</th>
        <th i18n:translate="">Type</th>
        <th i18n:translate="">Value</th>
      </tr>

      <tr tal:repeat="arg python: args.keys()">
        <td tal:content="arg"></td>
        <td tal:content="python: args[arg].get('type')"> </td>
        <td><input type="text" name="" size="10" value=""
                tal:attributes="value python: args[arg].get('default');
                                name arg"/></td>
      </tr>


    </tbody>
  </table>

  <input type="submit" name="testResults.html:method" value="Test"
         i18n:attributes="value test-button"/>

</form>
</div>

</body>
</html>


=== Added File Zope3/src/zope/products/codecontent/browser/sqltestresults.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>

<div metal:fill-slot="body">

  <pre tal:content="view/getRenderedSQL" />

  <table border="1" cellspacing="0" cellpadding="2"
      tal:define="result view/getTestResults"
      tal:condition="result">
    <tbody>

      <tr>
        <th tal:repeat="field result/columns"
            tal:content="field">Field Name</th>
      </tr>

      <tr tal:repeat="row result">
        <td tal:repeat="field result/columns"
            tal:content="python: getattr(row, field)">Value</td>
      </tr>


    </tbody>
  </table>

  <tal:block tal:condition="view/error">
    <h3 i18n:translate="">An Error occurred</h3>
    <pre tal:content="view/getFormattedError" />
  </tal:block>

</div>

</body>
</html>


=== Added File Zope3/src/zope/products/codecontent/browser/zpt.gif ===
  <Binary-ish file>

=== Added File Zope3/src/zope/products/codecontent/browser/zpt.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Define view component for ZPT page eval results.

$Id: zpt.py,v 1.1.2.1 2004/02/08 14:03:41 philikon Exp $
"""
class ZPTPageEval:

    def index(self, **kw):
        """Call a Page Template"""

        template = self.context
        request = self.request

        request.response.setHeader('content-type',
                                   template.content_type)

        return template.render(request, **kw)


=== Added File Zope3/src/zope/products/codecontent/browser/zpt_inlinecode.pt ===
<tal:tag condition="view/update"
/><html metal:use-macro="views/standard_macros/page">
  <body>
  <div metal:fill-slot="body">

  <div metal:define-macro="body">

    <form action="." tal:attributes="action request/URL" method="POST"
          enctype="multipart/form-data">

      <div metal:define-macro="formbody">

        <h3 tal:condition="view/label"
            tal:content="view/label"
            metal:define-slot="heading"
            >Edit something</h3>

        <div style="color:red; font-weight: bold">
          <p i18n:translate="">
            This screen allows you to activate Inline Code Evaluation. This
            means that you can say
            <span i18n:name="code-example-1"><pre>
               &lt;script type="text/server-python"&gt;<br/>
               &nbsp;&nbsp;print "Hello World!"<br/>
               &lt;/script&gt;
            </pre></span>
            or
            <span i18n:name="code-example-2"><pre>
               &lt;p tal:script="text/server-python"&gt;<br/>
               &nbsp;&nbsp;print "Hello World!"<br/>
               &lt;/p&gt;
            </pre></span>
          </p>
          <p i18n:translate="">
            Many Zope 3 developers consider inline code blocks something
            very bad, since it does not follow the design of Page Templates
            or Zope 3 in general. However, application and application server
            developers are not the only audience for Zope 3. Scripters are
            used to inline code from other technologies like PHP and it fits
            their brain, which is very important.
          </p>
        </div>

        <p tal:define="status view/update"
           tal:condition="status"
           tal:content="status" />

         <p tal:condition="view/errors" i18n:translate="">
           There are  <strong tal:content="python:len(view.errors)"
                              i18n:name="num_errors">6</strong> input errors.
        </p>

        <tal:block repeat="error view/errors">
          <div class="error" tal:content="error">error</div>
        </tal:block>

        <div class="row"
             metal:define-macro="widget_rows" tal:repeat="widget view/widgets"
             tal:content="structure widget/row">
            <div class="label">Name</div>
            <div class="field"><input type="text" style="width:100%" /></div>
        </div>

      </div>

      <div class="row">
        <div class="controls">
          <input type="submit" value="Refresh" 
              i18n:attributes="value refresh-button" />
          <input type="submit" name="UPDATE_SUBMIT" value="Submit" 
              i18n:attributes="value submit-button"/>
        </div>
      </div>

    </form>

  </div>

  </div>
  </body>

</html>




More information about the Zope3-Checkins mailing list