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


Python User.get_user方法代码示例

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


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

示例1: notify_user

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
 def notify_user(self, sender, conv_id, msg):
     #TODO: use task queue
     conv = Conversation.get_by_id(int(conv_id))
     for uname in conv.receivers_list_norm:
         if uname != sender:
             user = User.get_user(uname)
             if user.notify_on_msg:
                 new_message_notify(user.email, conv_id, msg)
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:10,代码来源:messages.py

示例2: get

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
    def get(self, username):
        """display profile of user with username, if None, display logged in user
        """
        mode = self.request.get('mode')
        upload_url = ""

        if mode == 'add_project':
            template = 'profile/add_project.html'
            upload_url = blobstore.create_upload_url('/' + username, max_bytes_per_blob=self.MAX_IMG_SIZE)
        elif mode == 'edit_project':
            template = 'profile/edit_project.html'
            upload_url = blobstore.create_upload_url('/' + username, max_bytes_per_blob=self.MAX_IMG_SIZE)
        elif mode == 'edit':
            template = 'profile/edit.html'
        else:
            template = 'profile/profile.html'

           

        user = User.get_user(username)

        if not user:
            user = User.save(username, '{}@someplace.com'.format(username), 'some long password')


        gravatar = user.avatar_url
        friends = []

        

        if user:
            all, ic, cc = self.organize_courses_for(user)

            if user.dob:
                dob = user.dob.strftime('%m/%d/%Y')
            else:
                dob = None

            projects = Project.get_projects_by_ids(user.projects)

            context = {'user': user,
                       'dob': dob,
                       'username': username,
                       'gravatar': gravatar,
                       'friends': friends,
                       'friend_btn': False,
                       'courses_all': Course.courses_to_dict(),
                       'courses_completed': cc,
                       'courses_incomplete': ic,
                       'projects': projects,
                       'upload_url': upload_url,
                       'errors': {}}

            self.render(template, context)
        else:
            self.redirect('/logout')
开发者ID:nitishparkar,项目名称:udacityplus,代码行数:58,代码来源:profile.py

示例3: get

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
    def get(self):
        name = self.get_cookie('username')
        friends = None

        if name:
            user = User.get_user(name)
            if user:
                friends = user.get_friends()

        template_values = {'title' : self.get_title(), 'username': name, 'friends': friends}
        self.render("index.html", template_values)
开发者ID:nitishparkar,项目名称:udacityplus,代码行数:13,代码来源:home.py

示例4: get

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
    def get(self, username):
        """display profile of user with username, if None, display logged in user
        """
        if not username:
            username = self.get_cookie("username")

        user = User.get_user(username)
        if user:
            # this is for link to logged in user's profile
            username = self.get_cookie("username")
            me = User.get_user(username)
            friends = me.get_friends()

            if friends:
                friend_btn = user.username_norm not in (f.username_norm for f in friends)
            else:
                friend_btn = True
            context = {'user': user, 'username': username, 'friends': friends, 'friend_btn': friend_btn}

            self.render("profile/profile.html", context)
        else:
            self.abort(404)
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:24,代码来源:profile.py

示例5: get

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
    def get(self):
        name = self.get_cookie('username')
        friends = None
        template_values = {}

        if name:
            user = User.get_user(name)
            if user and Authentication.valid_log_token(user.username_norm, user.log_token):
                friends = user.get_friends()
                template_values = {'title' : self.get_title(), 'username': name, 'friends': friends}
            else:
                self.redirect('/logout')

        self.render("index.html", template_values)
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:16,代码来源:home.py

示例6: get

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
    def get(self, conv_id=None, msg_id=None):
#       (conv_id and msg_id) or (not conv_id and not msg_id)
        if not bool(conv_id) ^ bool(msg_id):
            username = self.get_cookie("username")
            show, start, end, thread, id = self.get_params(["show", "from", "to", "thread", "id"])

            me = User.get_user(username)
            friends = me.get_friends()

            if show in ('all', 'new') or not show:
                if show == 'new':
                    self.show_form_for_new_message(conv_id, msg_id, friends)
                elif show == 'all' or not (show or conv_id or msg_id):
                    self.display_messages(username, start, end, friends)
                elif conv_id and msg_id:
                    self.display_message(int(msg_id), int(conv_id), friends)
            else:
                self.response.out.write("invalid url")
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:20,代码来源:messages.py

示例7: get

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
    def get(self, username):
        """display profile of user with username, if None, display logged in user
        """
        mode, = self.get_params(['mode'])


        if mode != 'edit':
            template = 'profile/profile.html'
        else:
            template = 'profile/edit.html'

        user = User.get_user(username)

        if not user:
            user = User.save(username, '{}@someplace.com'.format(username), 'some long password')


        gravatar = user.avatar_url
        friends = []

        if user:
            all, ic, cc = self.organize_courses_for(user)

            if user.dob:
                dob = user.dob.strftime('%m/%d/%Y')
            else:
                dob = None


            context = {'user': user,
                       'dob': dob,
                       'username': username,
                       'gravatar': gravatar,
                       'friends': friends,
                       'friend_btn': False,
                       'courses_all': Course.courses_to_dict(),
                       'courses_completed': cc,
                       'courses_incomplete': ic,
                       'errors': {}}

            self.render(template, context)
        else:
            self.redirect('/logout')
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:45,代码来源:profile.py

