Exemple #1
0
 def _available_badges(self):
     '''
     Return the badges that are editable by a user.
     '''
     c.groups = [{'permission': 'global.admin',
                  'label': _('In all instances'),
                  'show_label': True}]
     if c.instance:
         c.groups.append(
             {'permission': 'instance.admin',
              'label': _('In instance "%s"') % c.instance.label,
              'show_label': h.has_permission('global.admin')})
     badges = {}
     if has('global.admin'):
         badges['global.admin'] = {
             'instance': InstanceBadge.all(instance=None),
             'user': UserBadge.all(instance=None),
             'delegateable': DelegateableBadge.all(instance=None),
             'category': CategoryBadge.all(instance=None),
             'thumbnail': ThumbnailBadge.all(instance=None)}
     if has('instance.admin') and c.instance is not None:
         badges['instance.admin'] = {
             'instance': InstanceBadge.all(instance=c.instance),
             'user': UserBadge.all(instance=c.instance),
             'delegateable': DelegateableBadge.all(instance=c.instance),
             'category': CategoryBadge.all(instance=c.instance),
             'thumbnail': ThumbnailBadge.all(instance=c.instance)}
     return badges
Exemple #2
0
 def create_instance_badge(self):
     try:
         self.form_result = BadgeForm().to_python(request.params)
     except Invalid as i:
         return self.add('instance', i.unpack_errors())
     title, color, visible, description, impact, instance =\
         self._get_common_fields(self.form_result)
     InstanceBadge.create(title, color, visible, description, impact,
                          instance)
     # commit cause redirect() raises an exception
     meta.Session.commit()
     redirect(self.base_url)
Exemple #3
0
    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
Exemple #4
0
    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
Exemple #5
0
 def _to_python(self, value, state):
     from adhocracy.model import InstanceBadge
     try:
         value = int(value)
     except:
         pass
     badge = InstanceBadge.by_id(value, instance_filter=False)
     if badge is None or badge.instance not in [None, c.instance]:
         raise formencode.Invalid(
             _("No Badge ID '%s' exists") % value, value, state)
     return badge
Exemple #6
0
 def _to_python(self, value, state):
     from adhocracy.model import InstanceBadge
     try:
         value = int(value)
     except:
         pass
     badge = InstanceBadge.by_id(value, instance_filter=False)
     if badge is None or badge.instance not in [None, c.instance]:
         raise formencode.Invalid(
             _("No Badge ID '%s' exists") % value,
             value, state)
     return badge
Exemple #7
0
    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)
Exemple #8
0
    def test_get_all_badges(self):
        # setup
        from adhocracy.model import Badge, CategoryBadge, DelegateableBadge, \
            InstanceBadge, ThumbnailBadge
        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', True, u'description ü')
        InstanceBadge.create(u'badge ü', u'#ccc', True, u'description ü',
                             instance=instance)
        UserBadge.create(u'badge ü', u'#ccc', True, u'description ü')
        UserBadge.create(u'ü', u'#ccc', True, u'ü', instance=instance)
        DelegateableBadge.create(u'badge ü', u'#ccc', True, u'description ü')
        DelegateableBadge.create(u'badge ü', u'#ccc', True, u'description ü',
                                 instance=instance)
        CategoryBadge.create(u'badge ü', u'#ccc', True, u"desc")
        CategoryBadge.create(u'badge ü', u'#ccc', True, u"desc",
                             instance=instance)

        ThumbnailBadge.create(u'badge ü', u'#ccc', True, u"desc",
                              thumbnail=b'binary')
        ThumbnailBadge.create(u'badge ü', u'#ccc', True, u"desc",
                              thumbnail=b'binary', instance=instance)

        # all instance badges
        self.assertEqual(len(InstanceBadge.all()), 1)
        self.assertEqual(len(InstanceBadge.all(instance=instance)), 1)
        # all delegateable badges
        self.assertEqual(len(DelegateableBadge.all()), 1)
        self.assertEqual(len(DelegateableBadge.all(instance=instance)), 1)
        # all delegateable category badges
        self.assertEqual(len(CategoryBadge.all()), 1)
        self.assertEqual(len(CategoryBadge.all(instance=instance)), 1)
        # all delegateable thumbnail badges
        self.assertEqual(len(ThumbnailBadge.all()), 1)
        self.assertEqual(len(ThumbnailBadge.all(instance=instance)), 1)
        # all user badges
        self.assertEqual(len(UserBadge.all()), 3)
        self.assertEqual(len(UserBadge.all(instance=instance)), 1)
        # We can get all Badges by using `Badge`
        self.assertEqual(len(Badge.all()), 7)
        self.assertEqual(len(Badge.all(instance=instance)), 5)

        self.assertEqual(len(Badge.all_q().all()), 12)
Exemple #9
0
    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)