Exemple #1
0
def process_image(self, image_contents_id):
    session = Client().session()
    contents = session.query(ImageContents).\
        filter(ImageContents.image_contents_id == image_contents_id).\
        one()

    image = session.query(Image).\
        filter(Image.image_id == contents.image_id).\
        one()

    truck = ImageTruck(
        contents.contents, contents.content_type, image.source_url)
    truck.filename = image.filename
    metadata = ImageMetadata.image_metadata(truck.contents)
    truck.contents = ReorientImage.reorient_image(truck.contents)
    def after_upload(size):
        redis.publish(REDIS_CHANNEL, json.dumps({
            'task_id': self.request.id,
            'suffix': size,
        }))
    ResizeImage.make_resizes(image, truck, after_upload)

    print "uploading original image"
    truck.upload()
    redis.publish(REDIS_CHANNEL, json.dumps({
        'task_id': self.request.id,
        'suffix': '',
    }))

    delay(queued_tasks, Invalidate(), image.image_id)

    for attr, value in metadata.iteritems():
        setattr(image, attr, value)
    session.add(image)
    session.delete(contents)
Exemple #2
0
 def remove_tag(self, tag_name):
     from catsnap.table.image_tag import ImageTag
     from catsnap.table.tag import Tag
     session = Client().session()
     image_tag = session.query(ImageTag).\
             join(Tag, Tag.tag_id == ImageTag.tag_id).\
             filter(Tag.name == tag_name).\
             filter(ImageTag.image_id == self.image_id).\
             one()
     session.delete(image_tag)