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


Python User.objects方法代码示例

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


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

示例1: put

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
    def put(self, *args, **kwargs):
        if args or 'user' not in kwargs:
            self.raise401()

        username = self.get_argument('username', None)
        email = self.get_argument('email', None)
        password = self.get_argument('password', None)
        first_name = self.get_argument('first_name', None)
        last_name = self.get_argument('last_name', None)

        user = kwargs['user']
        update = {}
        if username:
            update['set__username'] = username
        if email:
            update['set__email'] = email
        if password:
            update['set__password'] = create_password(password)
        if first_name:
            update['set__first_name'] = first_name
        if last_name:
            update['set__last_name'] = last_name

        try:
            User.objects(username=user.username).update_one(**update)
            user = User.objects(name=username or user.username).first()
            self.set_status(201)
            self.write(document_to_json(user, filter_set=_FILTER))
        except Exception as e:
            reason = e.message
            self.raise400(reason=reason)
开发者ID:hitigon,项目名称:warehouse,代码行数:33,代码来源:user.py

示例2: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
    def post(self, *args, **kwargs):
        """Create a new project by providing the details about the project.
        If the validation and saving are successful, it response with the
        project data and 201 status.
        Otherwise, it gives 4XX status and error messages.
        """
        name = self.get_argument('name', None)
        description = self.get_argument('description', None)
        url = self.get_argument('url', None)
        leader = self.get_argument('leader', None)
        members = self.get_argument('members', None)
        teams = self.get_argument('teams', None)
        repos = self.get_argument('repos', None)
        tags = self.get_argument('tags', None)
        if 'user' not in kwargs:
            self.raise401()

        try:
            # todo - better arguments handler
            url = url.strip()
            url = url if url else None
            members_list = []
            repos_list = []
            teams_list = []
            project_leader = kwargs['user']
            if leader:
                project_leader = User.objects(username=leader).first()

            if repos:
                for repo in parse_listed_strs(repos):
                    r = Repo.objects(name=repo).first()
                    if not r:
                        continue
                    repos_list.append(r)
            if members:
                for member in parse_listed_strs(members):
                    u = User.objects(username=member).first()
                    if not u or u == project_leader:
                        continue
                    members_list.append(u)
            if teams:
                for team in parse_listed_strs(teams):
                    t = Team.objects(name=team).first()
                    if not t:
                        continue
                    teams_list.append(t)
            members_list.append(project_leader)
            tags_list = parse_listed_strs(tags)
            project = Project(
                name=name, description=description,
                url=url, repos=repos_list,
                leader=project_leader, members=members_list,
                teams=teams_list, tags=tags_list)
            project.save()
            project_data = document_to_json(project, filter_set=_FILTER)
            self.set_status(201)
            self.write(project_data)
        except Exception as e:
            reason = e.message
            self.raise400(reason=reason)
开发者ID:hitigon,项目名称:warehouse,代码行数:62,代码来源:project.py

示例3: GET

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
 def GET(self,id):
    page=int(web.input().get('page','1'))
    item=Node.objects(ID=int(id)).first()
    #todo 分页 or ajax
    comments=Tweet.objects(Q(SubjectID=int(id))&Q(flag__ne=1)).order_by("-ID") 
    #flag=1 means share 
    next=None
    if Auth.is_login():
         user=User.objects(id=Auth.uid()).first()
         mycollect=user.nodes_follow
         if item.ID in mycollect:
            collected=True
         else:
           collected=False
    else:
         user=None
         collected=False
    if item and  item.creatorID:
        creator=User.objects(ID=item.creatorID).first()
    else:
        creator =None
    datalist=[]
    for comment in comments:
       datalist.append((User.objects(ID=comment.AutherID).first(),comment))
    if user==creator :
            editble=True
    else:
           editble=False
    if  user and ( user.email=="[email protected]" or user.email=="[email protected]"  ):
            editble=True
    return render.item(editble=editble,user=user,creator=creator,item=item,datalist=datalist,collected=collected)
开发者ID:sinreal,项目名称:miihui,代码行数:33,代码来源:item.py

