Beispiel #1
0
    def manage_upload(self, file='', REQUEST=None, idprefix=None):
        """
        Replaces the current contents of the File or Image object with file.

        The file or images contents are replaced with the contents of 'file'.

        Override of OFS.Image version (through parent) to add automatic
        ids, with prefixes.

        A reasonable method to use to set the body of the CNXMLFile, but 'setSource' recommended
        if you don't need to be strictly File-ish.
        """
        # manage_upload can take file-ish as well as str
        read = getattr(file, 'read', None)
        if read:
            cursor = file.tell()   # so we can put the seek back where we found it
            file.seek(0)
            src = file.read()
            file.seek(cursor)
        else:
            src = file

        src = autoIds(src, prefix=idprefix)
        if type(src) is unicode:   # OFS.Image.File._read_data isn't happy with possible unicode
            src = src.encode('utf-8')
        return CNXMLFile.manage_upload(self, file=src, REQUEST=REQUEST)
Beispiel #2
0
    def manage_edit(self, title, content_type, precondition='',
                    filedata=None, REQUEST=None, idprefix=None):
        """
        Changes the title and content type attributes of the File or Image.

        Override of OFS.Image version (through parent) to add automatic
        ids, with prefixes.

        A reasonable method to use to set the body of the CNXMLFile, but 'setSource' recommended
        if you don't need to be strictly File-ish.
        """
        filedata = autoIds(filedata, prefix=idprefix)
        return CNXMLFile.manage_edit(self, title, content_type, precondition=precondition,
                                     filedata=filedata, REQUEST=REQUEST)