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


Python User.by_id方法代码示例

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


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

示例1: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def post(self):
   """
   Post method to like and unlike blogs
   """
   if self.user:
     if self.request.get("like_blog"):
       _blog_id = self.request.get("like_blog")
       user = self.user
       user_id = user.key.id()
       _user = User.by_id(int(user_id))
       _blog = Blog.get_by_id(int(_blog_id))
       like = Like(user=user.key, blog=_blog.key)
       like.like = 1
       like_key = like.put()
       blog = _blog.key.get()
       blog.likes.append(like_key)
       blog.put()
       self.redirect('/')
     if self.request.get("dislike"):
       _blog_id = self.request.get("dislike")
       user = self.user
       user_id = user.key.id()
       _user = User.by_id(int(user_id))
       _blog = Blog.get_by_id(int(_blog_id))
       like = Like.query(Like.user == user.key, Like.blog == _blog.key).get()
       like_key = like.key
       blog = _blog.key.get()
       blog.likes.remove(like_key)
       blog.put()
       like_key.delete()
       self.redirect('/')
   else:
     self.redirect('/login')
开发者ID:manpreet07,项目名称:multi-user-blog,代码行数:35,代码来源:blog.py

示例2: post_avatar

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def post_avatar(self, *args, **kwargs):
     '''
     Saves avatar - Reads file header an only allows approved formats
     '''
     user = User.by_id(self.session['user_id'])
     if 'avatar' in self.request.files:
         if len(self.request.files['avatar'][0]['body']) < (1024 * 1024):
             if user.avatar == "default_avatar.jpeg":
                 user.avatar = unicode(uuid4()) + u".jpeg"
             ext = imghdr.what(
                 "", h=self.request.files['avatar'][0]['body']
             )
             avatar_path = str(self.application.settings['avatar_dir'] + '/' + user.avatar)
             if ext in ['png', 'jpeg', 'gif', 'bmp']:
                 if os.path.exists(avatar_path):
                     os.unlink(avatar_path)
                 user.avatar = unicode(user.avatar[:user.avatar.rfind('.')] + "." + ext)
                 file_path = str(self.application.settings['avatar_dir'] + '/' + user.avatar)
                 avatar = open(file_path, 'wb')
                 avatar.write(self.request.files['avatar'][0]['body'])
                 avatar.close()
                 dbsession.add(user)
                 dbsession.flush()
                 self.render_page(success=["Successfully changed avatar"])
             else:
                 self.render_page(
                     errors=["Invalid image format, avatar must be: .png .jpeg .gif or .bmp"]
                 )
         else:
             self.render_page(errors=["The image is too large"])
     else:
         self.render_page(errors=["Please provide an image"])
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:34,代码来源:UserHandlers.py

示例3: initialize

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
	def initialize(self, *a, **kw):
		webapp2.RequestHandler.initialize(self, *a, **kw)
		uid = self.read_secure_cookie('user-id')
		self.user = uid and User.by_id(int(uid))
		if self.request.url.endswith('.json'):
			self.format = 'json'
		else:
			self.format = 'html'
开发者ID:daveyshindig,项目名称:TweetMoar,代码行数:10,代码来源:main.py

示例4: render

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def render(self, *args, **kwargs):
     """ Renders the top menu """
     if self.handler.session is not None:
         user = User.by_id(self.handler.session["user_id"])
         if self.handler.session["menu"] == "user":
             return self.render_string("menu/user.html", user=user)
         elif self.handler.session["menu"] == "admin":
             return self.render_string("menu/admin.html", handle=user.handle)
     return self.render_string("menu/public.html")
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:11,代码来源:Menu.py

示例5: do_id

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def do_id(self, user_id):
     '''
     Pull user based on id.
     Usage: id <user_id>
     '''
     user = User.by_id(user_id)
     if user is None:
         print(WARN + str("%s user not found in database." % username))
     else:
         print INFO + repr(user)
开发者ID:mach327,项目名称:RootTheBox,代码行数:12,代码来源:recovery.py

