當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。