Example #1
0
File: main.py Project: tav/open-map
def image_list(ctx, key='', cursor=None):
    is_auth(ctx, key)
    q = Image.all()
    if cursor:
        q = q.with_cursor(cursor)
    images = []
    N = 50
    last = N - 1
    idx = None
    for idx, img in enumerate(q.run(limit=N+1)):
        if idx == N:
            break
        images.append(img)
        if idx == last:
            cursor = q.cursor()
    if idx != N:
        cursor = None
    return {'images': images, 'cursor': cursor}
Example #2
0
    def post(self):
        form = json.loads(self.request.body)        

        stream = Stream.getStream(form['stream_id'])
        if not stream:
            return self.respond(error="Stream %(stream_id)r does not exist." % form)

        outpages = []
        images = []
        for idx in form['page_range'].split(','):
            if not idx: break
            idx = int(idx)
            if idx >= len(stream.images): continue

            images.append(stream.images[idx])
            outpages.append(idx)

        self.respond(page_range=outpages,images=images
                     , status="Grabbed pages %r from stream %r" % (outpages,form['stream_id']))
Example #3
0
    def post(self):

        icon_types = [
            {'section':'Application icons'},
            {'type':'iphone_app' 	,'name':'iPhone'		,'size':57	,'filename':'Icon.png'},
            {'type':'iphone4_app' 	,'name':'iPhone 4'		,'size':114	,'filename':'[email protected]'},
            {'type':'ipad_app' 		,'name':'iPad'			,'size':72	,'filename':'Icon-72.png'},
            {'section':'Search/settings icons'},
            {'type':'iphone_spot' 	,'name':'Spotlight iPhone'	,'size':29	,'filename':'Icon-Small.png'},
            {'type':'iphone4_spot' 	,'name':'Spotlight iPhone 4'	,'size':58	,'filename':'[email protected]'},
            {'type':'ipad_spot' 	,'name':'Spotlight iPad'	,'size':50	,'filename':'Icon-Small-50.png'},
            {'section':'Original'},
            {'type':'appstore' 		,'name':'Original' 		,'size':512	,'filename':'Original512.png'},
	 ]



        g = IconSet()
        g.put()     
           
        images = []
        for genre in icon_types:
            if 'section' in genre:
                images.append(genre)
            else:
                img = self.request.get("img")
                size = genre['size']		
                if (size<512):
                    img = db.Blob(self.resize(size,size))
                else:
                    img = db.Blob(img)
                setattr(g,genre['type'],img)
                images.append(genre)
        g.put()	
        path = os.path.join(os.path.dirname(__file__), 'templates','generate.html')
        self.response.out.write(template.render(path, {"images":images, "img_id":g.key()}))
Example #4
0
    def get(self):
        result = list()

        #user_id = request.args.get(user_id)
        user_id = app_global.unicode(self.session.get('user_id'))
        profile = self.request.get('page')
        adored = self.request.get('adored')
            

        if user_id is None:
            user_id = -1

        #Not profile page
        if (profile != "profile"):
            queryImg = Image.query()            # get all images
        #Profile page
        else:
            #queryImg = Image.query()
            queryImg = Image.query(Image.user == str(user_id))
        
        queryImg = queryImg.order(-Image.time_created)
        queryLike = Like.query()            # get likes
        queryComment = ImageComment.query() # get comments
        
        
        #likedByYou = queryLike.filter(Like.userID == str(user_id)).fetch(projection=[Like.imgID])
        likes = queryLike.filter(Like.userID == str(user_id)).fetch(projection=[Like.imgID])
        
        likedByYou = set()
        # add imgID's of images the current user liked to the set likedByYou
        for item in likes:
            likedByYou.add(item.imgID)
     
        images = queryImg.fetch()
        
        if adored is not None and adored == "true":
            likes = Like.query(Like.userID == str(user_id))
            relevantPicIDs = []
            for instance in likes.fetch():
                relevantPicIDs.append(int(instance.imgID))
            queryImg = Image.query().order(-Image.time_created)
            allPics = queryImg.fetch()
            images = []
            for pic in allPics:
                if pic.key.id() in relevantPicIDs:
                    images.append(pic)
            queryLike = Like.query()
        
       
        
        for i in range(0,len(images)):
            im = {}
            key = str(images[i].key.id())
           
            tagObj = ImageTag.query(ImageTag.imageKey == key).fetch(projection=[ImageTag.tag_name])
            tag_arr = []
            for tag in tagObj:
                tag_arr.append(tag.tag_name)
            
            im['uploaded_by'] = images[i].uploadedBy
            im['tags'] = tag_arr
            im['img_id'] = str(images[i].key.id())
            # im['total'] = images[i].total
            im['title'] = images[i].title
            im['image_url'] = images[i].image_url
            im['user_id'] = images[i].user
            im['total_likes'] = queryLike.filter(Like.imgID == im['img_id']).count()

            comments = queryComment.filter(ImageComment.imgID ==  im['img_id'])
            comments = comments.order(-ImageComment.upload_date).fetch()              
            im['comments'] = [c.to_dict() for c in comments]
    
            if adored is not None and adored == "true" and (str(user_id) == str(images[i].user)):
                im['deleteOption'] = "active"
                im['profilePicOption'] = "active"

            if im['img_id'] in likedByYou:
                im['adored'] = True
            else:
                im['adored'] = False

                
            for elem in comments:
                elem.commentID = elem.key.id()
                if elem.userID == str(user_id):
                    elem.yours = 1 #i only check if it exists later on

            result.append(im)
            
            
        #return json.dumps(result[0])
        self.response.out.write(json.dumps(result))