Пример #1
0
 def get_images(cls, entity):
     images = []
     for img in entity.get_images():
         images.append(
             ProductImage(url=img.get_serving_url(),
                          type=cls.get_image_type(img),
                          featured=img.featured))
     return images
Пример #2
0
    def get_images(cls, entity):
        images = []
        for img in entity.get_images():
            user = img.creator.get()

            creator = UserResponse(user_key=user.key.urlsafe())

            images.append(ProductImage(image_key=img.key.urlsafe(),
                                       url=img.get_serving_url(),
                                       type=cls.get_image_type(img),
                                       featured=img.featured,
                                       creator=creator,
                                       ocr_result=img.ocr_result))

        return images
Пример #3
0
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}
Пример #4
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']))
Пример #5
0
        def callback():
            p = page.key.get()

            images = []
            for n, i in enumerate(layout.get('images', [])):
                if n >= len(p.images):
                    images.append(
                        Image(key=ndb.Key('Image', str(n), parent=p.key),
                              width=i[0],
                              height=i[1]))
                    p.images.append(images[-1].key)
            ndb.put_multi_async(images)

            for d in ['links', 'text', 'lines', 'maps']:
                a = getattr(p, d)
                a.extend([t.get(d, d)] * (layout.get(d, 0) - len(a)))
            p.layout = layoutid
            p.put()
            return p
Пример #6
0
    def get(self):
        images = []
        file = BytesIO(urllib2.urlopen(
            "https://account-sockclub-com.s3.amazonaws.com/deck_creation/5694660253057024_deck_page1.jpg").read())
        im = Image.open(file)
        im = im.convert('RGB')
        im = im.resize((595, 842), Image.ANTIALIAS)

        file = BytesIO(urllib2.urlopen(
            "https://account-sockclub-com.s3.amazonaws.com/deck_creation/5694660253057024_deck_page2.jpg").read())
        im2 = Image.open(file)
        im2 = im2.convert('RGB')
        im2 = im2.resize((595, 842), Image.ANTIALIAS)

        images.append(im2)

        logging.info(PIL.__version__)

        pdf = BytesIO()
        im.save(pdf, "PDF", quality=100, save_all=True, append_images=images)
        # logging.info(pdf.getvalue())
        self.response.headers['Content-Type'] = "application/pdf"
        self.response.out.write(pdf.getvalue())
Пример #7
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':'*****@*****.**'},
            {'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':'*****@*****.**'},
            {'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()}))
Пример #8
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))