Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions
ATContentTypes.content.base.ATCTFileContent Class Reference
Inheritance diagram for ATContentTypes.content.base.ATCTFileContent:
Inheritance graph
[legend]
Collaboration diagram for ATContentTypes.content.base.ATCTFileContent:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def download
def index_html
def get_data
def size
def get_content_type
def update_data
def manage_edit
def post_validate
def manage_afterPUT
def initializeArchetype
def copyLayoutFromParent
def edit
def cmf_edit
def exclude_from_nav
def get_size

Static Public Attributes

string precondition = ''
tuple manage_options
tuple security = ClassSecurityInfo()
tuple data = ComputedAttribute(get_data, 1)
tuple content_type = ComputedAttribute(get_content_type, 1)
 schema = ATContentTypeSchema
string archetype_name = 'AT Content Type'
tuple assocMimetypes = ()
tuple assocFileExt = ()
tuple cmf_edit_kws = ()
 isDocTemp = False

Private Member Functions

def _cleanupFilename
def _setATCTFileContent

Detailed Description

Base class for content types containing a file like ATFile or ATImage

The file field *must* be the exclusive primary field

Definition at line 238 of file base.py.


Member Function Documentation

def ATContentTypes.content.base.ATCTFileContent._cleanupFilename (   self,
  filename,
  request = None 
) [private]
Cleans the filename from unwanted or evil chars

Definition at line 329 of file base.py.

00329 
00330     def _cleanupFilename(self, filename, request=None):
00331         """Cleans the filename from unwanted or evil chars
00332         """
00333         if filename and not isinstance(filename, unicode):
00334             encoding = self.getCharset()
00335             filename = unicode(filename, encoding)
00336 
00337         filename = cleanupFilename(filename, request=request)
00338         return filename and filename.encode(encoding) or None

Here is the call graph for this function:

Here is the caller graph for this function:

def ATContentTypes.content.base.ATCTFileContent._setATCTFileContent (   self,
  value,
  kwargs 
) [private]
Set id to uploaded id

Definition at line 339 of file base.py.

00339 
00340     def _setATCTFileContent(self, value, **kwargs):
00341         """Set id to uploaded id
00342         """
00343         field = self.getPrimaryField()
00344         # set first then get the filename
00345         field.set(self, value, **kwargs) # set is ok
00346         if self._isIDAutoGenerated(self.getId()):
00347             filename = field.getFilename(self, fromBaseUnit=False)
00348             request = self.REQUEST
00349             clean_filename = self._cleanupFilename(filename, request=request)
00350             request_id = request.form.get('id')
00351             if request_id and not self._isIDAutoGenerated(request_id):
00352                 # request contains an id
00353                 # skip renaming when then request id is not autogenerated which
00354                 # means the user has defined an id. It's autogenerated when the
00355                 # the user has disabled "short name editing".
00356                 return
00357             elif clean_filename == self.getId():
00358                 # destination id and old id are equal
00359                 return
00360             elif clean_filename:
00361                 # got a clean file name - rename it
00362                 # apply subtransaction. w/o a subtransaction renaming
00363                 # fails when the type is created using portal_factory
00364                 transaction.savepoint(optimistic=True)
00365                 self.setId(clean_filename)

Here is the caller graph for this function:

def ATContentTypes.content.base.ATCTMixin.cmf_edit (   self,
  args,
  kwargs 
) [inherited]
Overwrite this method to make AT compatible with the crappy
CMF edit()

Definition at line 182 of file base.py.

00182 
00183     def cmf_edit(self, *args, **kwargs):
00184         """Overwrite this method to make AT compatible with the crappy
00185         CMF edit()
00186         """
00187         raise NotImplementedError("cmf_edit method isn't implemented")

Here is the caller graph for this function:

Copies the layout from the parent object if it's of the same type.

Definition at line 149 of file base.py.

00149 
00150     def copyLayoutFromParent(self):
00151         """Copies the layout from the parent object if it's of the same type."""
00152         parent = aq_parent(aq_inner(self))
00153         if parent is not None:
00154             # Only set the layout if we are the same type as out parent object
00155             if parent.meta_type == self.meta_type:
00156                 # If the parent is the same type as us it should implement
00157                 # BrowserDefaultMixin
00158                 parent_layout = parent.getLayout()
00159                 # Just in case we should make sure that the layout is
00160                 # available to the new object
00161                 if parent_layout in [l[0] for l in self.getAvailableLayouts()]:
00162                     self.setLayout(parent_layout)

Here is the call graph for this function:

def ATContentTypes.content.base.ATCTFileContent.download (   self,
  REQUEST = None,
  RESPONSE = None 
)
Download the file (use default index_html)

Definition at line 257 of file base.py.

00257 
00258     def download(self, REQUEST=None, RESPONSE=None):
00259         """Download the file (use default index_html)
00260         """
00261         if REQUEST is None:
00262             REQUEST = self.REQUEST
00263         if RESPONSE is None:
00264             RESPONSE = REQUEST.RESPONSE
00265         field = self.getPrimaryField()
00266         return field.download(self, REQUEST, RESPONSE)

