当前位置: 首页>>代码示例>>Python>>正文


Python Album.all方法代码示例

本文整理汇总了Python中models.Album.all方法的典型用法代码示例。如果您正苦于以下问题:Python Album.all方法的具体用法?Python Album.all怎么用?Python Album.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Album的用法示例。


在下文中一共展示了Album.all方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import all [as 别名]
    def get(self, hash, extension=None):
        q = Album.all().filter('hash =', hash)
        album = q.get()
        if album:
            if extension:
                return self.error(404)
            
            q = Image.all().filter('album =', album)
            return self.response.out.write(render_template('album.html', {
                'name': album.name,
                'images': q,
            }))

        q = Image.all().filter('hash =', hash)
        image = q.get()
        if image:
            if not extension:
                return self.response.out.write(render_template('image.html',
                    { 'image': image }))
            elif image.extension == extension:
                return write_image(self, image.image_data, extension)
            else:
                return self.error(404)
        
        return self.error(404)
开发者ID:chosak,项目名称:restful-gallery,代码行数:27,代码来源:app.py

示例2: delete

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import all [as 别名]
    def delete(self, album_id, image_id, extension=None):
        """DELETE handler for gallery images.

        URL pattern: /albums/${album_id}/images/${image_id}
        
        If image exists, returns 200 OK. 
        If image doesn't exist, returns 404 NOT FOUND.

        Returns 401 UNAUTHORIZED to all calls if authorization fails.
        """
        q = Album.all().filter('album_id =', album_id)
        album = q.get()
        if not album:
            return self.error(404)

        q = Image.all().filter('album =', album).filter('image_id =', image_id)
        image = q.get()
        if not image:
            return self.error(404)
        
        if extension and extension != image.extension:
            return self.error(404)

        if not config.DEMO_MODE:
            image.delete()
开发者ID:chosak,项目名称:restful-gallery,代码行数:27,代码来源:app.py

示例3: post

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import all [as 别名]
    def post(self, album_id):
        """POST handler for a gallery image.

        URL pattern: /albums/${album_id}/images
        POST data must be of type multipart/form and contain image as 'file'.
        POST data must also contain image metadata: 'name'.
        Image filename must include an extension.

        Returns 201 CREATED with JSON data structure describing new image.
        Returns Content-type: application/json.
        Also returns Location header pointing to API URL for image details.

        Include 'wrapjson' parameter in POST to wrap returns JSON in
        a <textarea>. This also changes the returned Content-type to text/html.

        If album doesn't exist, returns 404 NOT FOUND.
        If request is poorly formatted returns 400 BAD REQUEST.

        Returns 401 UNAUTHORIZED to all calls if authorization fails.
        """
        q = Album.all().filter('album_id =', album_id)
        album = q.get()
        if not album:
            return self.error(404)

        try:
            data = dict(((str(k), v) for k, v in self.request.POST.items()))
            if 'file' in data:
                data['extension'] = data['file'].filename.split('.')[-1].lower()
                if data['extension'] == data['file'].filename:
                    data['extension'] = ''
                else:
                    data['extension'] = '.' + data['extension']
                data['image_data'] = data['file'].file.read()

            image = Image(image_id=config.IMAGE_ID_GENERATOR(),
                          album=album,
                          **data)
        except:
            data = {}
            self.error(400)
        else:
            if not config.DEMO_MODE:
                image.put()

            data = image.to_dict()
            self.response.headers['Location'] = data['url']
            self.response.set_status(201)

        write_json(self, data, wrapjson='wrapjson' in self.request.POST)
开发者ID:chosak,项目名称:restful-gallery,代码行数:52,代码来源:app.py