示例6: do_id

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def do_id(self, user_id):
     """
     Pull user based on id.
     Usage: id <user_id>
     """
     user = User.by_id(user_id)
     if user is None:
         print (WARN + "'%s' user not found in database." % username)
     else:
         print INFO + repr(user)
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:12,代码来源:recovery.py

示例7: __crack__

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def __crack__(self, job, weapon_system):
     '''
     Does the actual password cracking, before calling this function you should
     ensure the weapon system is online and not busy
     '''
     results = None
     user = User.by_id(job.user_id)
     if user is None:
         logging.error("Invalid job passed to dispatcher (no user with id %d)." % (
             job.user_id,
         ))
     elif job == None:
         logging.error("Invalid job passed to dispatcher (job is None).")
     else:
         job.started = datetime.now()
         algorithm = Algorithm.by_id(job.algorithm_id)
         try:
             ssh_keyfile = NamedTemporaryFile()
             ssh_keyfile.write(weapon_system.ssh_key)
             ssh_keyfile.seek(0)
             ssh_context = SshContext(
                 weapon_system.ip_address,
                 user=weapon_system.ssh_user, 
                 keyfile=ssh_keyfile.name,
             )
             rpc_connection = rpyc.ssh_connect(
                 ssh_context, 
                 weapon_system.service_port,
             )
             hashes = job.to_list()
             logging.info("Sending %s job to %s for cracking." % (
                 job.job_name, 
                 weapon_system.weapon_system_name,
             ))
             job.status = u"IN_PROGRESS"
             dbsession.add(job)
             dbsession.flush()
             results = rpc_connection.root.exposed_crack_list(
                 job.id, 
                 job.to_list(), 
                 algorithm.algorithm_name,
             )
         except:
             logging.exception("Connection to remote weapon system failed, check parameters.")
         finally:
             ssh_keyfile.close()
         if results is not None:
             job.save_results(results)
         else:
             logging.warn("No results returned from weapon system.")
         job.status = u"COMPLETED"
         job.finished = datetime.now()
         dbsession.add(job)
         dbsession.flush()
         self.__next__()
开发者ID:DJHartley,项目名称:The-Planetary-Assault-System,代码行数:57,代码来源:Dispatch.py

示例8: initialize

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def initialize(self, *a, **kw):
   """
   Initialize method returns user
   :param a:
   :type a:
   :param kw:
   :type kw:
   """
   webapp2.RequestHandler.initialize(self, *a, **kw)
   uid = self.read_secure_cookie('user_id')
   self.user = uid and User.by_id(int(uid))
开发者ID:manpreet07,项目名称:multi-user-blog,代码行数:13,代码来源:blog.py

示例9: initialize

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
    def initialize(self, *a, **kw):
        webapp2.RequestHandler.initialize(self, *a, **kw)
        uid = self.read_secure_cookie('user_id') 
        if not uid:
            self.user = None
        else :
            self.user =  User.by_id(int(uid))
#------------for .json
        if self.request.url.endswith('.json'):
            self.format='json'
        else:
            self.format='html'
开发者ID:kensupernova,项目名称:simple-multiuser-blog,代码行数:14,代码来源:blog.py

示例10: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def get(self):
   """
   Get method to render blog.html
   """
   if self.user:
     user_key = self.user
     user_id = user_key.key.id()
     _user = User.by_id(int(user_id))
     _blogs = Blog.query_blogs().fetch()
     likes = Like.query().fetch()
     self.render('blog.html', blogs=_blogs, user=_user, likes=likes)
   else:
     _blogs = Blog.query_blogs().fetch()
     self.render('blog.html', blogs=_blogs, user=None, likes=None)
开发者ID:manpreet07,项目名称:multi-user-blog,代码行数:16,代码来源:blog.py

示例11: initialize

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
    def initialize(self, *a, **kw):
        """
        Runs on every request.
        Checks that user is logged in.

        """
        webapp2.RequestHandler.initialize(self, *a, **kw)
        uid = self.read_secure_cookie('userId')
        print('INITIALIZE!')
        print(uid)
        self.user = uid and User.by_id(int(uid))

        if self.request.url.endswith('.json'):
            self.format = 'json'
        else:
            self.format = 'html'