Here is the call graph for this function:

def ATContentTypes.content.base.ATCTMixin.edit (   self,
  args,
  kwargs 
) [inherited]
Reimplementing edit() to have a compatibility method for the old
cmf edit() method

Definition at line 164 of file base.py.

00164 
00165     def edit(self, *args, **kwargs):
00166         """Reimplementing edit() to have a compatibility method for the old
00167         cmf edit() method
00168         """
00169         if len(args) != 0:
00170             # use cmf edit method
00171             return self.cmf_edit(*args, **kwargs)
00172 
00173         # if kwargs is containing a key that is also in the list of cmf edit
00174         # keywords then we have to use the cmf_edit comp. method
00175         cmf_edit_kws = getattr(aq_inner(self).aq_explicit, 'cmf_edit_kws', ())
00176         for kwname in kwargs.keys():
00177             if kwname in cmf_edit_kws:
00178                 return self.cmf_edit(**kwargs)
00179         # standard AT edit - redirect to update()
00180         return self.update(**kwargs)

Here is the caller graph for this function:

Accessor for excludeFromNav field

Definition at line 188 of file base.py.

00188 
00189     def exclude_from_nav(self):
00190         """Accessor for excludeFromNav field
00191         """
00192         field = self.getField('excludeFromNav')
00193         if field is not None:
00194             return field.get(self)
00195         else:
00196             return False

Here is the call graph for this function:

CMF compatibility method

Definition at line 297 of file base.py.

00297 
00298     def get_content_type(self):
00299         """CMF compatibility method
00300         """
00301         f = self.getPrimaryField().getAccessor(self)()
00302         return f and f.getContentType() or 'text/plain' #'application/octet-stream'

Here is the call graph for this function:

CMF compatibility method

Definition at line 282 of file base.py.

00282 
00283     def get_data(self):
00284         """CMF compatibility method
00285         """
00286         data = aq_base(self.getPrimaryField().getAccessor(self)())
00287         return str(getattr(data, 'data', data))

Here is the call graph for this function:

Here is the caller graph for this function:

ZMI / Plone get size method

Reimplemented in ATContentTypes.content.base.ATCTFolderMixin, and ATContentTypes.content.base.ATCTFolder.

Definition at line 198 of file base.py.

00198 
00199     def get_size(self):
00200         """ZMI / Plone get size method
00201         """
00202         f = self.getPrimaryField()
00203         if f is None:
00204             return 0
00205         return f.get_size(self) or 0
00206 
00207 InitializeClass(ATCTMixin)

Here is the call graph for this function:

Here is the caller graph for this function:

def ATContentTypes.content.base.ATCTFileContent.index_html (   self,
  REQUEST = None,
  RESPONSE = None 
)
Make it directly viewable when entering the objects URL

Definition at line 268 of file base.py.

00268 
00269     def index_html(self, REQUEST=None, RESPONSE=None):
00270         """Make it directly viewable when entering the objects URL
00271         """
00272         if REQUEST is None:
00273             REQUEST = self.REQUEST
00274         if RESPONSE is None:
00275             RESPONSE = REQUEST.RESPONSE
00276         field = self.getPrimaryField()
00277         data  = field.getAccessor(self)(REQUEST=REQUEST, RESPONSE=RESPONSE)
00278         if data:
00279             return data.index_html(REQUEST, RESPONSE)
00280         # XXX what should be returned if no data is present?

Here is the call graph for this function:

Here is the caller graph for this function:

def ATContentTypes.content.base.ATCTMixin.initializeArchetype (   self,
  kwargs 
) [inherited]
called by the generated add* factory in types tool

Overwritten to call edit() instead of update() to have the cmf
compatibility method.

Definition at line 125 of file base.py.

00125 
00126     def initializeArchetype(self, **kwargs):
00127         """called by the generated add* factory in types tool
00128 
00129         Overwritten to call edit() instead of update() to have the cmf
00130         compatibility method.
00131         """
00132         try:
00133             self.initializeLayers()
00134             self.markCreationFlag()
00135             self.setDefaults()
00136             if kwargs:
00137                 self.edit(**kwargs)
00138             self._signature = self.Schema().signature()
00139             if self.isPrincipiaFolderish:
00140                 self.copyLayoutFromParent()
00141         except ConflictError:
00142             raise
00143         except Exception, msg:
00144             LOG.warn('Exception in initializeArchetype', exc_info=True)
00145             if DEBUG and str(msg) not in ('SESSION',):
00146                 # debug code
00147                 raise

Here is the call graph for this function:

def ATContentTypes.content.base.ATCTFileContent.manage_afterPUT (   self,
  data,
  marshall_data,
  file,
  context,
  mimetype,
  filename,
  REQUEST,
  RESPONSE 
)
After webdav/ftp PUT method

Set the title according to the uploaded filename if the title
is empty or set it to the id if no filename is given.

Reimplemented from ATContentTypes.content.base.ATCTContent.