示例4: delete

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
 def delete(self, *args, **kwargs):
     # auth code and token
     if args or 'user' not in kwargs:
         self.raise401()
     user = kwargs['user']
     try:
         User.objects(username=user.username).delete()
         self.set_status(204)
         self.finish()
     except Exception as e:
         reason = e.message
         self.raise400(reason=reason)
开发者ID:hitigon,项目名称:warehouse,代码行数:14,代码来源:user.py

示例5: POST

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
 def POST(self):
   unfoid=web.input().get("unfollow")
   thisguy=User.objects(ID=int(unfoid)).first()
   user=User.objects(id=Auth.uid()).first()
   followings=user.followings
   _id=int(unfoid)
   if _id in followings:
      followings.remove(_id)
      user.followings=followings
      user.followings_count-=1
      thisguy.followed_count-=1
      user.save()
      thisguy.save()
      return "Unfollow_success"
   return "cant unfollow"
开发者ID:sinreal,项目名称:miihui,代码行数:17,代码来源:user.py

示例6: GET

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
 def GET(self,uid):
     #关注我的人 should keep it in  a list ?
     if Auth.is_login():
             me=User.objects(id=Auth.uid()).first()
     else:
            me=None
     user=User.objects(ID=int(uid)).first()
     followeds=User.objects(followings=user.ID)
     page=int(web.input().get("page","1"))
     count=user.followed_count
     if page*10<count:
        next=page+1
     else:
        next=None      
     return render.followeds(user=me,thisguy=user,count=count,next=next,followeds=followeds)
开发者ID:sinreal,项目名称:miihui,代码行数:17,代码来源:user.py

示例7: search

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
 def search(query,callback=None):
     results = {}
     results['users'] = User.objects(Q(name__istartswith=query) |  Q(username__istartswith=query)).only("_id","name","username","about")
     results['tags'] = Tag.objects(Q(name__istartswith=query)).no_sub_classes().only("_id","name","about")
     if callback != None:
         return callback(results)
     return results
开发者ID:CarbonComputed,项目名称:flotag,代码行数:9,代码来源:search.py

示例8: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
    def post(self, *args, **kwargs):
        client_id = self.get_argument('client_id', None)
        user_id = self.get_argument('user_id', None)
        scopes = self.get_argument('scopes', [])

        try:
            base_uri, uri = self.get_uri()
            scopes_list = parse_listed_strs(scopes)
            client = Client.objects(client_id=client_id).first()
            user = User.objects(id=ObjectId(user_id)).first()
            cred = Credential.objects(
                client_id=client_id, user_id=user_id).first()
            if not client or not user or not cred:
                raise Exception('Authorization failed')
            credentials = {
                'client_id': cred.client_id,
                'response_type': cred.response_type,
                'request': binary_to_request(cred.request),
                'redirect_uri': cred.redirect_uri,
                'state': cred.state,
                'user': user,
            }
            content = self.endpoint.create_authorization_response(
                uri, 'GET', {}, {}, scopes_list, credentials)
            self.redirect(content[0]['Location'])
        except Exception as e:
            self.write(self.get_response(error=e))
开发者ID:hitigon,项目名称:warehouse,代码行数:29,代码来源:auth.py

示例9: facebook_authorized

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
def facebook_authorized():
    resp = facebook.authorized_response()
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    if isinstance(resp, OAuthException):
        return 'Access denied: %s' % resp.message

    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me')
    username = me.data['name']
    email= me.data['email']
    user = User.objects(email=email).first()
    if user:
        session['user_id'] = str(user.id)
    else:
        user = User()
        user.email = email
        user.username = username
        user.save()
        Inventory(owner=user.to_dbref(),
                      name='Basic',
                      is_basic=True).save()

    return redirect('/')
开发者ID:Rmanolis,项目名称:rpg-demo,代码行数:29,代码来源:app.py

