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


Python model.Instance类代码示例

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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