当前位置: 首页>>代码示例>>Python>>正文


Python Instance.find方法代码示例

本文整理汇总了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)
开发者ID:JonnyWalker,项目名称:adhocracy,代码行数:37,代码来源:test_badges.py

示例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
开发者ID:alkadis,项目名称:vcv,代码行数:9,代码来源:invite.py

示例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)
开发者ID:JonnyWalker,项目名称:adhocracy,代码行数:9,代码来源:__init__.py

示例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)
开发者ID:alkadis,项目名称:vcv,代码行数:18,代码来源:common.py

示例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)
开发者ID:whausen,项目名称:part,代码行数:10,代码来源:test_milestones.py

示例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)
开发者ID:whausen,项目名称:part,代码行数:12,代码来源:test_milestones.py

示例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
开发者ID:JonnyWalker,项目名称:adhocracy,代码行数:12,代码来源:test_badges.py

示例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
开发者ID:AnonOnWarpath,项目名称:adhocracy,代码行数:13,代码来源:test_badges.py

示例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))
开发者ID:dwt,项目名称:adhocracy,代码行数:13,代码来源:user_helper.py

示例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))
开发者ID:alkadis,项目名称:vcv,代码行数:13,代码来源:user_helper.py

示例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
开发者ID:alkadis,项目名称:vcv,代码行数:14,代码来源:test_badges.py

示例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)
开发者ID:JonnyWalker,项目名称:adhocracy,代码行数:16,代码来源:test_badges.py

示例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)
开发者ID:whausen,项目名称:part,代码行数:16,代码来源:common.py

示例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'])
开发者ID:AnonOnWarpath,项目名称:adhocracy,代码行数:17,代码来源:test_instances.py

示例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
开发者ID:JonnyWalker,项目名称:adhocracy,代码行数:18,代码来源:common.py


注:本文中的adhocracy.model.Instance.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。