本文整理汇总了Python中cuser.middleware.CuserMiddleware.set_user方法的典型用法代码示例。如果您正苦于以下问题:Python CuserMiddleware.set_user方法的具体用法?Python CuserMiddleware.set_user怎么用?Python CuserMiddleware.set_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cuser.middleware.CuserMiddleware
的用法示例。
在下文中一共展示了CuserMiddleware.set_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_current_user_field
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import set_user [as 别名]
def test_current_user_field(self):
user = User.objects.get(username="test")
CuserMiddleware.set_user(user)
TestModel.objects.create(name="TEST")
CuserMiddleware.del_user()
test_instance = TestModel.objects.get(name="TEST")
self.assertEqual(test_instance.creator, user)
示例2: setUpTestData
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import set_user [as 别名]
def setUpTestData(cls):
cls.user = User.objects.create_user(
username="Toto", email="", password="secret"
)
cls.user_repr = repr(cls.user)
CuserMiddleware.set_user(cls.user)
cls.pet = Pet.objects.create(name="Catz", age=12)
cls.human = Human.objects.create(name="George", age=42, height=175)
cls.human_repr = repr(cls.human)
示例3: setUp
# 需要导入模块: from cuser.middleware import CuserMiddleware [as 别名]
# 或者: from cuser.middleware.CuserMiddleware import set_user [as 别名]
def setUp(self):
self.user = User.objects.create_user(
username="Toto", email="", password="secret"
)
self.user_repr = repr(self.user)
CuserMiddleware.set_user(self.user)
self.pet = Pet.objects.create(name="Catz", age=12)
self.pet2 = Pet.objects.create(name="Catzou", age=1)
self.human = Human.objects.create(name="George", age=42, height=175)
self.human.pets.add(self.pet)
self.human_repr = repr(self.human)