示例4: update_photos

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import all [as 别名]
def update_photos():
    logging.info('-> updateing pages')
    from importing import get_docs_data, get_albums_data
    albums = get_albums_data(Var.get_value('admin'),Var.get_value('password'))
    
    docs_by_keys = dict((album['res_id'],album) for album in albums)    
    updated_or_deleted = set()
    
    updated_cnt = deleted_cnt = created_cnt = 0  
    pupdated_cnt = pdeleted_cnt = pcreated_cnt = 0
    # updateing
    for album in Album.all():        
        # delete
        if not album.res_id in docs_by_keys:
            for photo in album.photos:
                photo.delete()
                logging.info('photo %s deleted (in album=%s)', photo.res_id, album.res_id)
                pdeleted_cnt+=1
            album.delete()
            deleted_cnt+=1
            logging.info('album %s deleted'%album.res_id)
            updated_or_deleted.add( album.res_id )

        else:        
            # update existing album 
            doc = docs_by_keys[album.res_id]
            album.title = doc['title']
            album.put()            
            logging.info('album %s updated'%doc['res_id'])
            updated_or_deleted.add( album.res_id )            
            
            ######################
            # update/delete his photos            
            pupdated_or_deleted=set()
            pdocs_by_keys = dict( (pdoc['res_id'],pdoc) for pdoc in doc['photos'])
            #add/remove/update
            for photo in album.photos:
                if not photo.res_id in pdocs_by_keys:
                    photo.delete()
                    pdeleted_cnt+=1
                    logging.info('photo %s deleted (in album=%s)', photo.res_id, album.res_id)
                else:
                    pdoc = pdocs_by_keys[photo.res_id]
                    photo.title = pdoc['title']
                    photo.src = pdoc['src']
                    photo.mimetype = pdoc['mimetype']
                    photo.height = pdoc['height']
                    photo.width = pdoc['width']      
                    photo.order = doc['photos'].index(pdoc)              
                    photo.put()
                    pupdated_cnt+=1
                    logging.info('photo %s updated (in album=%s)', photo.res_id, album.res_id)                
                pupdated_or_deleted.add(photo.res_id)
            
            ######################
            ## create new photos
            new_photos_ids = set(pdocs_by_keys) - pupdated_or_deleted
            for new_photo_id in new_photos_ids:
                pdoc = pdocs_by_keys[new_photo_id]
                Photo(
                    album=album,                
                    key_name=pdoc['res_id'],
                    src=pdoc['src'],
                    title=pdoc['title'],
                    mimetype=pdoc['mimetype'],
                    height=pdoc['height'],
                    width=pdoc['width'],
                    order=doc['photos'].index(pdoc)          
                ).put()
                logging.info('photo %s created (in album=%s)', photo.res_id, album.res_id)
                pcreated_cnt+=1        
            updated_cnt+=1
        
    # new pages
    new_albums_ids = set(docs_by_keys) - updated_or_deleted
    for new_album_id in new_albums_ids:
        doc = docs_by_keys[new_album_id]
        # create new album
        album = Album(key_name=doc['res_id'],
                      title = doc['title'])
        album.put()        
        for pdoc in doc['photos']:
            # create new photo
            Photo(
                album=album,                
                key_name=pdoc['res_id'],
                src=pdoc['src'],
                title=pdoc['title'],
                mimetype=pdoc['mimetype'],
                height=pdoc['height'],
                width=pdoc['width'],
                order=doc['photos'].index(pdoc)           
            ).put()
            pcreated_cnt+=1
            logging.info('photo %s created (in album=%s)', pdoc['res_id'], album.res_id )                        
        logging.info('album %s created'%doc['res_id'])
        created_cnt+=1
        
    logging.info('<- updateing album/photos updated=%s created=%s deleted=%s pupdated=%s pcreated=%s pdeleted=%s',
                    updated_cnt, created_cnt, deleted_cnt, pupdated_cnt, pcreated_cnt, pdeleted_cnt)
开发者ID:ppalucki,项目名称:shcms,代码行数:102,代码来源:tasks.py

示例5: photos

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import all [as 别名]
 def photos(self):
     """ zwroc strone ze zdjeciami """
     albums = Album.all()
     return self.render('admin/photos2.html', albums=albums)
开发者ID:ppalucki,项目名称:shcms,代码行数:6,代码来源:admin.py


注:本文中的models.Album.all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。