[Zope-dev] ZClass.manage_subclassableClassNames
Joerg Wittenberger
Joerg Wittenberger <Joerg.Wittenberger@pobox.com>
Wed, 27 Oct 1999 19:05:05 +0200 (CEST)
Hi folks,
I'm trying to get my first Zope product working. It shall:
* manage dublin core meta data with each object (works)
* deliver rdf/dc meta data info (works)
* have both content (like a file but editable like DTMLDocument)
and children nodes like a folder (works)
* mirror the document hirarchy and meta data in the file system (half
working)
* don't evaluate DTML (for various reasons) (easy)
* replicate hirarchy based on a subscription mechanism (not yet
started)
and be subclassable as ZClass and searchable.
The latter two are the problem. I can't find how the
ZClass.manage_subclassableClassNames() method collects which classes
are subclassable.
Furthermore the PrincipiaSearchSource() method is never called for
some reason.
I append the 0.0.0.0.0.0.0.1 ;-) version of my code, any help
appreciated.
/Jerry
--
You can have it done fast,
you can have it done cheap,
and you can have it done well.
--- But you can only have two of those at once.
----------------------------------------------------------------------------
""" We add documentation here the other day. """
from OFS.Folder import Folder
import Globals
import ExtensionClass
import DocumentTemplate
from Globals import HTML, HTMLFile, MessageDialog
from DateTime import DateTime
import os, string
from zLOG import LOG
def manage_addDCDocument(self, id, file='', REQUEST=None):
""" Create a DCDocument """
if type(file) is not type(''): file=file.read()
self._setObject(id, DCDocument(id, data=file, REQUEST=REQUEST))
return self.manage_main(self, REQUEST, update_menu=1)
manage_main=HTMLFile('documentEdit', globals())
manage_addDCDocumentForm=HTMLFile('addDCDocumentForm', globals())
# This should be somewhere else!
def _dropPathSep(path):
if path[-1] == os.sep: return path[:-1]
return path
the_publisher = 'XYZ Deutschland GmbH'
the_rights = 'all rights reserved'
class DCDocument(Folder):
""" jojo """
meta_type = 'DCDocument'
description = ''
_properties=({'id':'title', 'type':'string', 'mode':'w'},
{'id':'creator', 'type':'string', 'mode':'w'},
# The subject should better be 'tokens' type
{'id':'subject', 'type':'string', 'mode':'w'},
{'id':'description', 'type':'text', 'mode':'w'},
{'id':'publisher', 'type':'string', 'mode':'w'},
#{'id':'contributor', 'type':'string', 'mode':'w'},
#{'id':'date', 'type':'date', 'mode':''},
#{'id':'type', 'type':'string', 'mode':'w'},
#{'id':'format', 'type':'string', 'mode':'w'},
{'id':'identifier', 'type':'string', 'mode':'w'},
#{'id':'source', 'type':'string', 'mode':'w'},
#{'id':'language', 'type':'string', 'mode':'w'},
#{'id':'relation', 'type':'string', 'mode':'w'},
#{'id':'coverage', 'type':'string', 'mode':'w'},
{'id':'rights', 'type':'string', 'mode':'w'},
)
_dc_properties = _properties
def __init__(self, id, data=None, REQUEST=None):
self.id=id
if REQUEST: self.data=REQUEST['data']
else: self.data=data
if type(self.data) is not type(''): self.data=self.data.read()
self._setPropValue('creator', `REQUEST.AUTHENTICATED_USER`)
self._setPropValue('date', DateTime().Date())
self._setPropValue('publisher', the_publisher)
self._setPropValue('rights', the_rights)
self._setPropValue('identifier', '')
self.manage_changeProperties(REQUEST)
path=REQUEST['PATH_INFO']
path, drop = os.path.split(_dropPathSep(path))
self._saveData(path=path, fn=id)
self._saveProperties(path=path, fn=id)
return ''
def _SavePath(self, path=None, fn=None, REQUEST=None,
ext='.sgml', base='/tmp'):
if REQUEST:
path = REQUEST['PATH_INFO']
path, drop = os.path.split(_dropPathSep(path))
path, fn = os.path.split(path)
dirname = base + path
if not os.path.exists(dirname): os.makedirs(dirname)
return os.path.join(dirname, fn) + ext
def _saveData(self, path=None, fn=None, REQUEST=None, ext='.sgml'):
if REQUEST: path = self._SavePath(REQUEST=REQUEST, ext=ext)
else: path = self._SavePath(path=path, fn=fn, ext=ext)
try:
f=open(path, 'wb')
except: raise
f.write(self.data)
f.close()
def _saveProperties(self, path=None, fn=None, REQUEST=None, ext='.rdf'):
if REQUEST: path = self._SavePath(REQUEST=REQUEST, ext=ext)
else: path = self._SavePath(path=path, fn=fn, ext=ext)
try:
f=open(path, 'w')
except: raise
f.write(self.RDF())
f.close()
def get_size(self):
return len(self.data)
def PrincipiaSearchSource(self):
"Support for searching - the document's contents are searched."
LOG('Hier', 0, self.data)
return self.data
_rdf_header= """<?xml version="1.0" ?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.0/"
>
"""
def RDF(self, REQUEST=None):
' retunrs the properties as xml '
md=self._rdf_header
md = md + ' <rdf:Description about="' + self.id + '">\n'
for p in self._dc_properties:
n = p['id']
try:
v = getattr(self, n)
except AttributeError:
v = None
if v and v != '':
md=(md + ' <dc:' + n + '>'
+ DocumentTemplate.DT_Util.html_quote(v)
+ '</dc:' + n + '>\n')
md = (md +' <dc:date>' + self.bobobase_modification_time().Date()
+ '</dc:date>\n')
if REQUEST is not None:
REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml')
return md+' </rdf:Description>\n</rdf:RDF>\n'
_size_changes={
'Bigger': (5,5),
'Smaller': (-5,-5),
'Narrower': (0,-5),
'Wider': (0,5),
'Taller': (5,0),
'Shorter': (-5,0),
}
def _er(self,SUBMIT,dtpref_cols,dtpref_rows,REQUEST):
dr,dc = self._size_changes[SUBMIT]
rows=max(1,string.atoi(dtpref_rows)+dr)
cols=max(40,string.atoi(dtpref_cols)+dc)
e=(DateTime('GMT') + 365).rfc822()
resp=REQUEST['RESPONSE']
resp.setCookie('dtpref_rows',str(rows),path='/',expires=e)
resp.setCookie('dtpref_cols',str(cols),path='/',expires=e)
def manage_edit(self, data, SUBMIT='Change',dtpref_cols='50',
dtpref_rows='20', REQUEST=None):
""" tbc """
if self._size_changes.has_key(SUBMIT):
self._er(SUBMIT,dtpref_cols,dtpref_rows,REQUEST)
if type(data) is not type(''): data=data.read()
self.data=data
self._saveData(REQUEST=REQUEST)
if REQUEST:
REQUEST.RESPONSE.redirect(REQUEST['URL1'] + '/manage_editForm')
def manage_editProperties(self, REQUEST):
""" eit the PRoperties and write the copy into the meta file """
Folder.manage_editProperties(self, REQUEST)
self._saveProperties(REQUEST=REQUEST)
def index_html(self, REQUEST=None):
""" render the document, i.e., give away the plain text """
# if REQUEST: REQUEST.RESPONSE.setHeader('Content-Type', 'text/plain')
return self.data
manage_editForm=HTMLFile('documentEdit', globals())
manage_options=(
{'label':'Contents', 'action':'manage_editForm'},
{'label':'Children', 'action':'manage_main'},
{'label':'View', 'action':'index_html'},
{'label':'Properties', 'action':'manage_propertiesForm'},
{'label':'Import/Export', 'action':'manage_importExportForm'},
#{'label':'Security', 'action':'manage_access'},
{'label':'Undo', 'action':'manage_UndoForm'},
#{'label':'Find', 'action':'manage_findFrame', 'target':'manage_main'},
)
__ac_permissions__=(
('View management screens',
('manage_editForm', 'manage', 'manage_main', 'manage_uploadForm',
'PrincipiaSearchSource')),
('Change DCDocuments', ('manage_edit', 'manage_upload', 'PUT')),
('View', ('__call__', '')),
)
Globals.default__class_init__(DCDocument)