Ejemplo n.º 1
0
Archivo: index.py Proyecto: jroes/tsurp
    def get(self, user_nickname):
        try:
            
            extra_header_values = {
                'title': 'tsurp: %s''s images' % user_nickname
                }

            user_nickname = urllib.unquote(user_nickname)

            images = db.GqlQuery("SELECT * FROM Image WHERE author_nickname = :1", user_nickname)

            if not images or not isinstance(images, db.GqlQuery):
                self.error(404)
                return

            images_table = "<table id='images_table'>"
            rowcount = 0
            rows = "<tr>"
            for img in images:
                # 5 images per row
                if (rowcount % 5) == 0 and rowcount > 0:
                    rows += "</tr><tr>"
                    
                image_url = "/%s" % to_url56(img.key().id())
                image_src_url = "/img%s" % image_url
                rows += "<td>"
                rows += "<a href='%s'>" % image_url
                rows += "<img src='%s' /></a>" % image_src_url
                rows += "</td>"
                rowcount += 1
            images_table += rows
            images_table += "</tr></table>"

            values = {
                'images_table': images_table,
                'username': user_nickname
                }

            write_template(self.response, 'userimages.html', values, 
                           extra_header_values)
        except Exception, e:
            self.error(404)
            logging.error('%s: %s' % (self.__class__.__name__,
                          traceback.print_exc()))
Ejemplo n.º 2
0
    def add(image_data, ext, author=None, title=''):
        image = Image()

        image.image = db.Blob(image_data)
        image.ext = ext
        if author:
            image.author_nickname = author.nickname()
            image.author = author
        image.title = title
        image.put()

        image_id = to_url56(image.key().id())
        try:
            memcache.add(image_id, image)
        except ValueError:
            # too big for memcache
            pass

        return image_id