Definition at line 404 of file base.py.

00404 
00405                         filename, REQUEST, RESPONSE):
00406         """After webdav/ftp PUT method
00407 
00408         Set the title according to the uploaded filename if the title
00409         is empty or set it to the id if no filename is given.
00410         """
00411         id = self.getId()
00412         title = self.Title()
00413         if not title:
00414             if filename:
00415                 self.setTitle(filename)
00416             else:
00417                 # Use the last-segment from the url as the id, as the
00418                 # object might have been renamed somehow (eg: by id
00419                 # mangling).
00420                 request = REQUEST or getattr(self, 'REQUEST', None)
00421                 if request is not None:
00422                     path_info = request.get('PATH_INFO')
00423                     if path_info:
00424                         id = posixpath.basename(path_info)
00425                 self.setTitle(id)
00426 
00427 InitializeClass(ATCTFileContent)
00428 

Here is the caller graph for this function:

def ATContentTypes.content.base.ATCTFileContent.manage_edit (   self,
  title,
  content_type,
  precondition = '',
  filedata = None,
  REQUEST = None 
)
Changes the title and content type attributes of the File or Image.

Definition at line 315 of file base.py.

00315 
00316                     filedata=None, REQUEST=None):
00317         """
00318         Changes the title and content type attributes of the File or Image.
00319         """
00320         if self.wl_isLocked():
00321             raise ResourceLockedError, "File is locked via WebDAV"
00322 
00323         self.setTitle(title)
00324         if filedata is not None:
00325             self.update_data(filedata, content_type, len(filedata))
00326         if REQUEST:
00327             message="Saved changes."
00328             return self.manage_main(self,REQUEST,manage_tabs_message=message)

Here is the call graph for this function:

Here is the caller graph for this function:

def ATContentTypes.content.base.ATCTFileContent.post_validate (   self,
  REQUEST = None,
  errors = None 
)
Validates upload file and id

Definition at line 367 of file base.py.

00367 
00368     def post_validate(self, REQUEST=None, errors=None):
00369         """Validates upload file and id
00370         """
00371         id     = REQUEST.form.get('id')
00372         field  = self.getPrimaryField()
00373         f_name = field.getName()
00374         upload = REQUEST.form.get('%s_file' % f_name, None)
00375         filename = getattr(upload, 'filename', None)
00376         if isinstance(filename, basestring):
00377             filename = os.path.basename(filename)
00378             filename = filename.split("\\")[-1]
00379         clean_filename = self._cleanupFilename(filename, request=REQUEST)
00380         used_id = (id and not self._isIDAutoGenerated(id)) and id or clean_filename
00381 
00382         if upload:
00383             # the file may have already been read by a
00384             # former method
00385             upload.seek(0)
00386 
00387         if not used_id:
00388             return
00389 
00390         if getattr(self, 'check_id', None) is not None:
00391             check_id = self.check_id(used_id,required=1)
00392         else:
00393             # If check_id is not available just look for conflicting ids
00394             parent = aq_parent(aq_inner(self))
00395             check_id = used_id in parent.objectIds() and \
00396                        'Id %s conflicts with an existing item'% used_id or False
00397         if check_id and used_id == id:
00398             errors['id'] = check_id
00399             REQUEST.form['id'] = used_id
00400         elif check_id:
00401             errors[f_name] = check_id

Here is the call graph for this function:

Get size (image_view.pt)

Definition at line 291 of file base.py.

00291 
00292     def size(self):
00293         """Get size (image_view.pt)
00294         """
00295         return self.get_size()

Here is the call graph for this function:

def ATContentTypes.content.base.ATCTFileContent.update_data (   self,
  data,
  content_type = None,
  size = 'ignored' 
)

Definition at line 306 of file base.py.

00306 
00307     def update_data(self, data, content_type=None, size='ignored'):
00308         kwargs = {}
00309         if content_type is not None:
00310             kwargs['mimetype'] = content_type
00311         mutator = self.getPrimaryField().getMutator(self)
00312         mutator(data, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

string ATContentTypes.content.base.ATCTMixin.archetype_name = 'AT Content Type' [static, inherited]

Definition at line 109 of file base.py.

Definition at line 112 of file base.py.

Definition at line 111 of file base.py.

Definition at line 113 of file base.py.

Definition at line 303 of file base.py.

tuple ATContentTypes.content.base.ATCTFileContent.data = ComputedAttribute(get_data, 1) [static]

Definition at line 288 of file base.py.

Definition at line 116 of file base.py.

Initial value:
(
        ATCTContent.manage_options[0:1] +
        ATCTContent.manage_options[2:]
        )

Definition at line 249 of file base.py.

Definition at line 247 of file base.py.

ATContentTypes.content.base.ATCTMixin.schema = ATContentTypeSchema [static, inherited]

Definition at line 107 of file base.py.

tuple ATContentTypes.content.base.ATCTFileContent.security = ClassSecurityInfo() [static]

Reimplemented from ATContentTypes.content.base.ATCTContent.

Definition at line 254 of file base.py.


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