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


Python Album.put方法代码示例

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


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

示例1: post

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

        URL pattern: /albums
        POST data must contain album metadata: 'name'.

        Returns 201 CREATED with JSON data structure describing new album.
        Returns Content-type: application/json.
        Also returns Location header pointing to API URL for album details.
        
        Include 'wrapjson' parameter in POST to wrap returned JSON in
        a <textarea>. This also changes the returned Content-type to text/html.

        If request is poorly formatted returns 400 BAD REQUEST.

        Returns 401 UNAUTHORIZED to all calls if authorization fails.
        """
        try:
            data = dict(((str(k), v) for k, v in self.request.POST.items()))
            album = Album(album_id=config.ALBUM_ID_GENERATOR(),
                          **data)
        except:
            data = {}
            self.error(400)
        else:
            if not config.DEMO_MODE:
                album.put() 

            data = album.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,代码行数:35,代码来源:app.py

示例2: get

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import put [as 别名]
    def get(self):
    	user = users.get_current_user()
        if user is not None:
            nickname = users.get_current_user().nickname()
            logInOut = users.create_logout_url(self.request.uri)
            greeting = "Please Enter Your Picasa Album Address:"
            gd_client = gdata.photos.service.PhotosService()
            
            # try delete the user's album in the DB
            # pass if can't find.
            try:
                query = "Where owner = '%s'" % (nickname)
                allAlbum = Album.gql(query)
                db.delete(allAlbum)
            except:
                print "no album deleted for %s" % (nickname)
                pass

            # Grab user album list from Google Picasa and store in DB    
            try:
                albumList = gd_client.GetUserFeed(user=user)
                for album in albumList.entry:
                    newAlbum = Album()
                    newAlbum.owner = nickname
                    newAlbum.albumName = album.title.text
                    newAlbum.albumID = album.gphoto_id.text
                    newAlbum.albumPhoto = album.numphotos.text
                    newAlbum.put()
            except:
                print "%s album not added into DB" % (nickname)
                pass
                    # Grab all available albums for the user
            nickname = users.get_current_user().nickname()
            query = "Where owner = '%s'" % (nickname)
            time.sleep(1)
            allAlbum = Album.gql(query)
            print query
            print allAlbum.count()

            template_values = {
                    'user': user,
                    'logInOut': logInOut,
                    'greeting': greeting,
                    'albumInfo': allAlbum,
            }
            return render_template(self, 'index.html', template_values)
        
        else:
            logInOut = users.create_login_url(self.request.uri)
            greeting = "Please Login to continue."

            template_values = {
                'user': user,
                'logInOut': logInOut,
                'greeting': greeting,
            }
            return render_template(self, 'index.html', template_values)
        return render_template(self, 'index.html', template_values)
开发者ID:JimmyCDChen,项目名称:photoAlbum,代码行数:60,代码来源:main.py

示例3: post

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import put [as 别名]
    def post(self):
        user = get_user()

        if user:
            album = Album(parent=DEFAULT_DOMAIN_KEY)
            album.author = user.key
            album.name = self.request.get('album_name')
            album.description = self.request.get('album_desc')

            album.put()

            self.redirect('/album/%s/view' % album.key.integer_id())
        else:
            self.redirect_to_login()
开发者ID:MichaelAquilina,项目名称:Photo-Nebula,代码行数:16,代码来源:views.py

示例4: post

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import put [as 别名]
    def post(self):
        if not users.is_current_user_admin():
            self.redirect('/')
        else:
            try:
                key = ndb.Key(urlsafe=self.request.get('key'))
                album = key.get()
            except:
                album = Album()

            album.populate(name=self.request.get('name'),
                           description=self.request.get('description'))
            album.put()

            self.redirect("/add-album?key=" + album.ukey())
开发者ID:IanChilds,项目名称:ButtonsAndLace,代码行数:17,代码来源:add_album.py

示例5: get

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import put [as 别名]
	def get(self):
		album = ""
		edit = 0
		# Check whether we're creating a album or a Question
		if self.request.GET['album'] == '1':
			questions = ""
			retrieve = 0
			# If coming back from cancelling /question
			if self.request.GET.get('cancel'):
				urlstring = self.request.GET['cancel']
				album_key = ndb.Key(urlsafe=urlstring)
				album = album_key.get()
				questions = Question.query(ancestor=album_key).order(-Question.date).fetch()
				retrieve = 1
			else:
				album = Album(album_type=self.request.GET.get('type'))
				album.album_id = album.put().id()
				album.put()
				# self.response.write(str(album.album_id))
			template_values = {
				'album': album,
				'album_type': album.album_type,
				'questions': questions,
				'edit': edit,
				'retrieve': retrieve
			}
			template = JINJA_ENVIRONMENT.get_template('create.html')
			time.sleep(0.2)
			self.response.write(template.render(template_values))
		else:
			# Create a new Question with edit = 0 to indicate new entry
			urlstring = self.request.GET['id']
			album_key = ndb.Key(urlsafe=urlstring)
			album = album_key.get()
			template_values = {
				'album': album,
				'album_type': album.album_type,
				'edit': edit
			}
			template = JINJA_ENVIRONMENT.get_template('question.html')
			self.response.write(template.render(template_values))
开发者ID:nischalshrestha,项目名称:recognize,代码行数:43,代码来源:recognize.py

示例6: update_photos

# 需要导入模块: from models import Album [as 别名]
# 或者: from models.Album import put [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


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