• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.User类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: qq_weibo_get_code

def qq_weibo_get_code():
    code = request.args['code']
    openid = request.args['openid']
    openkey = request.args['openkey']

    qqbot = db.session.query(Bot).filter(Bot.type == 1).one()
    bot = qqbot.build_bot()
    resp = bot.request_access_token(code)
    resp.openid = openid
    resp.openkey = openkey
    logger.debug(resp)

    u = db.session.query(User).filter(User.openid == openid)
    if u.count():
        u = u.one()
        u.assign(resp)
    else:
        u = User()
        u.assign(resp)
        db.session.add(u)
        logger.info('Created new user <%s %s>' % (u.name, u.openid))
    db.session.commit()

    if not u.token:
        u.generate_token()

    return 'your arm server token: %s' % (u.token)
开发者ID:bcho-archive,项目名称:remote_server,代码行数:27,代码来源:views.py


示例2: post

    def post(self):
        data = request.form
        print data
        if len(set(['name', 'cost', 'payer', 'buyins']) &
               set([x for x in data])) == 4:

            # Validate that users involved have accounts

                # Extract payer id
            payer = User.objects(username=data['payer'])
            payer_id = payer[0].id

                # Extract ids of those who buy in
            buyins = User.objects(username__in=data['buyins'])
            buyin_ids = map(lambda x: x.id, buyins)

            purchase = Purchase(name=data['name'],
                                cost=data['cost'],
                                payer=payer_id,
                                buyins=buyin_ids,
                                time=datetime.datetime.now())
            purchase.save()

            debt_up_to_date = self.updateDebt(purchase)

            return jsonify({'res': True,
                            'messsage': 'Purchase added',
                            'debts': debt_up_to_date})
        return jsonify({'res': False,
                        'message': 'default'})
开发者ID:sambodanis,项目名称:Receipt-Tracker,代码行数:30,代码来源:views.py


示例3: test_user_password

    def test_user_password(self, testapp):
        """ Test password hashing and checking """

        admin = User('admin', 'supersafepassword')

        assert admin.username == 'admin'
        assert admin.check_password('supersafepassword')
开发者ID:MadJukesInc,项目名称:WhatTheHellIs.com,代码行数:7,代码来源:test_models.py


示例4: setUp

  def setUp(self):
    t = Tool(id=1, name='test_tool', status=1, status_message='working ok')
    t.save()

    u = User(id=1, name='Test user', subscribed=True)
    u.card_set.add(Card(card_id='12345678'))
    u.save()
开发者ID:paullessing,项目名称:acserver-django,代码行数:7,代码来源:tests.py


示例5: staff_group_add

def staff_group_add(cid, email, aid):
    assign = Assignment.query.filter_by(id=aid, course_id=cid).one_or_none()
    if not assign or not Assignment.can(assign, current_user, 'grade'):
        flash('Cannot access assignment', 'error')
        return abort(404)

    form = forms.StaffAddGroupFrom()
    result_page = url_for('.student_assignment_detail', cid=cid,
                          email=email, aid=aid)

    student = User.lookup(email)
    if not student:
        return abort(404)

    if form.validate_on_submit():
        target = User.lookup(form.email.data)
        if not target or not target.is_enrolled(cid):
            flash("This user is not enrolled", 'warning')
            return redirect(result_page)
        try:
            Group.force_add(current_user, student, target, assign)
        except BadRequest as e:
            flash("Error: {}".format(str(e.description)), 'error')
            return redirect(result_page)

    return redirect(result_page)
开发者ID:gratimax,项目名称:ok,代码行数:26,代码来源:admin.py


示例6: test_is_staff

    def test_is_staff(self):
        self.setup_course()
        random_user = User(name=self.studentA['name'], email=self.studentA['email'])
        db.session.add(random_user)
        db.session.commit()

        self.assertTrue(self.staff1.is_staff())
        self.assertTrue(self.admin.is_staff())
        self.assertFalse(self.user1.is_staff())
        self.assertFalse(random_user.is_staff())
开发者ID:Cal-CS-61A-Staff,项目名称:ok,代码行数:10,代码来源:test_enrollment.py


