本文整理汇总了Python中adhocracy.model.Instance类的典型用法代码示例。如果您正苦于以下问题:Python Instance类的具体用法?Python Instance怎么用?Python Instance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Instance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_all_badgets
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
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
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
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
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: _make_content
def _make_content(self):
"""Returns creator, delegateable and badge"""
from adhocracy.model import InstanceBadge, Instance
creator = tt_make_user('creator')
instance = Instance.create("instance2", u"instance2", creator)
badge = InstanceBadge.create(u'testbadge', u'#ccc2', 'description')
return creator, instance, badge
示例7: test_create_milestone
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)
示例8: _make_content
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
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
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
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: get_allowed_instances
def get_allowed_instances(cls, user):
"""
returns all instances in which the given user has permission to send a
message to all users
"""
if has('global.message'):
return Instance.all()
else:
return [m.instance for m in user.memberships
if (m.instance is not None
and m.instance.is_authenticated
and 'instance.message' in m.group.permissions)]
示例13: _get_allowed_instances
def _get_allowed_instances(cls, user):
"""
returns all instances in which the given user has permission to send a
message to all users
"""
if has('global.message'):
return Instance.all()
else:
perm = Permission.find('instance.message')
instances = [m.instance for m in user.memberships
if (m.instance is not None
and m.instance.is_authenticated
and perm in m.group.permissions)]
return sorted(instances, key=lambda i: i.label)
示例14: test_to_dict
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)
示例15: _to_python
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)