Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
CMFDefault.Document.Document Class Reference
Inheritance diagram for CMFDefault.Document.Document:
Inheritance graph
[legend]
Collaboration diagram for CMFDefault.Document.Document:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def manage_editDocument
def edit
def setMetadata
def guessFormat
def handleText
def getMetadataHeaders
def SafetyBelt
def isValidSafetyBelt
def updateSafetyBelt
def SearchableText
 Content accessor methods.
def CookedBody
def EditableBody
def Format
def setFormat
def PUT
 FTP handlers.
def manage_FTPget
def get_size

Public Attributes

 id
 title
 description
 text
 cooked_text
 text_format

Static Public Attributes

 effective_date = expiration_dateNone
string cooked_text = ''
tuple security = ClassSecurityInfo()
tuple manage_edit = DTMLFile('zmi_editDocument', _dtmldir)

Private Member Functions

def _edit
def _safety_belt_update

Private Attributes

 _size
 _stx_level
 _last_safety_belt_editor
 _last_safety_belt
 _safety_belt

Static Private Attributes

tuple __implements__
int _size = 0
int _stx_level = 1
string _last_safety_belt_editor = ''
string _last_safety_belt = ''
string _safety_belt = ''
tuple _htmlsrc

Detailed Description

A Document - Handles both StructuredText and HTML.

Definition at line 59 of file Document.py.


Constructor & Destructor Documentation

def CMFDefault.Document.Document.__init__ (   self,
  id,
  title = '',
  description = '',
  text_format = '',
  text = '' 
)

Definition at line 81 of file Document.py.

00081 
00082     def __init__(self, id, title='', description='', text_format='', text=''):
00083         DefaultDublinCoreImpl.__init__(self)
00084         self.id = id
00085         self.title = title
00086         self.description = description
00087         self.setFormat(text_format)
00088         self._edit(text)


Member Function Documentation

def CMFDefault.Document.Document._edit (   self,
  text 
) [private]
Edit the Document and cook the body.

Definition at line 103 of file Document.py.

00103 
00104     def _edit(self, text):
00105         """ Edit the Document and cook the body.
00106         """
00107         self.text = text
00108         self._size = len(text)
00109 
00110         text_format = self.text_format
00111         if text_format == 'html':
00112             self.cooked_text = text
00113         elif text_format == 'plain':
00114             self.cooked_text = html_quote(text).replace('\n', '<br />')
00115         else:
00116             self.cooked_text = HTML(text, level=self._stx_level, header=0)

Here is the caller graph for this function:

def CMFDefault.Document.Document._safety_belt_update (   self,
  safety_belt = '' 
) [private]
Check validity of safety belt and update tracking if valid.

Return 0 if safety belt is invalid, 1 otherwise.

Note that the policy is deliberately lax if no safety belt value is
present - "you're on your own if you don't use your safety belt".

When present, either the safety belt token:
 - ... is the same as the current one given out, or
 - ... is the same as the last one given out, and the person doing the
   edit is the same as the last editor.

Definition at line 237 of file Document.py.

00237 
00238     def _safety_belt_update(self, safety_belt=''):
00239         """Check validity of safety belt and update tracking if valid.
00240 
00241         Return 0 if safety belt is invalid, 1 otherwise.
00242 
00243         Note that the policy is deliberately lax if no safety belt value is
00244         present - "you're on your own if you don't use your safety belt".
00245 
00246         When present, either the safety belt token:
00247          - ... is the same as the current one given out, or
00248          - ... is the same as the last one given out, and the person doing the
00249            edit is the same as the last editor."""
00250 
00251         if not self.isValidSafetyBelt(safety_belt):
00252             return 0
00253         self.updateSafetyBelt(safety_belt)
00254         return 1

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFDefault.Document.Document.CookedBody (   self,
  stx_level = None,
  setlevel = 0 
)
Get the "cooked" (ready for presentation) form of the text.

The prepared basic rendering of an object.  For Documents, this
means pre-rendered structured text, or what was between the
<BODY> tags of HTML.

If the format is html, and 'stx_level' is not passed in or is the
same as the object's current settings, return the cached cooked
text.  Otherwise, recook.  If we recook and 'setlevel' is true,
then set the recooked text and stx_level on the object.

Definition at line 274 of file Document.py.

