Example #1
0
    def set_tags(self, tag_labels):
        from gallery.db.models import Tag
        tags = []

        for label in tag_labels:
            t = session.query(Tag).filter(Tag.label == label).first()
            if not t:
                t = Tag(label)
                session.add(t)
            
            tags += [ t ]

        self.tags = tags
        session.flush()
Example #2
0
def image_server(request):
    # example request: /view/PHOTOKEY/width
    args = request.matchdict.get('args')

    if not args or len(args) < 1:
        return httpexceptions.HTTPBadRequest('Missing key parameter')

    key = args[0]
    p = session.query(Photo).filter_by(key = key).first()
    if not p:
        return httpexceptions.HTTPNotFound('Could not find that image')

    path = p.path

    if not os.path.exists(path):
        return httpexceptions.HTTPNotFound('Da plaatje ken ik nie vinde nie')

    if len(args) >= 2:
        scale = args[1]
        try:
            scale = int(scale)
        except ValueError:
            return httpexceptions.HTTPBadRequest('Invalid scale parameter')

        if scale < 16 or scale > 1024:
            return httpexceptions.HTTPBadRequest("Scale value outside acceptable range")
        
        from StringIO import StringIO
        img = Image.open(path)
        b = StringIO()
        img.thumbnail((scale, scale), Image.ANTIALIAS)
        img.save(b, "JPEG")
        b.seek(0)
        pdata = b.read()
    else:
        pdata = open(p.path).read()

    # hardcoded jpg for now
    return Response(body=pdata, content_type='image/jpeg')
Example #3
0
 def find_by_tag(txt):
     #.join(PhotoTag,Tag)\
     q = session.query(Photo)\
         .join(Photo.tags)\
         .filter(Tag.label.like('%' + txt + '%'))
     return q