开发者ID:iingemar,项目名称:dazzling-octo-blog,代码行数:18,代码来源:base.py

示例12: initialize

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
	def initialize(self, *a, **kw):	
		"""
		Checks if user id and username is valid
		As well as format to JSON for API
		"""
		webapp2.RequestHandler.initialize(self, *a, **kw)
		uid = self.read_secure_cookie('user_id')
		self.user = uid and User.by_id(int(uid))

		if self.request.url.endswith(".json"):
			self.format = "json"
		else:
			self.format = "html"


		def notfound(self):
			self.error(404)
			self.write('<h1>404: Oopsy</h1> Sorry, my friend page does not exist')
开发者ID:charlesjavelona,项目名称:buildawki,代码行数:20,代码来源:main.py

示例13: initialize

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
    def initialize(self, *a, **kw):
        '''
        By default, each instance of the Handler class will have the attributes 
        request, response and app (that's why one can use e.g. self.request.get(); 
        self.request is a request object) because it inherits these attributes from 
        webapp2.RequestHandler. Whenever the handler is called (i.e. when you receive 
        a request for that URL), a new instance is created and initialized with the 
        appropriate values for the attributes.

        The initialize() method is called every time a new instance of NewPost is 
        created (which happens on each http request to the web server) and as you can 
        see it retrieves the user_id from the cookie (if present), retrives the 
        corresponding User from the db and stores it instance variable user (self.user)
        so it can be easily accessed by the rest of the code.
        '''
        webapp2.RequestHandler.initialize(self, *a, **kw)
        uid = self.read_secure_cookie('user_id')
        '''
        If uid has any value that evaluates to True, call the method
        User.by_id(int(uid)) and assign the return value (which will be a User object)
        to self.user. If uid has any value that evaluates to False, assign that value 
        to self.user. In that case, it won't even try to call User.by_id(int(uid)).
        '''
        self.user = uid and User.by_id(int(uid))  # assign a User object to self.user
开发者ID:yijiaow,项目名称:multi-user-blog,代码行数:26,代码来源:main.py

示例14: __crack__

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def __crack__(self, job, weapon_system):
     '''
     Does the actual password cracking, before calling this function you should
     ensure the weapon system is online and not busy
     '''
     user = User.by_id(job.user_id)
     if user == None or job == None:
         logging.error("Invalid job passed to dispatcher.")
     else:
         job.status = u"IN_PROGRESS"
         dbsession.add(job)
         dbsession.flush()
         algo = job.hashes[0].algorithm
         job.started = datetime.now()
         try:
             ssh_keyfile = NamedTemporaryFile()
             ssh_keyfile.write(weapon_system.ssh_key)
             ssh_keyfile.seek(0)
             ssh_context = SshContext(weapon_system.ip_address,
                                      user=weapon_system.ssh_user, keyfile=ssh_keyfile.name)
             rpc_connection = rpyc.ssh_connect(
                 ssh_context, self.service_port)
             hashes = job.to_list()
             results = rpc_connection.root.exposed_crack_list(
                 job.id, job.to_list(), algo, weapon_system.cpu_count)
         except:
             logging.exception("Connection to remote weapon system failed, check parameters")
         finally:
             ssh_keyfile.close()
         if results != None:
             job.save_results(results)
         job.completed = True
         job.finished = datetime.now()
         dbsession.add(job)
         dbsession.flush()
         self.__next__()
开发者ID:brutalhonesty,项目名称:The-Planetary-Assault-System,代码行数:38,代码来源:Dispatch.py

示例15: initialize

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_id [as 别名]
 def initialize(self, *a, **kw):
     webapp2.RequestHandler.initialize(self, *a, **kw)
     uid = self.read_secure_cookie('user_id')
     self.user = uid and User.by_id(int(uid))
开发者ID:Eduardoescamilla,项目名称:Udacity_blog,代码行数:6,代码来源:handler.py


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