00274 
00275     def CookedBody(self, stx_level=None, setlevel=0):
00276         """ Get the "cooked" (ready for presentation) form of the text.
00277 
00278         The prepared basic rendering of an object.  For Documents, this
00279         means pre-rendered structured text, or what was between the
00280         <BODY> tags of HTML.
00281 
00282         If the format is html, and 'stx_level' is not passed in or is the
00283         same as the object's current settings, return the cached cooked
00284         text.  Otherwise, recook.  If we recook and 'setlevel' is true,
00285         then set the recooked text and stx_level on the object.
00286         """
00287         if (self.text_format == 'html' or self.text_format == 'plain'
00288             or (stx_level is None)
00289             or (stx_level == self._stx_level)):
00290             return self.cooked_text
00291         else:
00292             cooked = HTML(self.text, level=stx_level, header=0)
00293             if setlevel:
00294                 self._stx_level = stx_level
00295                 self.cooked_text = cooked
00296             return cooked

def CMFDefault.Document.Document.edit (   self,
  text_format,
  text,
  file = '',
  safety_belt = '' 
)
Update the document.

To add webDav support, we need to check if the content is locked, and if
so return ResourceLockedError if not, call _edit.

Note that this method expects to be called from a web form, and so
disables header processing

Definition at line 122 of file Document.py.

00122 
00123     def edit(self, text_format, text, file='', safety_belt=''):
00124         """ Update the document.
00125 
00126         To add webDav support, we need to check if the content is locked, and if
00127         so return ResourceLockedError if not, call _edit.
00128 
00129         Note that this method expects to be called from a web form, and so
00130         disables header processing
00131         """
00132         self.failIfLocked()
00133         if not self._safety_belt_update(safety_belt=safety_belt):
00134             msg = _(u'Intervening changes from elsewhere detected. '
00135                     u'Please refetch the document and reapply your changes. '
00136                     u'(You may be able to recover your version using the '
00137                     u"browser 'back' button, but will have to apply them to "
00138                     u'a freshly fetched copy.)')
00139             raise EditingConflict(msg)
00140         if file and (type(file) is not type('')):
00141             contents=file.read()
00142             if contents:
00143                 text = contents
00144         if html_headcheck(text) and text_format.lower() != 'plain':
00145             text = bodyfinder(text)
00146         self.setFormat(text_format)
00147         self._edit(text)
00148         self.reindexObject()

Here is the call graph for this function:

Here is the caller graph for this function:

Get the "raw" (as edited) form of the text.

The editable body of text.  This is the raw structured text, or
in the case of HTML, what was between the <BODY> tags.

Definition at line 298 of file Document.py.

00298 
00299     def EditableBody(self):
00300         """ Get the "raw" (as edited) form of the text.
00301 
00302         The editable body of text.  This is the raw structured text, or
00303         in the case of HTML, what was between the <BODY> tags.
00304         """
00305         return self.text

Here is the caller graph for this function:

Dublin Core Format element - resource format.

Definition at line 311 of file Document.py.

00311 
00312     def Format(self):
00313         """ Dublin Core Format element - resource format.
00314         """
00315         if self.text_format == 'html':
00316             return 'text/html'
00317         else:
00318             return 'text/plain'

Here is the caller graph for this function:

Used for FTP and apparently the ZMI now too 

Definition at line 429 of file Document.py.

00429 
00430     def get_size( self ):
00431         """ Used for FTP and apparently the ZMI now too """
00432         return self._size
00433 
00434 InitializeClass(Document)

Here is the caller graph for this function:

Return RFC-822-style header spec.

Definition at line 196 of file Document.py.

00196 
00197     def getMetadataHeaders(self):
00198         """Return RFC-822-style header spec."""
00199         hdrlist = DefaultDublinCoreImpl.getMetadataHeaders(self)
00200         hdrlist.append( ('SafetyBelt', self._safety_belt) )
00201         return hdrlist

Here is the caller graph for this function:

def CMFDefault.Document.Document.guessFormat (   self,
  text 
)
Simple stab at guessing the inner format of the text 

Definition at line 171 of file Document.py.

00171 
00172     def guessFormat(self, text):
00173         """ Simple stab at guessing the inner format of the text """
00174         if html_headcheck(text): return 'html'
00175         else: return 'structured-text'

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFDefault.Document.Document.handleText (   self,
  text,
  format = None,
  stx_level = None 
)
Handles the raw text, returning headers, body, format 

Definition at line 177 of file Document.py.

00177 
00178     def handleText(self, text, format=None, stx_level=None):
00179         """ Handles the raw text, returning headers, body, format """
00180         headers = {}
00181         if not format:
00182             format = self.guessFormat(text)
00183         if format == 'html':
00184             parser = SimpleHTMLParser()
00185             parser.feed(text)
00186             headers.update(parser.metatags)
00187             if parser.title:
00188                 headers['Title'] = parser.title
00189             body = bodyfinder(text)
00190         else:
00191             headers, body = parseHeadersBody(text, headers)
00192             if stx_level:
00193                 self._stx_level = stx_level
00194         return headers, body, format

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFDefault.Document.Document.isValidSafetyBelt (   self,
  safety_belt 
)
Check validity of safety belt.

