예제 #1
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)
예제 #2
0
 def _to_python(self, value, state):
     from adhocracy.model import Badge
     badge = Badge.by_id(value)
     if not badge:
         raise formencode.Invalid(
             _("No Badge ID '%s' exists") % value, value, state)
     return badge
예제 #3
0
 def _to_python(self, value, state):
     from adhocracy.model import Badge
     badge = Badge.by_id(value)
     if not badge:
         raise formencode.Invalid(
             _("No Badge ID '%s' exists") % value,
             value, state)
     return badge
예제 #4
0
def badge_styles():
    '''
    Render a <style>-block with dyamic badge styles
    '''
    from adhocracy.lib.templating import render_def
    from adhocracy.model import Badge
    badges = Badge.all_q().all()
    return render_def('/badge/tiles.html', 'badge_styles', badges=badges,
                      cached=True)
예제 #5
0
파일: badge_tiles.py 프로젝트: alkadis/vcv
def badge_styles(instance):
    '''
    Render a <style>-block with dyamic badge styles
    '''
    from adhocracy.lib.templating import render_def
    from adhocracy.model import Badge
    badges = Badge.all(instance=instance, include_global=True)
    return render_def('/badge/tiles.html', 'badge_styles', badges=badges,
                      cached=True)
예제 #6
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)
예제 #7
0
    def test_valid_badge(self):
        from adhocracy.forms import ValidBadge
        from adhocracy.model import Badge, UserBadge

        creator = tt_make_user('creator')
        badged_user = tt_make_user('badged_user')
        badge = Badge.create('testbadge', '#ccc', 'description')
        UserBadge.create(badged_user, badge, creator)
        value = ValidBadge.to_python(badge.id, None)
        self.assertEqual(value, badge)
예제 #8
0
 def test_add_badge(self):
     from adhocracy.model import Badge
     #add badge
     badge = Badge.create(u'badge ü', u'#ccc', u'description ü')
     self.assert_(str(badge) == '<Badge(1,badge ?)>')
     #We can set a flag if this badge should be uses with users (default)
     #or with delegateables
     self.assert_(badge.badge_delegateable == False)
     badge.badge_delegateable = True
     self.assert_(badge.badge_delegateable == True)
예제 #9
0
    def _make_one(self):
        """Returns creator, badged user and badge"""

        from adhocracy.model import Badge, UserBadge
        creator = tt_make_user('creator')
        badged_user = tt_make_user('badged_user')
        badge = Badge.create(u'testbadge', u'#ccc', u'description')
        UserBadge.create(badged_user, badge, creator)

        return creator, badged_user, badge
예제 #10
0
    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
예제 #11
0
 def index(self, format='html'):
     #require.user.manage()
     badges = Badge.all()
     if format == 'json':
         return render_json([badge.to_dict() for badge in badges])
     badges_users = filter(lambda x: not x.badge_delegateable, badges)
     c.badges_users = sorted(badges_users, key=attrgetter('title'))
     badges_delegateables = filter(lambda x: x.badge_delegateable, badges)
     c.badges_delegateables = sorted(badges_delegateables, key=attrgetter('title'))
     return render("/badge/index.html")
예제 #12
0
    def test_valid_badge(self):
        from adhocracy.forms import ValidBadge
        from adhocracy.model import Badge, UserBadge

        creator = tt_make_user('creator')
        badged_user = tt_make_user('badged_user')
        badge = Badge.create('testbadge', '#ccc', 'description')
        UserBadge.create(badged_user, badge, creator)
        value = ValidBadge.to_python(badge.id, None)
        self.assertEqual(value, badge)
예제 #13
0
 def create(self):
     title = self.form_result.get('title').strip()
     description = self.form_result.get('description').strip()
     color = self.form_result.get('color').strip()
     group = self.form_result.get('group')
     display_group = self.form_result.get('display_group')
     badge_delegateable = bool(self.form_result.get('badge_delegateable'))
     badge = Badge.create(title, color, description, group, display_group, badge_delegateable)
     meta.Session.add(badge)
     meta.Session.commit()
     redirect(self.base_url)
예제 #14
0
    def test_add_badge(self):
        from adhocracy.model import Badge

        # add badge
        badge = Badge.create(u"badge ü", u"#ccc", u"description ü")
        self.assert_(str(badge) == "<Badge(1,badge ?)>")
        # We can set a flag if this badge should be uses with users (default)
        # or with delegateables
        self.assert_(badge.badge_delegateable == False)
        badge.badge_delegateable = True
        self.assert_(badge.badge_delegateable == True)
예제 #15
0
    def test_invalid_badge(self):
        from formencode import Invalid
        from adhocracy.forms import ValidBadge
        from adhocracy.model import Badge, UserBadge

        creator = tt_make_user('creator')
        badged_user = tt_make_user('badged_user')
        badge = Badge.create('testbadge', '#ccc', 'description')
        UserBadge.create(badged_user, badge, creator)
        self.assertRaises(Invalid, ValidBadge.to_python,
                          badge.id + 1, state=None)
예제 #16
0
    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
예제 #17
0
 def index(self, format='html'):
     #require.user.manage()
     badges = Badge.all()
     if format == 'json':
         return render_json([badge.to_dict() for badge in badges])
     badges_users = filter(lambda x: not x.badge_delegateable, badges)
     c.badges_users = sorted(badges_users, key=attrgetter('title'))
     badges_delegateables = filter(lambda x: x.badge_delegateable, badges)
     c.badges_delegateables = sorted(badges_delegateables,
                                     key=attrgetter('title'))
     return render("/badge/index.html")