示例7: post

 def post(self):
     try:
         username = generate_username()
         user = User(username=username)
         user.save()
         self.write(json.dumps(user.to_representation()))
     except Chat.DoesNotExist:
         self.clear()
         self.set_status(404)
         self.finish({'error': 'not found'})
开发者ID:opalczynski,项目名称:gameofspots,代码行数:10,代码来源:handlers.py


示例8: test_lookup

    def test_lookup(self):
        email = '[email protected]'

        user = User.lookup(email)
        assert user is None

        db.session.add(User(email=email))
        db.session.commit()

        user = User.lookup(email)
        assert user.email == email
开发者ID:Cal-CS-61A-Staff,项目名称:ok,代码行数:11,代码来源:test_user.py


示例9: post

 def post(self):
     if self.registration_form.validate_on_submit():
         try:
             user = User(self.registration_form.login.data, self.registration_form.password.data)
             user.email = self.registration_form.email.data
             db.session.add(user)
             db.session.commit()
             session['userId'] = user.id
             flash('Willkommen Benutzer "%s".' % user.login, 'info')
             return redirect(url_for('vote.home.inactive'))
         except IntegrityError:
             self.registration_form.login.errors.append("Eine Benutzer mit diesem Login existiert bereits")
             return self.render()
     return self.render()
开发者ID:dennisausbremen,项目名称:tunefish,代码行数:14,代码来源:session_mgmt.py


示例10: me

def me(user: User):
    """
    User object representation ready for JSON serialization.

    :param user: User object
    :return: Dictionary with User representation fields
    """
    return {
        'id':         user.id,
        'nickname':   user.nickname,
        'university': University.query.get(user.university).name,
        'gender':     user.get_gender(),
        'boards':     [board(b) for b in user.get_boards()],
        'profilepic': user.profilepic
    }
开发者ID:ar3s3ru,项目名称:uChan3,代码行数:15,代码来源:JSONRepresentation.py


示例11: test_enroll_from_form

    def test_enroll_from_form(self):
        self.setup_course()

        Enrollment.enroll_from_form(self.course.id, make_enrollment_form(self.studentB))

        user = User.lookup(self.studentB['email'])
        self.studentB['id'] = user.id

        self.enrollment_matches_info(user, self.studentB)

        Enrollment.enroll_from_form(self.course.id, make_enrollment_form(self.lab_assistantA))
        lab_assistant = User.lookup(self.lab_assistantA['email'])
        self.lab_assistantA['id'] = lab_assistant.id

        self.enrollment_matches_info(lab_assistant, self.lab_assistantA)
开发者ID:Cal-CS-61A-Staff,项目名称:ok,代码行数:15,代码来源:test_enrollment.py


示例12: test_basic

    def test_basic(self):
        i = User(username='alice', email='[email protected]')
        j = User(username='bob', email='[email protected]')
        db.session.add(i)
        db.session.add(j)
        db.session.commit()

        t = i.create_task(title='I want to test', abstract='a test', content='I want to test the test part.') 
#        db.session.add(t)
#        db.session.commit()
        assert len(i.watched_tasks) == 1
        assert len(t.watcher.all()) == 1
        j.watch_task(t)
        assert len(i.watched_tasks) == 1
        assert len(t.watcher.all()) == 2
        assert j in t.watcher.all()
开发者ID:WilliamChui,项目名称:SYSU-Software-2015,代码行数:16,代码来源:test_task.py


示例13: test_score_staff

    def test_score_staff(self):
        self._test_backup(True)

        user = User.lookup(self.user1.email)
        self.login(self.staff1.email)

        response = self.client.post('/api/v3/score/')
        self.assert_400(response)
        assert response.json['code'] == 400
        backup = Backup.query.filter(Backup.submitter_id == user.id).first()

        data = {'bid': encode_id(backup.id), 'kind': 'Total',
                'score': 128.2, 'message': 'wow'}
        response = self.client.post('/api/v3/score/', data=data)
        self.assert_200(response)
        assert response.json['code'] == 200

        self.logout()
        self.login(self.admin.email)

        data = {'bid': encode_id(backup.id), 'kind': 'Total',
                'score': 128.2, 'message': 'wow'}
        response = self.client.post('/api/v3/score/', data=data)
        self.assert_200(response)
        assert response.json['code'] == 200