Definition at line 209 of file Document.py.

00209 
00210     def isValidSafetyBelt(self, safety_belt):
00211         """Check validity of safety belt.
00212         """
00213         if not safety_belt:
00214             # we have no safety belt value
00215             return True
00216         if self._safety_belt is None:
00217             # the current object has no safety belt (ie - freshly made)
00218             return True
00219         if safety_belt == self._safety_belt:
00220             # the safety belt does match the current one
00221             return True
00222         this_user = getSecurityManager().getUser().getId()
00223         if ((safety_belt == self._last_safety_belt)
00224                 and (this_user == self._last_safety_belt_editor)):
00225             # safety belt and user match last safety belt and user
00226             return True
00227         return False

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFDefault.Document.Document.manage_editDocument (   self,
  text,
  text_format,
  file = '',
  REQUEST = None 
)
A ZMI (Zope Management Interface) level editing method 

Definition at line 93 of file Document.py.

00093 
00094     def manage_editDocument( self, text, text_format, file='', REQUEST=None ):
00095         """ A ZMI (Zope Management Interface) level editing method """
00096         Document.edit( self, text_format=text_format, text=text, file=file )
00097         if REQUEST is not None:
00098             REQUEST['RESPONSE'].redirect(
00099                 self.absolute_url()
00100                 + '/manage_edit'
00101                 + '?manage_tabs_message=Document+updated'
00102                 )

Here is the call graph for this function:

Definition at line 394 of file Document.py.

00394 
00395     def manage_FTPget(self):
00396         "Get the document body for FTP download (also used for the WebDAV SRC)"
00397         if self.Format() == 'text/html':
00398             ti = self.getTypeInfo()
00399             method_id = ti and ti.queryMethodID('gethtml', context=self)
00400             if method_id:
00401                 method = getattr(self, method_id)
00402                 if getattr(aq_base(method), 'isDocTemp', 0):
00403                     bodytext = method(self, self.REQUEST)
00404                 else:
00405                     bodytext = method()
00406             else:
00407                 # Use the old code as fallback. May be removed some day.
00408                 hdrlist = self.getMetadataHeaders()
00409                 hdrtext = ''
00410                 for name, content in hdrlist:
00411                     if name.lower() == 'title':
00412                         continue
00413                     else:
00414                         hdrtext = '%s\n <meta name="%s" content="%s" />' % (
00415                             hdrtext, name, content)
00416 
00417                 bodytext = self._htmlsrc % {
00418                     'title': self.Title(),
00419                     'metatags': hdrtext,
00420                     'body': self.EditableBody(),
00421                     }
00422         else:
00423             hdrlist = self.getMetadataHeaders()
00424             hdrtext = formatRFC822Headers( hdrlist )
00425             bodytext = '%s\r\n\r\n%s' % ( hdrtext, self.text )
00426 
00427         return bodytext

Here is the caller graph for this function:

def CMFDefault.Document.Document.PUT (   self,
  REQUEST,
  RESPONSE 
)

FTP handlers.

Handle HTTP (and presumably FTP?) PUT requests 

Definition at line 349 of file Document.py.

00349 
00350     def PUT(self, REQUEST, RESPONSE):
00351         """ Handle HTTP (and presumably FTP?) PUT requests """
00352         self.dav__init(REQUEST, RESPONSE)
00353         self.dav__simpleifhandler(REQUEST, RESPONSE, refresh=1)
00354 
00355         try:
00356             self.failIfLocked()
00357         except ResourceLockedError, msg:
00358             transaction.abort()
00359             RESPONSE.setStatus(423)
00360             return RESPONSE
00361 
00362         body = REQUEST.get('BODY', '')
00363         if REQUEST.get_header('Content-Type', '') == 'text/html':
00364             format = 'html'
00365         else:
00366             format = None
00367         headers, body, format = self.handleText(body, format)
00368 
00369         safety_belt = headers.get('SafetyBelt', '')
00370         if not self._safety_belt_update(safety_belt):
00371             # XXX Can we get an error msg through?  Should we be raising an
00372             #     exception, to be handled in the FTP mechanism?  Inquiring
00373             #     minds...
00374             transaction.abort()
00375             RESPONSE.setStatus(450)
00376             return RESPONSE
00377 
00378         self.setFormat(format)
00379         self.setMetadata(headers)
00380         self._edit(body)
00381         RESPONSE.setStatus(204)
00382         self.reindexObject()
00383         return RESPONSE

Here is the call graph for this function:

Return the current safety belt setting.
For web form hidden button.

Definition at line 203 of file Document.py.

00203 
00204     def SafetyBelt(self):
00205         """Return the current safety belt setting.
00206         For web form hidden button."""
00207         return self._safety_belt