예제 #18
0
    def _make_one(self):
        """Returns creator, badged user and badge"""

        from adhocracy.model import Badge, UserBadge

        creator = tt_make_user("creator")
        badged_user = tt_make_user("badged_user")
        badge = Badge.create(u"testbadge", u"#ccc", u"description")
        UserBadge.create(badged_user, badge, creator)

        return creator, badged_user, badge
예제 #19
0
def badge_styles(instance):
    '''
    Render a <style>-block with dyamic badge styles
    '''
    from adhocracy.lib.templating import render_def
    from adhocracy.model import Badge
    badges = Badge.all(instance=instance, include_global=True)
    return render_def('/badge/tiles.html',
                      'badge_styles',
                      badges=badges,
                      cached=True)
예제 #20
0
 def _get_badge_or_redirect(self, id):
     '''
     Get a badge. Redirect if it does not exist. Redirect if
     the badge is not from the current instance, but the user is
     only an instance admin, not a global admin
     '''
     badge = Badge.by_id(id, instance_filter=False)
     if badge is None:
         self._redirect_not_found(id)
     if badge.instance != c.instance and not has('global.admin'):
         self._redirect_not_found(id)
     return badge
예제 #21
0
 def create(self):
     title = self.form_result.get('title').strip()
     description = self.form_result.get('description').strip()
     color = self.form_result.get('color').strip()
     group = self.form_result.get('group')
     display_group = self.form_result.get('display_group')
     badge_delegateable = bool(self.form_result.get('badge_delegateable'))
     badge = Badge.create(title, color, description, group, display_group,
                          badge_delegateable)
     meta.Session.add(badge)
     meta.Session.commit()
     redirect(self.base_url)
예제 #22
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)
예제 #23
0
    def test_invalid_badge(self):
        from formencode import Invalid
        from adhocracy.forms import ValidBadge
        from adhocracy.model import Badge, UserBadge

        creator = tt_make_user('creator')
        badged_user = tt_make_user('badged_user')
        badge = Badge.create('testbadge', '#ccc', 'description')
        UserBadge.create(badged_user, badge, creator)
        self.assertRaises(Invalid,
                          ValidBadge.to_python,
                          badge.id + 1,
                          state=None)
예제 #24
0
 def test_to_dict(self):
     from adhocracy.model import Badge
     badge = Badge.create(u'badge', u'#ccc', u'description')
     result = badge.to_dict()
     self.assertEqual(
         result, {
             'color': u'#ccc',
             'title': u'badge',
             'id': 1,
             'users': [],
             'display_group': False,
             'group': None,
             'badge_delegateable': False
         })
예제 #25
0
    def test_to_dict(self):
        from adhocracy.model import Badge

        badge = Badge.create(u"badge", u"#ccc", u"description")
        result = badge.to_dict()
        self.assertEqual(
            result,
            {
                "color": u"#ccc",
                "title": u"badge",
                "id": 1,
                "users": [],
                "display_group": False,
                "group": None,
                "badge_delegateable": False,
            },
        )
예제 #26
0
 def edit(self, id, errors=None):
     c.form_title = c.save_button = _("Edit Badge")
     c.action_url = self.base_url + '/edit/%s' % id
     c.groups = meta.Session.query(Group).order_by(Group.group_name).all()
     badge = Badge.by_id(id)
     if badge is None:
         self._redirect_not_found(id)
     group_default = badge.group and badge.group.code or ''
     defaults = dict(title=badge.title,
                     description=badge.description,
                     color=badge.color,
                     group=group_default,
                     display_group=badge.display_group,
                     badge_delegateable=badge.badge_delegateable, 
                     )
     
     return htmlfill.render(render("/badge/form.html"),
                            errors=errors,
                            defaults=defaults)
예제 #27
0
    def edit(self, id, errors=None):
        c.form_title = c.save_button = _("Edit Badge")
        c.action_url = self.base_url + '/edit/%s' % id
        c.groups = meta.Session.query(Group).order_by(Group.group_name).all()
        badge = Badge.by_id(id)
        if badge is None:
            self._redirect_not_found(id)
        group_default = badge.group and badge.group.code or ''
        defaults = dict(
            title=badge.title,
            description=badge.description,
            color=badge.color,
            group=group_default,
            display_group=badge.display_group,
            badge_delegateable=badge.badge_delegateable,
        )

        return htmlfill.render(render("/badge/form.html"),
                               errors=errors,
                               defaults=defaults)
예제 #28
0
    def update(self, id):
        badge = Badge.by_id(id)
        if badge is None:
            self._redirect_not_found(id)

        title = self.form_result.get('title').strip()
        description = self.form_result.get('description').strip()
        color = self.form_result.get('color').strip()
        group = self.form_result.get('group')
        display_group = self.form_result.get('display_group')

        if group:
            badge.group = group
        else:
            badge.group = None
        badge.title = title
        badge.color = color
        badge.description = description
        badge.display_group = display_group
        meta.Session.commit()
        h.flash(_("Badge changed successfully"), 'success')
        redirect(self.base_url)
예제 #29
0
    def update(self, id):
        badge = Badge.by_id(id)
        if badge is None:
            self._redirect_not_found(id)

        title = self.form_result.get('title').strip()
        description = self.form_result.get('description').strip()
        color = self.form_result.get('color').strip()
        group = self.form_result.get('group')
        display_group = self.form_result.get('display_group')

        if group:
            badge.group = group
        else:
            badge.group = None
        badge.title = title
        badge.color = color
        badge.description = description
        badge.display_group = display_group
        meta.Session.commit()
        h.flash(_("Badge changed successfully"), 'success')
        redirect(self.base_url)