本文整理汇总了Python中adhocracy.model.Instance.find方法的典型用法代码示例。如果您正苦于以下问题:Python Instance.find方法的具体用法?Python Instance.find怎么用?Python Instance.find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类adhocracy.model.Instance
的用法示例。
在下文中一共展示了Instance.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_all_badgets
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def test_get_all_badgets(self):
#setup
from adhocracy.model import Badge, CategoryBadge, DelegateableBadge, \
InstanceBadge
from adhocracy.model import UserBadge, Instance
instance = Instance.find(u'test')
# create for each type a global scope and an instance scope badge
InstanceBadge.create(u'badge ü', u'#ccc', u'description ü')
InstanceBadge.create(u'badge ü', u'#ccc', u'description ü',
instance=instance)
UserBadge.create(u'badge ü', u'#ccc', u'description ü')
UserBadge.create(u'ü', u'#ccc', u'ü', instance=instance)
DelegateableBadge.create(u'badge ü', u'#ccc', u'description ü')
DelegateableBadge.create(u'badge ü', u'#ccc', u'description ü',
instance=instance)
CategoryBadge.create(u'badge ü', u'#ccc', u"desc")
CategoryBadge.create(u'badge ü', u'#ccc', u"desc", instance=instance)
# all instance badges
self.assert_(len(InstanceBadge.all()) == 1)
self.assert_(len(InstanceBadge.all(instance=instance)) == 1)
# all delegateable badges
self.assert_(len(DelegateableBadge.all()) == 1)
self.assert_(len(DelegateableBadge.all(instance=instance)) == 1)
# all delegateable category badges
self.assert_(len(CategoryBadge.all()) == 1)
self.assert_(len(CategoryBadge.all(instance=instance)) == 1)
# all user badgets
self.assert_(len(UserBadge.all()) == 1)
self.assert_(len(UserBadge.all(instance=instance)) == 1)
# We can get all Badges by using `Badge`
self.assert_(len(Badge.all()) == 4)
self.assert_(len(Badge.all(instance=instance)) == 4)
self.assert_(len(Badge.all_q().all()) == 8)
示例2: valid_instance
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def valid_instance(name):
instance = Instance.find(name)
if instance is None:
print (u"Invalid instance: %s" % name)
sys.exit(1)
else:
return instance
示例3: setUp
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def setUp(self):
super(TestController, self).setUp()
# the test instance is generated by setup-app
instance = Instance.find('test')
assert instance, "We need an instance to setup the context"
_register_tmpl_context(instance, user=None)
_register_request(**self.request)
示例4: _to_python
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def _to_python(self, value, state):
from adhocracy.model import Instance
if can.badge.manage_global() or can.badge.edit_global():
if value:
instance = Instance.find(value)
if instance is None:
raise AssertionError("Could not find instance %s" % value)
return instance
return None
elif can.badge.manage_instance() or can.badge.edit_instance():
instance = Instance.find(value)
if instance is not None and instance == c.instance:
return instance
raise formencode.Invalid(
_("You're not allowed to edit global badges"),
value, state)
示例5: _make_one
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def _make_one(title, text, creator=None, time=None):
from adhocracy.model import Instance, Milestone
if creator is None:
creator = tt_make_user()
instance = Instance.find('test')
now = datetime.now()
milestone = Milestone.create(instance, creator, title, text, now)
return (milestone, creator)
示例6: test_create_milestone
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def test_create_milestone(self):
from adhocracy.model import Instance, Milestone
now = datetime.now()
creator = tt_make_user()
instance = Instance.find('test')
milestone = Milestone.create(instance, creator, u'Titleü', u'Textü',
now)
self.assertEqual(milestone.instance, instance)
self.assertEqual(milestone.creator, creator)
self.assertEqual(len(Milestone.all()), 1)
示例7: _make_content
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def _make_content(self):
"""Returns creator, delegateable and badge"""
from adhocracy.model import DelegateableBadge, Proposal, Instance
instance = Instance.find('test')
creator = tt_make_user('creator')
delegateable = Proposal.create(instance, u"labeld", creator)
badge = DelegateableBadge.create(u'testbadge', u'#ccc', 'description')
return creator, delegateable, badge
示例8: _make_content
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def _make_content(self):
"""Returns creator, delegateable and badge"""
from adhocracy.model import Badge, Proposal, Instance
instance = Instance.find("test")
creator = tt_make_user("creator")
delegateable = Proposal.create(instance, u"labeld", creator)
badge = Badge.create(u"testbadge", u"#ccc", "description")
return creator, delegateable, badge
示例9: post_login_url
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def post_login_url(user):
from adhocracy.lib.helpers import base_url
url = config.get('adhocracy.post_login_url')
if url is None:
return base_url('/user/%s/dashboard' % user.user_name)
instance = config.get('adhocracy.post_login_instance')
if instance is None:
return base_url(url)
else:
return base_url(url, Instance.find(instance))
示例10: post_logout_url
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def post_logout_url():
from adhocracy.lib.helpers import base_url
url = config.get('adhocracy.post_logout_url')
if url is None:
return base_url()
instance = config.get('adhocracy.post_logout_instance')
if instance is None:
return base_url(url)
else:
return base_url(url, Instance.find(instance))
示例11: _make_content
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def _make_content(self):
"""Returns creator, delegateable and badge"""
from adhocracy.model import ThumbnailBadge, Proposal, Instance
instance = Instance.find(u'test')
creator = tt_make_user(u'creator')
delegateable = Proposal.create(instance, u"labeld", creator)
thumbnail = b'binary'
badge = ThumbnailBadge.create(u'testbadge', u'#ccc', True,
u'description', thumbnail=thumbnail)
return creator, delegateable, badge
示例12: test_to_dict
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def test_to_dict(self):
from adhocracy.model import CategoryBadge, Instance
instance = Instance.find('test')
badge = CategoryBadge.create(u'badge', u'#ccc', u'description',
instance=instance)
result = badge.to_dict()
result = sorted(result.items())
expected = {'title': u'badge',
'color': u'#ccc',
'description': u'description',
'id': 1,
'instance': instance.id}
expected = sorted(expected.items())
self.assertEqual(result, expected)
示例13: _to_python
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def _to_python(self, value, state):
from adhocracy.model import Instance
if has('global.admin'):
if value:
instance = Instance.find(value)
if instance is None:
raise AssertionError("Could not find instance %s" % value)
return instance
return None
elif has('instance.admin') and c.instance:
return c.instance
raise formencode.Invalid(
_("You're not allowed to edit global badges"),
value, state)
示例14: test_members
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def test_members(self):
from adhocracy.model import Instance, Group
test_instance = Instance.find('test')
members = test_instance.members()
self.assertEqual(len(members), 1)
self.assertEqual(members[0].user_name, u'admin')
voters = Group.find(u'Voter')
tt_make_user(u'second', voters)
members = test_instance.members()
self.assertEqual(len(members), 2)
self.assertEqual(sorted([member.user_name for member in
test_instance.members()]),
['admin', 'second'])
示例15: get_instances
# 需要导入模块: from adhocracy.model import Instance [as 别名]
# 或者: from adhocracy.model.Instance import find [as 别名]
def get_instances(args):
'''
Flatten out the instances parsed by a parser from create_parser
used with `use_instance=True`
'''
if args.instances:
keys = [item for sublist in args.instances for item in
sublist]
instances = []
for key in keys:
obj = Instance.find(key)
if obj is None:
raise ValueError("Instance '%s' does not exist" % key)
instances.append(obj)
return instances
return None