[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[OpenTAL-checkins] opental/OpenPT ZOPT.py __init__.py www/ptAdd.pt...
From: |
Fernando Lalo Martins |
Subject: |
[OpenTAL-checkins] opental/OpenPT ZOPT.py __init__.py www/ptAdd.pt... |
Date: |
Sun, 26 Jan 2003 21:04:17 -0500 |
CVSROOT: /cvsroot/opental
Module name: opental
Changes by: Fernando Lalo Martins <address@hidden> 03/01/26 21:04:16
Modified files:
OpenPT : ZOPT.py __init__.py
OpenPT/www : ptAdd.pt
Added files:
OpenPT/default_text: empty_html.pt plone.pt sample.pt
Removed files:
OpenPT/www : default.html
Log message:
Now when you instantiate a ZopePageTemplate, you can choose one from a
set
of built-in files with default text (to add more, just drop foo.pt files
in the default_text dir), or upload yours.
FIXME: to allow that to work, I had to make ptAdd a ZopePageTemplate.
This is a kludge; I will implement a replacement for FSPageTemplate
right away.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/ZOPT.py.diff?tr1=1.39&tr2=1.40&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/__init__.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/default_text/empty_html.pt?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/default_text/plone.pt?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/default_text/sample.pt?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/www/ptAdd.pt.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: opental/OpenPT/ZOPT.py
diff -u opental/OpenPT/ZOPT.py:1.39 opental/OpenPT/ZOPT.py:1.40
--- opental/OpenPT/ZOPT.py:1.39 Thu Jan 16 19:21:30 2003
+++ opental/OpenPT/ZOPT.py Sun Jan 26 21:04:16 2003
@@ -21,7 +21,8 @@
import cPickle as pickle
#import pickle
-import os, AccessControl, Acquisition, sys
+import os, AccessControl, Acquisition, sys, fnmatch
+from App.FactoryDispatcher import FactoryDispatcher
from Acquisition import aq_base
from Globals import DTMLFile, ImageFile, MessageDialog, package_home
from zLOG import LOG, ERROR, INFO
@@ -176,6 +177,8 @@
if hasattr(pax, 'xml2pax'):
source_types['XML'] = pax.xml2pax
+default_text_dir = os.path.join(package_home(globals()), 'default_text')
+
# FIXME: lots of stuff below can probably be refactored out -
# there is still a lot of cruft pasted from ZPT
@@ -213,8 +216,6 @@
'name_request': 'request',
'name_modules': 'modules',
}
- _default_content_fn = os.path.join(package_home(globals()),
- 'www', 'default.html')
manage_options = (
{'label':'Edit', 'action':'pt_editForm',
@@ -234,11 +235,13 @@
'select_variable': 'pt_handler_list'},
)
- def __init__(self, id, text=None):
+ def __init__(self, id, text_fn):
self.id = str(id)
self.ZBindings_edit(self._default_bindings)
- if text is None:
- text = open(self._default_content_fn).read()
+ if text_fn is None:
+ text = '<openpt />'
+ else:
+ text = open(os.path.join(default_text_dir, text_fn)+'.pt').read()
self.macros = make_macro_collection()
self.pt_edit(text)
@@ -561,18 +564,20 @@
Globals.InitializeClass(ZopePageTemplate)
-manage_addPageTemplateForm = PageTemplateFile(
- 'www/ptAdd.pt', globals(), __name__='manage_addPageTemplateForm')
+manage_addPageTemplateForm = ZopePageTemplate('manage_addPageTemplateForm',
None)
+manage_addPageTemplateForm.write(
+ open(os.path.join(package_home(globals()), 'www', 'ptAdd.pt')).read())
+manage_addPageTemplateForm.__name__ = manage_addPageTemplateForm.id
from urllib import quote
-def manage_addPageTemplate(self, id, title=None, text=None,
+def manage_addPageTemplate(self, id, title=None, text_fn=None,
REQUEST=None, submit=None):
"Add a Page Template with optional file content."
id = str(id)
if REQUEST is None:
- self._setObject(id, ZopePageTemplate(id, text))
+ self._setObject(id, ZopePageTemplate(id, text_fn))
ob = getattr(self, id)
if title:
ob.pt_setTitle(title)
@@ -581,9 +586,11 @@
file = REQUEST.form.get('file')
headers = getattr(file, 'headers', None)
if headers is None or not file.filename:
- zpt = ZopePageTemplate(id)
+ zpt = ZopePageTemplate(id, text_fn)
else:
- zpt = ZopePageTemplate(id, file, headers.get('content_type'))
+ zpt = ZopePageTemplate(id, None)
+ zpt.pt_edit(file)
+ zpt.content_type = headers.get('content_type')
self._setObject(id, zpt)
@@ -592,6 +599,18 @@
if submit==" Add and Edit ": u="%s/%s" % (u,quote(id))
REQUEST.RESPONSE.redirect(u+'/manage_main')
return ''
+
+
+class __FactoryDispatcher__(FactoryDispatcher):
+ "customized FactoryDispatcher for OpenPT"
+ security = AccessControl.ClassSecurityInfo()
+ security.declareObjectProtected('Add Page Templates')
+ security.declareProtected('Add Page Templates', 'default_text_dir')
+ def default_text_dir(*a, **kw):
+ return [name[:-3] for name in os.listdir(default_text_dir) if
+ fnmatch.fnmatch(name, '*.pt')]
+Globals.InitializeClass(__FactoryDispatcher__)
+
def initialize(context):
context.registerClass(
Index: opental/OpenPT/__init__.py
diff -u opental/OpenPT/__init__.py:1.4 opental/OpenPT/__init__.py:1.5
--- opental/OpenPT/__init__.py:1.4 Thu Jan 16 18:09:50 2003
+++ opental/OpenPT/__init__.py Sun Jan 26 21:04:16 2003
@@ -15,4 +15,4 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
-from ZOPT import initialize
+from ZOPT import initialize, __FactoryDispatcher__
Index: opental/OpenPT/www/ptAdd.pt
diff -u opental/OpenPT/www/ptAdd.pt:1.1 opental/OpenPT/www/ptAdd.pt:1.2
--- opental/OpenPT/www/ptAdd.pt:1.1 Thu Jan 16 17:57:59 2003
+++ opental/OpenPT/www/ptAdd.pt Sun Jan 26 21:04:16 2003
@@ -7,7 +7,7 @@
Page Templates allow you to use simple HTML or XML attributes to
create dynamic templates. You may choose to upload the template text
from a local file by typing the file name or using the <em>browse</em>
-button.
+button, or choose one of the built-in templates.
</p>
<form action="manage_addPageTemplate" method="post"
@@ -25,11 +25,21 @@
</tr>
<tr>
<td align="left" valign="top">
- <div class="form-optional">
- File
+ <div class="form-label">
+ Initial text
</div>
</td>
<td align="left" valign="top">
+ <tal:block repeat="name container/default_text_dir">
+ <input type="radio" name="text_fn" tal:attributes="
+ id string:${radio_${name};
+ value name;
+ checked python: test(repeat['name'].start, 'checked', None)
+ " />
+ <label tal:attributes="for string:${radio_${name}"
tal:content="name">name</label>
+ <br />
+ </tal:block>
+ <br />
<input type="file" name="file" size="25" value="" />
</td>
</tr>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [OpenTAL-checkins] opental/OpenPT ZOPT.py __init__.py www/ptAdd.pt...,
Fernando Lalo Martins <=