示例8: show_form_for_new_message

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
    def show_form_for_new_message(self, thread=None, id=None, friends=None, errors=None):
        """Shows a form for a brand new message and a reply if given thread and id
        """
        username = self.get_cookie('username')
        if not friends:
            user = User.get_user(username)
            friends = user.get_friends()

        context = {'friends': friends, 'username': username, 'errors': errors}

        if id and thread:
            id = int(id)
            thread = int(thread)

            msg = Message.get_by_id(id)
            conv = Conversation.get_by_id(thread)

            context['receiver'] = msg.sender
            context['title'] = conv.title

        self.render("messages/new_message.html", context)
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:23,代码来源:messages.py

示例9: post

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
    def post(self, username):
        mode = self.request.get('mode')
        if mode == 'add_project':
            blob_info = None
            fileerror = 'Screenshot is mandatory'
            upload_files = self.get_uploads('screenshot')
            if upload_files:
                blob_info = upload_files[0]
                if 'image' in blob_info.content_type:
                    screenshot = blob_info.key()
                    screenshot_url = images.get_serving_url(screenshot)
                    fileerror = ''
                else:
                    # uploaded file wasn't an images, hence remove from the blobstore
                    blobstore.delete(blob_info.key())
                    fileerror = 'Invalid image type'
            else:
                fileerror = 'Please provide a screenshot of your project (max size: 1MB)'

            title = self.request.get('title').strip()
            titleerror = validate_project_title(title)

            url = self.request.get('url').strip()
            urlerror = validate_project_url(url)

            short_description = self.request.get('short_description').strip()
            sderror = validate_project_short_description(short_description)
            
            if titleerror or urlerror or sderror or fileerror:
                if blob_info and not fileerror:
                    # blob was okay but validation of some other field failed
                    # hence remove it to avoid orphaned entry
                    # also remove the serving url
                    Project.remove_screenshot_blob(blob_info.key())

                user = User.get_user(username)
                template = 'profile/add_project.html'
                upload_url = blobstore.create_upload_url('/' + username, max_bytes_per_blob=self.MAX_IMG_SIZE)
                context = { 'user': user,
                            'username': username,
                            'title': title,
                            'url': url,
                            'short_description': short_description,
                            'upload_url': upload_url,
                            'titleerror': titleerror,
                            'urlerror': urlerror,
                            'sderror': sderror,
                            'fileerror': fileerror}
                self.render(template, context)
                return
            else:
                user = User.get_user(username)
                project_id = Project.add_project(title=title, screenshot=screenshot,
                    screenshot_url=screenshot_url, url=url, short_description=short_description, 
                    author=user.key)

                User.add_project(username, project_id)
                
        elif mode == 'edit_project':
            blob_info = None
            screenshot = None
            screenshot_url = None
            fileerror = ''

            upload_files = self.get_uploads('screenshot')
            if upload_files:
                blob_info = upload_files[0]
                if 'image' in blob_info.content_type:
                    screenshot = blob_info.key()
                    screenshot_url = images.get_serving_url(screenshot)
                else:
                    # uploaded file wasn't an images, hence remove from the blobstore
                    blobstore.delete(blob_info.key())
                    fileerror = 'Invalid image type'

            project_id = self.request.get('projects_dropdown')

            title = self.request.get('title').strip()
            titleerror = validate_project_title(title)

            url = self.request.get('url').strip()
            urlerror = validate_project_url(url)

            short_description = self.request.get('short_description').strip()
            sderror = validate_project_short_description(short_description)

            if titleerror or urlerror or sderror or fileerror:
                if blob_info and not fileerror:
                    # same as above
                    Project.remove_screenshot_blob(blob_info.key())
                
                user = User.get_user(username)
                projects = Project.get_projects_by_ids(user.projects)
                upload_url = blobstore.create_upload_url('/' + username, max_bytes_per_blob=self.MAX_IMG_SIZE)
                template = 'profile/edit_project.html'
                context = { 'user': user,
                            'username': username,
                            'title': title,
                            'url': url,
                            'short_description': short_description,
#.........这里部分代码省略.........
开发者ID:nitishparkar,项目名称:udacityplus,代码行数:103,代码来源:profile.py

示例10: checkUsernameAvailability

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
	def checkUsernameAvailability(self, username):
		users = User.get_user(username)
		self.response.out.write(users != None)
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:5,代码来源:RPC.py

示例11: valid_log_token

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
 def valid_log_token(username, log_token):
     user = User.get_user(username)
     return user and bc.hashpw(log_token, user.log_token) == user.log_token
开发者ID:ArslanRafique,项目名称:udacityplus,代码行数:5,代码来源:authentication.py

示例12: valid_login

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
 def valid_login(username, password):
     user = User.get_user(username)
     if user and bc.hashpw(password, user.password) == user.password:
         return Authentication.create_and_save_log_token(user) 
开发者ID:ArslanRafique,项目名称:udacityplus,代码行数:6,代码来源:authentication.py

示例13: valid_log_token

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import get_user [as 别名]
 def valid_log_token(username, log_token):
     if username:
         username = username.lower()
         user = User.get_user(username)
         return user and log_token == user.log_token
开发者ID:Ramesh7128,项目名称:udacityplus,代码行数:7,代码来源:authentication.py


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