示例10: post_app

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
def post_app():
    #print('form')
    signed_request = request.form.get('signed_request')
    data = facebook_tools.parse_signed_request(signed_request,
                                              FACEBOOK_APP_SECRET)
    print(signed_request)
    print(data)
    session['oauth_token'] = (data['oauth_token'],'')
    me = facebook.get('/me')
    username = me.data['name']
    email= me.data['email']
    user = User.objects(email=email).first()
    if user:
        session['user_id'] = str(user.id)
    else:
        user = User()
        user.email = email
        user.username = username
        user.save()
        Inventory(owner=user.to_dbref(),
                      name='Basic',
                      is_basic=True).save()


    return send_file('public/index.html')
开发者ID:Rmanolis,项目名称:rpg-demo,代码行数:27,代码来源:app.py

示例11: admin_get_user_token

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
def admin_get_user_token():
    user_id = request.values.get("user_id")
    try:
        user = User.objects(user_id=user_id).get()
        return jsonify(access_token=user.login.get_auth_token())
    except:
        return jsonify(err="User not found")
开发者ID:hochbergg,项目名称:cartman,代码行数:9,代码来源:admin.py

示例12: get_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
def get_user():
    id = get_user_id()
    if id:
        u = User.objects(id=id).first()
        return u
    else:
        return None
开发者ID:Rmanolis,项目名称:rpg-demo,代码行数:9,代码来源:common.py

示例13: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
    def post(self):
        data = self.post_schema()
        name = data['name']
        password = data['password']
        try:
            user = User.objects(name=name).get()
        except DoesNotExist:
            # 失败
            self.write_not_found_entity_response()
            # self.render("login.html", error="name not found")
            return

        hashed_password = bcrypt.hashpw(utf8(password),
                                        utf8(user.hashed_password))
        if hashed_password == user.hashed_password:
            # 成功
            self.set_secure_cookie("shanbay_user", str(user.id))
            self.write_response(user.format_response())
            return
            # self.render("home.html")
            # self.redirect(self.get_argument("next", "/"))
        else:
            logging.error("incorrect password")
            self.render("login.html", error="incorrect password")
            return
开发者ID:MioYvo,项目名称:shanbay,代码行数:27,代码来源:user_handler.py

示例14: put

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
    def put(self, *args, **kwargs):
        if 'user' not in kwargs or not args:
            self.raise401()
        update = {}
        user = kwargs['user']
        task_id = parse_path(args[0])[0]
        task = Task.objects(id=task_id).first()
        project = task.project
        if not project or user not in project.members:
            self.raise401()
        category = self.get_argument('category', None)
        description = self.get_argument('description', None)
        project_name = self.get_argument('project', None)
        status = self.get_argument('status', None)
        priority = self.get_argument('priority', None)
        assign_to = self.get_argument('assign_to', None)
        due = self.get_argument('due', None)
        tags = self.get_argument('tags', None)

        if category:
            update['set__category'] = category
        if description:
            update['set__description'] = description
        if project_name:
            project = Project.objects(name=project_name).first()
            if not project or user not in project.members:
                self.raise401()
            update['set__project'] = project
        if assign_to:
            assign_to_list = []
            for member in parse_listed_strs(assign_to):
                u = User.objects(username=member).first()
                if not u:
                    continue
                assign_to_list.append(u)
            update['set__assign_to'] = assign_to_list
        if status:
            update['set__status'] = status
        if priority:
            update['set__priority'] = priority
        if due:
            try:
                due_day = int(due)
            except ValueError:
                due_day = 0
            due_time = get_utc_time(due_day * 24 * 3600)
            update['set__due'] = due_time
        if tags:
            tags_list = parse_listed_strs(tags)
            update['set__tags'] = tags_list
        try:
            Task.objects(id=task_id).update_one(**update)
            task = Task.objects(id=task_id).first()
            task_data = document_to_json(task, filter_set=_FILTER)
            self.set_status(201)
            self.write(task_data)
        except Exception as e:
            reason = e.message
            self.raise400(reason=reason)
开发者ID:hitigon,项目名称:warehouse,代码行数:61,代码来源:task.py

示例15: load_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import objects [as 别名]
 def load_user(id):
     if id in (None, 'None'):
         return None
     try:
         from models.user import User
         return User.objects(id=id).first()
     except:
         return None
开发者ID:Lunchable,项目名称:eat,代码行数:10,代码来源:factory.py


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