Example #1
0
    def uploadImage(self, file, REQUEST=None):
        """
        Upload image to the collection and then return to the referring URL.
        """

        sha1_hash = sha_hexdigest(file)
        for image in self.storage.objectValues('Image'):
            if not hasattr(image, 'sha1_hash'):
                image.sha1_hash = sha_hexdigest(image)
            if sha1_hash == image.sha1_hash:
                return image

        id, title = cookId(None, None, file)
        # first, determine if this is a utf-8 text and not ascii
        try:
            id.decode('ascii')
        except UnicodeError:
            id = id.decode('utf-8')

        orig_id = id
        id = make_id(self.storage, title=title)
        id = manage_addImage(self.storage, id, file, title)
        if REQUEST:
            return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        ob = self.storage._getOb(id)
        return ob
    def uploadImage(self, file, REQUEST=None):
        """
        Upload image to the collection and then return to the referring URL.
        """

        sha1_hash = sha_hexdigest(file)
        for image in self.storage.objectValues('Image'):
            if not hasattr(image, 'sha1_hash'):
                image.sha1_hash = sha_hexdigest(image)
            if sha1_hash == image.sha1_hash:
                return image

        id, title = cookId(None, None, file)
        # first, determine if this is a utf-8 text and not ascii
        try:
            id.decode('ascii')
        except UnicodeError:
            id = id.decode('utf-8')

        orig_id = id
        id = make_id(self.storage, title=title)
        id = manage_addImage(self.storage, id, file, title)
        if REQUEST:
            return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        ob = self.storage._getOb(id)
        return ob
Example #3
0
    def _update(self, portal):
        images = portal.images.objectValues('Image')
        dup_images = {}
        for image in images:
            if not hasattr(image, 'sha1_hash'):
                image.sha1_hash = sha_hexdigest(image)
                self.log.debug('Image hash added, %s: %s' % (
                    image.getId(), image.sha1_hash))
            if image.getId() != image.title:
                orig_image = getattr(portal.images, image.title, None)
                if orig_image:
                    if not hasattr(orig_image, 'sha1_hash'):
                        orig_image.sha1_hash = sha_hexdigest(orig_image)
                    if image.sha1_hash == orig_image.sha1_hash:
                        dup_images[image.getId()] = orig_image.getId()

        schema_tool = portal.getSchemaTool()
        obj_textarea_props = {}
        for meta_type, schema_ob in schema_tool.listSchemas().items():
            textarea_widgets = schema_ob.objectValues('Naaya Schema Text Area Widget')
            textarea_props = [widget.id.rsplit('-property', 1)[0]
                    for widget in textarea_widgets]
            obj_textarea_props[meta_type] = textarea_props
        for ob in portal.getCatalogedObjectsA(
                meta_type=obj_textarea_props.keys()):
            for dup_id in dup_images.keys():
                for prop_id in obj_textarea_props[ob.meta_type]:
                    for lang in portal.gl_get_languages():
                        curr_prop = ob.getLocalAttribute(
                                prop_id, lang)
                        if dup_id in curr_prop:
                            ob.set_localpropvalue(prop_id, lang,
                                    curr_prop.replace(
                                        dup_id, dup_images[dup_id]))
                            self.log.debug('Object %s, image id changed from %s to %s'
                                    % (ob.absolute_url(), dup_id, dup_images[dup_id]))
        portal.images.manage_delObjects(dup_images.keys())
        for image_id in dup_images.keys():
            self.log.debug('Deleted duplicated image: %s' % image_id)
        return True
    def uploadImage(self, file, REQUEST=None):
        """
        Upload image to the collection and then return to the referring URL.
        """

        sha1_hash = sha_hexdigest(file)
        for image in self.storage.objectValues('Image'):
            if not hasattr(image, 'sha1_hash'):
                image.sha1_hash = sha_hexdigest(image)
            if sha1_hash == image.sha1_hash:
                return image
        id, title = cookId(None, None, file)
        orig_id = id
        i = 0
        while self.storage._getOb(id, None):
            i += 1
            id = '%s-%u' % (orig_id, i)
        id = manage_addImage(self.storage, id, file, title)
        if REQUEST:
            return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        ob = self.storage._getOb(id)
        return ob
Example #5
0
    def uploadImage(self, file, REQUEST=None):
        """
        Upload image to the collection and then return to the referring URL.
        """

        sha1_hash = sha_hexdigest(file)
        for image in self.storage.objectValues('Image'):
            if not hasattr(image, 'sha1_hash'):
                image.sha1_hash = sha_hexdigest(image)
            if sha1_hash == image.sha1_hash:
                return image
        id, title = cookId(None, None, file)
        orig_id = id
        i = 0
        while self.storage._getOb(id, None):
            i += 1
            id = '%s-%u' % (orig_id, i)
        id = manage_addImage(self.storage, id, file, title)
        if REQUEST:
            return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        ob = self.storage._getOb(id)
        return ob