當前位置: 首頁>>代碼示例>>Python>>正文


Python User.get方法代碼示例

本文整理匯總了Python中app.users.models.User.get方法的典型用法代碼示例。如果您正苦於以下問題:Python User.get方法的具體用法?Python User.get怎麽用?Python User.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app.users.models.User的用法示例。


在下文中一共展示了User.get方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get

# 需要導入模塊: from app.users.models import User [as 別名]
# 或者: from app.users.models.User import get [as 別名]
 def get(self, id=None):
     if id:
         try:
             user = User.get(id=id)
         except User.DoesNotExist:
             return Response(status=404)
         else:
             return Response(json.dumps(user.serialize), mimetype='application/json')
     else:
         return Response(status=404)
開發者ID:47bytes,項目名稱:flask-big-app,代碼行數:12,代碼來源:views.py

示例2: post

# 需要導入模塊: from app.users.models import User [as 別名]
# 或者: from app.users.models.User import get [as 別名]
    def post(self, id=None):
        if id:
            try:
                User.get(id=id)
                #hier prüfen ob der user den freund schon besitzt oder via app mit /<id>/friends/ ?
            except User.DoesNotExist:
                return Response(status=404)
            else:
                #add new user friend
                resp = request.get_json()
                friend = resp.get('friend')
                accepted = resp.get('accepted') or False
                blocked = resp.get('blocked') or False

                friend = UserFriend.create(
                    user=id,
                    friend=friend,
                    accepted=accepted,
                    blocked=blocked, 
                )
            return Response(json.dumps(friend.serialize), mimetype='application/json')
        else:
            return Response(status=404)
開發者ID:47bytes,項目名稱:flask-big-app,代碼行數:25,代碼來源:views.py

示例3: delete

# 需要導入模塊: from app.users.models import User [as 別名]
# 或者: from app.users.models.User import get [as 別名]
    def delete(self, id=None):
        resp = request.get_json()
        if id:
            try:
                user = User.get(id=id)
            except User.DoesNotExist:
                return Response(status=404)
            else:
                user.activated = resp.get('activated', user.activated)
                user.save()

                return Response(json.dumps(user.serialize), mimetype='application/json')

        else:
            return Response(status=404)
開發者ID:47bytes,項目名稱:flask-big-app,代碼行數:17,代碼來源:views.py

示例4: put

# 需要導入模塊: from app.users.models import User [as 別名]
# 或者: from app.users.models.User import get [as 別名]
    def put(self, id=None):
        resp = request.get_json()
        if id:
            try:
                user = User.get(id=id)
            except User.DoesNotExist:
                return Response(status=404)
            else:
                user.avatar = resp.get('avatar', user.avatar)
                user.email = resp.get('email', user.email)
                user.username = resp.get('username', user.username)
                user.first_name = resp.get('first_name', user.first_name)
                user.last_name = resp.get('last_name', user.last_name)
                user.password = resp.get('password', user.password)
                user.gender = resp.get('gender', user.gender)
                user.save()

                return Response(json.dumps(user.serialize), mimetype='application/json')

        else:
            return Response(status=404)
開發者ID:47bytes,項目名稱:flask-big-app,代碼行數:23,代碼來源:views.py

示例5: test_user_get_function

# 需要導入模塊: from app.users.models import User [as 別名]
# 或者: from app.users.models.User import get [as 別名]
    def test_user_get_function(self):
        test_list = [
            dict(username='flatcoke', password='qwer1235',
                 email='[email protected]', name='TaeminKim', ),
            dict(username='c121213', password='12341234',
                 email='[email protected]', name='Kevin', ),
            dict(username='gogogohaha', password='asdfasdf',
                 email='[email protected]', name='TaeMin', ),
            dict(username='taemin-kim', password='googoo',
                 email='[email protected]', name='Noah', ),
            dict(username='11good', password='1',
                 email='[email protected]', name='flatcoke', ),
        ]
        for i in test_list:
            user = User(i['username'], i['name'], i['email'], i['password'])
            db.session.add(user)
            db.session.commit()

            result = User.get(user.id)
            self.assertIsInstance(result, User)
            self.assertEqual(result.username, i['username'])
            self.assertEqual(result.name, i['name'])
            self.assertNotEqual(result.password, i['password'])
開發者ID:flatcoke,項目名稱:forc,代碼行數:25,代碼來源:mod_auth_test.py


注:本文中的app.users.models.User.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。