本文整理汇总了Python中user.User.get_renderer方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_renderer方法的具体用法?Python User.get_renderer怎么用?Python User.get_renderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.User
的用法示例。
在下文中一共展示了User.get_renderer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bind_custom
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_renderer [as 别名]
def test_bind_custom(self):
Dashboard.add_dashboard([User])
from mf.renderer import TextRenderer
from user import CustomStatus
assert isinstance(User.get_renderer("custom"), TextRenderer) == True
request = [("User[custom]", "one")]
user = User()
user.bind_form(request)
print "custom= " + str(user)
assert user["custom"] == CustomStatus.unserialize("one")
示例2: test_bind_multi_array3
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_renderer [as 别名]
def test_bind_multi_array3(self):
Dashboard.add_dashboard([User])
group = connection.Group()
group["name"] = "sampleGroup"
group["creation_date"] = datetime.utcnow()
group.save()
request = [("User[multi2][0][group]", str(group["_id"])), ("User[multi2][0][role]", "role1")]
renderer = User.get_renderer("multi2.group")
renderer.set_reference(Group)
user = User()
user.bind_form(sorted(request))
assert len(user["multi2"]) == 1
assert user["multi2"][0]["role"] == "role1"
assert user["multi2"][0]["group"] == group["_id"]
示例3: test_objectdbref
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_renderer [as 别名]
def test_objectdbref(self):
Dashboard.add_dashboard([User])
group = connection.Group()
group["name"] = "sampleGroup"
group["creation_date"] = datetime.utcnow()
group.save()
request = [("User[groups][0]", str(group["_id"]))]
user = connection.User()
user["name"] = "sampleUser"
user["email"] = "[email protected]"
user["groupRef"] = group["_id"]
renderer = User.get_renderer("groupRef")
assert renderer.is_object_id == True
renderer.set_reference(Group)
user.save()
assert group["_id"] == user["groupRef"]
assert isinstance(user["groupRef"], ObjectId)
示例4: test_bind_multi_array4
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_renderer [as 别名]
def test_bind_multi_array4(self):
Dashboard.add_dashboard([User])
group = connection.Group()
group["name"] = "sampleGroup"
group["creation_date"] = datetime.utcnow()
group.save()
request = [("User[multi2][0][group]", str(group["_id"])), ("User[multi2][0][role]", "role1")]
renderer = SimpleReferenceRenderer(User, "group", Group, "multi2")
renderer.is_object_id = True
# renderer = User.get_renderer("multi2.group")
# renderer.set_reference(Group)
user = User()
user.bind_form(sorted(request))
print str(User.get_renderer("multi2.group").__class__.__name__)
assert len(user["multi2"]) == 1
assert user["multi2"][0]["role"] == "role1"
assert user["multi2"][0]["group"] == group["_id"]
示例5: objectId_adapter
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_renderer [as 别名]
#u2 = {"name": "Tommy", "admin" : True, "age" : 40, "email" : "nomail", "creation_date" : datetime.utcnow(), "options" : { 'tags': 'cool' , 'categories': '' }, "array" : [ 'three', 'four'] }
#db.users.insert(u2)
#u3 = {"name": "Mike", "admin" : True, "age" : 50, "email" : "dummy", "creation_date" : datetime.utcnow(), "options" : { 'tags': 'cool' , 'categories': 'any' }, "array" : [ 'three', 'four'] }
#db.users.insert(u3)
#g1 = {"name": "sample", "creation_date" : datetime.utcnow() }
#db.groups.insert(g1)
Dashboard.set_connection(connection)
Dashboard.add_dashboard([User, Group, SuperGroup],config,'/test')
renderer = mf.renderer.TextChoiceRenderer(User,'email','')
renderer.limit([ 'nomail', '[email protected]', '[email protected]' ])
renderer.add_extra_control('<button class="btn btn-info">Fake button</button>')
renderer = User.get_renderer('groupRef')
renderer.set_reference(Group)
groupid_renderer = mf.renderer.SimpleReferenceRenderer(User,'groupid',Group)
# automatically serialize bson ObjectId to Mongo extended JSON
json_renderer = JSON()
def objectId_adapter(obj, request):
return json_util.default(obj)
def datetime_adapter(obj, request):
return json_util.default(obj)
json_renderer.add_adapter(ObjectId, objectId_adapter)
json_renderer.add_adapter(datetime, datetime_adapter)
config.add_renderer('json', json_renderer)