开发者ID:Cal-CS-61A-Staff,项目名称:ok,代码行数:25,代码来源:test_api.py


示例14: test_export_final

    def test_export_final(self):
        self._test_backup(True)
        student = User.lookup(self.user1.email)

        backup = Backup.query.filter(Backup.submitter_id == student.id).first()
        endpoint = '/api/v3/assignment/{0}/submissions/'.format(self.assignment.name)

        response = self.client.get(endpoint)
        self.assert_403(response)

        self.login(self.staff1.email)
        response = self.client.get(endpoint)
        self.assert_200(response)
        backups = response.json['data']['backups']
        self.assertEqual(len(backups), 1)
        self.assertEqual(backups[0]['is_late'], False)
        self.assertEqual(len(backups[0]['group']), 1)
        self.assertEqual(backups[0]['group'][0]['email'], self.user1.email)
        self.assertEqual(len(backups[0]['messages']), 1)

        self.assertEqual(response.json['data']['count'], 1)
        self.assertEqual(response.json['data']['has_more'], False)
        self.assertEqual(response.json['data']['offset'], 0)

        response = self.client.get(endpoint + '?offset=1')
        self.assert_200(response)
        backups = response.json['data']['backups']
        self.assertEqual(len(backups), 0)
        self.assertEqual(response.json['data']['count'], 1)
        self.assertEqual(response.json['data']['has_more'], False)
        self.assertEqual(response.json['data']['offset'], 1)
开发者ID:Cal-CS-61A-Staff,项目名称:ok,代码行数:31,代码来源:test_api.py


示例15: test_export_user

    def test_export_user(self):
        self._test_backup(True)
        student = User.lookup(self.user1.email)
        self.login(self.staff1.email)

        backup = Backup.query.filter(Backup.submitter_id == student.id).first()

        endpoint = '/api/v3/assignment/{0}/export/{1}'.format(self.assignment.name,
                                                          student.email)
        response = self.client.get(endpoint)
        self.assert_200(response)
        backups = response.json['data']['backups']
        self.assertEqual(len(backups), 1)
        self.assertTrue('submission_time' in backups[0])
        self.assertEqual(backups[0]['submission_time'], backups[0]['created'])
        self.assertEqual(response.json['data']['count'], 1)
        self.assertEqual(response.json['data']['limit'], 150)
        self.assertEqual(response.json['data']['offset'], 0)
        self.assertEqual(response.json['data']['has_more'], False)

        response = self.client.get(endpoint + "?offset=20&limit=2")
        self.assert_200(response)
        backups = response.json['data']['backups']
        self.assertEqual(len(backups), 0)
        self.assertEqual(response.json['data']['count'], 1)
        self.assertEqual(response.json['data']['limit'], 2)
        self.assertEqual(response.json['data']['offset'], 20)
        self.assertEqual(response.json['data']['has_more'], False)
开发者ID:Cal-CS-61A-Staff,项目名称:ok,代码行数:28,代码来源:test_api.py


示例16: test_enroll_from_csv

    def test_enroll_from_csv(self):
        self.setup_course()

        template = "{email},{name},{sid},{class_account},{section}"
        form = BatchEnrollmentForm()
        form.csv.data = template.format(**self.studentA) + "\n" + template.format(**self.studentB)

        Enrollment.enroll_from_csv(self.course.id, form)

        user_a = User.lookup(self.studentA['email'])
        self.studentA['id'] = user_a.id
        self.enrollment_matches_info(user_a, self.studentA)

        user_b = User.lookup(self.studentB['email'])
        self.studentB['id'] = user_b.id
        self.enrollment_matches_info(user_b, self.studentB)
开发者ID:Cal-CS-61A-Staff,项目名称:ok,代码行数:16,代码来源:test_enrollment.py


示例17: routine

        def routine(user: User, board: Board):
            """
            Create new Thread linked to specified board, from POST JSON data.

            :param user:  Requesting User object
            :param board: Board object
            :return: New thread inside specified board
            """
            try:
                # Check thread JSON arguments
                self.check_args()
                self.validate_args()

                # Process anon, image and construct new entity
                anon   = str_to_bool(self.args['anon'])
                image  = self.media_processing()
                thread = Thread(anon, self.args['title'], self.args['text'], image, board.id, user.id)

                # Add new Thread table to database
                uchan.add_to_db(thread)

                # Add new ThreadUser link
                thread = user.get_last_thread()
                uchan.add_to_db(ThreadUser(thread.id, user.id))

                return responses.successful(201, JSONRepresentation.thread(thread, user))
            except ValueError as msg:
                return responses.client_error(400, '{}'.format(msg))
            except KeyError as key:
                return responses.client_error(400, 'Invalid parameter: {}'.format(key))