Content accessor methods.

Used by the catalog for basic full text indexing 

Definition at line 262 of file Document.py.

00262 
00263     def SearchableText(self):
00264         """ Used by the catalog for basic full text indexing """
00265         return "%s %s %s" % ( self.Title()
00266                             , self.Description()
00267                             , self.EditableBody()
00268                             )

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFDefault.Document.Document.setFormat (   self,
  format 
)
Set text format and Dublin Core resource format.

Definition at line 324 of file Document.py.

00324 
00325     def setFormat(self, format):
00326         """ Set text format and Dublin Core resource format.
00327         """
00328         value = str(format)
00329         old_value = self.text_format
00330 
00331         if value == 'text/html' or value == 'html':
00332             self.text_format = 'html'
00333         elif value == 'text/plain':
00334             if self.text_format not in ('structured-text', 'plain'):
00335                 self.text_format = 'structured-text'
00336         elif value == 'plain':
00337             self.text_format = 'plain'
00338         else:
00339             self.text_format = 'structured-text'
00340 
00341         # Did the format change? We might need to re-cook the content.
00342         if value != old_value:
00343             if html_headcheck(self.text) and value != 'plain':
00344                 self.text = bodyfinder(self.text)
00345 
00346             self._edit(self.text)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFDefault.Document.Document.setMetadata (   self,
  headers 
)

Definition at line 150 of file Document.py.

00150 
00151     def setMetadata(self, headers):
00152         headers['Format'] = self.Format()
00153         new_subject = keywordsplitter(headers)
00154         headers['Subject'] = new_subject or self.Subject()
00155         new_contrib = contributorsplitter(headers)
00156         headers['Contributors'] = new_contrib or self.Contributors()
00157         for key, value in self.getMetadataHeaders():
00158             if not key in headers:
00159                 headers[key] = value
00160         self._editMetadata(title=headers['Title'],
00161                           subject=headers['Subject'],
00162                           description=headers['Description'],
00163                           contributors=headers['Contributors'],
00164                           effective_date=headers['Effective_date'],
00165                           expiration_date=headers['Expiration_date'],
00166                           format=headers['Format'],
00167                           language=headers['Language'],
00168                           rights=headers['Rights'],
00169                           )

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFDefault.Document.Document.updateSafetyBelt (   self,
  safety_belt 
)
Update safety belt tracking.

Definition at line 229 of file Document.py.

00229 
00230     def updateSafetyBelt(self, safety_belt):
00231         """Update safety belt tracking.
00232         """
00233         this_user = getSecurityManager().getUser().getId()
00234         self._last_safety_belt_editor = this_user
00235         self._last_safety_belt = safety_belt
00236         self._safety_belt = str(self._p_mtime)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Initial value:
(z2IMutableDocument, z2IDocument,
                      PortalContent.__implements__,
                      DefaultDublinCoreImpl.__implements__)

Definition at line 65 of file Document.py.

tuple CMFDefault.Document.Document._htmlsrc [static, private]
Initial value:
(
        '<html>\n <head>\n'
        ' <title>%(title)s</title>\n'
       '%(metatags)s\n'
        ' </head>\n'
        ' <body>%(body)s</body>\n'
        '</html>\n'
        )

Definition at line 384 of file Document.py.

string CMFDefault.Document.Document._last_safety_belt = '' [static, private]

Definition at line 76 of file Document.py.

Definition at line 234 of file Document.py.

Definition at line 75 of file Document.py.

Definition at line 233 of file Document.py.

string CMFDefault.Document.Document._safety_belt = '' [static, private]

Definition at line 77 of file Document.py.

Definition at line 235 of file Document.py.

int CMFDefault.Document.Document._size = 0 [static, private]

Definition at line 71 of file Document.py.

Definition at line 107 of file Document.py.

int CMFDefault.Document.Document._stx_level = 1 [static, private]

Definition at line 73 of file Document.py.

Definition at line 192 of file Document.py.

Definition at line 70 of file Document.py.

Definition at line 111 of file Document.py.

Definition at line 85 of file Document.py.

CMFDefault.Document.Document.effective_date = expiration_dateNone [static]

Definition at line 69 of file Document.py.

Definition at line 83 of file Document.py.

tuple CMFDefault.Document.Document.manage_edit = DTMLFile('zmi_editDocument', _dtmldir) [static]

Definition at line 90 of file Document.py.

tuple CMFDefault.Document.Document.security = ClassSecurityInfo() [static]

Definition at line 79 of file Document.py.

Definition at line 106 of file Document.py.

Definition at line 286 of file Document.py.

Definition at line 84 of file Document.py.


The documentation for this class was generated from the following file: