Esempio n. 1
0
def addImage(self,
             id,
             title='',
             file='',
             content_type='',
             precondition='',
             subject=(),
             description='',
             contributors=(),
             effective_date=None,
             expiration_date=None,
             format='image/png',
             language='',
             rights=''):
    """
        Add an Image
    """

    # cookId sets the id and title if they are not explicity specified
    id, title = OFS.Image.cookId(id, title, file)

    self = self.this()

    # Instantiate the object and set its description.
    iobj = Image(id, title, '', content_type, precondition, subject,
                 description, contributors, effective_date, expiration_date,
                 format, language, rights)

    # Add the Image instance to self
    self._setObject(id, iobj)

    # 'Upload' the image.  This is done now rather than in the
    # constructor because it's faster (see File.py.)
    self._getOb(id).manage_upload(file)
Esempio n. 2
0
 def _set_audio_image(self, v):
     if v == interfaces.IAudio['audio_image'].missing_value:
         return
     upload = v
     if isinstance(upload, ofsimage.Image):
         image = upload
     else:
         image = ofsimage.Image(id=upload.filename,
                                title=upload.filename,
                                file=upload)
     self.audio_data['audio_image'] = image
Esempio n. 3
0
def build_ofsimage(url):
    datafile = tempfile.TemporaryFile('w+b')
    fin = urllib2.urlopen(url)
    data = fin.read(64)
    while data:
        datafile.write(data)
        data = fin.read(64)
    fin.close()
    datafile.flush()
    datafile.seek(0)

    ofsimage = Image.Image(id='thumbnail', title='thumbnail', file=datafile)
    datafile.close()

    return ofsimage
Esempio n. 4
0
    def cook(self):
        """makes the id valid

            strips all not allowed characters from id, or if id is None uses
            file.filename for guessing a id

            returns self
        """
        from OFS import Image
        id, unused_title = Image.cookId(self._maybe_id, "", self._file)
        if isinstance(id, str):
            try:
                id = str(id, 'utf-8')
            except UnicodeError:
                pass
        if isinstance(id, str):
            id = id.encode('latin1', 'replace')
        id = string.translate(id, characters.char_transmap)
        self._maybe_id = id
        self._validation_result = None
        return self
Esempio n. 5
0
    def cook(self):
        """makes the id valid

            strips all not allowed characters from id, or if id is None uses
            file.filename for guessing a id

            returns self
        """
        from OFS import Image
        id, unused_title = Image.cookId(self._maybe_id, "", self._file)
        if isinstance(id, str):
            try:
                id = unicode(id, 'utf-8')
            except UnicodeError:
                pass
        if isinstance(id, unicode):
            id = id.encode('latin1', 'replace')
        id = string.translate(id, characters.char_transmap)
        self._maybe_id = id
        self._validation_result = None
        return self
Esempio n. 6
0
def fileobject_add_helper(context, id, text):
    if hasattr(context.aq_base, id):
        getattr(context, id).update_data(text)
    else:
        Image.manage_addFile(context, id, text, content_type='text/plain')
Esempio n. 7
0
 def __init__(self, id):
     super(ZODBFile, self).__init__(id)
     # Actual container of file data
     self._file = Image.File(id, id, '')
Esempio n. 8
0
def fileobject_add_helper(context, id, text):
    if hasattr(context.aq_base, id):
        getattr(context, id).update_data(text)
    else:
        Image.manage_addFile(context, id, text, content_type='text/plain')