开发者ID:ar3s3ru,项目名称:uChan3,代码行数:30,代码来源:board.py


示例18: test_assignment_api

    def test_assignment_api(self):
        self._test_backup(True)
        student = User.lookup(self.user1.email)
        endpoint = '/api/v3/assignment/{0}'.format(self.assignment.name)
        # View a public assignment
        response = self.client.get(endpoint)
        self.assert_200(response)
        # Change assignment to be hidden
        self.assignment.visible = False
        db.session.commit()
        response = self.client.get(endpoint)
        self.assert_403(response)

        self.assignment.visible = True
        db.session.commit()

        self.login(self.staff1.email)
        response = self.client.get(endpoint)
        self.assert_200(response)
        self.assertEqual(response.json['data']['name'], self.assignment.name)

        # Hidden assignment, but should be visible to staff
        self.assignment.visible = False
        db.session.commit()
        response = self.client.get(endpoint)
        self.assert_200(response)

        self.login(self.user1.email)
        self.assignment.visible = False
        db.session.commit()
        response = self.client.get(endpoint)
        self.assert_403(response)
开发者ID:Cal-CS-61A-Staff,项目名称:ok,代码行数:32,代码来源:test_api.py


示例19: staff_flag_backup

def staff_flag_backup(cid, email, aid):
    assign = Assignment.query.filter_by(id=aid, course_id=cid).one_or_none()
    if not assign or not Assignment.can(assign, current_user, 'grade'):
        return abort(404)
    result_page = url_for('.student_assignment_detail', cid=cid,
                          email=email, aid=aid)

    student = User.lookup(email)
    if not student:
        abort(404)
    user_ids = assign.active_user_ids(student.id)

    bid = request.form.get('bid')

    form = forms.CSRFForm()
    if form.validate_on_submit():
        backup = Backup.query.filter_by(id=utils.decode_id(bid),
                                        assignment=assign).one_or_none()
        if not backup:
            flash('{} does not exist'.format(bid, 'error'))
            return redirect(result_page)

        if not backup.flagged:
            result = assign.flag(backup.id, user_ids)
            flash('Flagged backup {} for grading'.format(bid), 'success')
        else:
            result = assign.unflag(backup.id, user_ids)
            flash('Removed grading flag on {}'.format(bid), 'success')

    return redirect(result_page)
开发者ID:gratimax,项目名称:ok,代码行数:30,代码来源:admin.py


示例20: board_routine

def board_routine(user: User, func, id: int, *args, **kwargs):
    """
    Basic board routine.
    Serves as a layer of abstraction to treat priority errors in board method resource routines.

    This fuction needs to be passed (and called) by session_oriented_request() (inherited from AuthEntity),
    with subroutine function (that has to be called from within this routine) and an ID (serves as Board ID).

    Function passed to this routine needs this signature:
        >>> def func(user: User, board: Board, *args, **kwargs)

    N.B. *args and **kwargs can be omitted.

    :param user:   User Object (got from session_oriented_request())
    :param func:   Subroutine function (needs to be called from within this routine)
    :param id:     Board ID
    :param args:   Name arguments
    :param kwargs: Positional arguments
    :return:
    """
    # Requesting board object
    board = BoardAPI.get_board(id)

    if board is None:
        # Board does not exists
        return responses.client_error(404, 'Board does not exist')
    elif not user.board_subscribed(id):
        # User not subscribed to this board
        return responses.client_error(401, 'User is not authorized to see this board')

    # Return the result got from closure function passed as argument
    return func(user, board, *args, **kwargs)
开发者ID:ar3s3ru,项目名称:uChan3,代码行数:32,代码来源:board.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python group.Group类代码示例发布时间:2022-05-27
下一篇:
Python manager.get_current_customer_name函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap