Ejemplo n.º 1
0
    def update_badges(self, id, format='html'):
        instance = get_entity_or_abort(model.Instance, id)
        editable_badges = self._editable_badges(instance)
        badges = self.form_result.get('badge')
        #remove badges
        for badge in instance.badges:
            if badge not in editable_badges:
                # the user can not edit the badge, so we don't remove it
                continue
            if badge not in badges:
                instance.badges.remove(badge)
        #add badges
        for badge in badges:
            if badge not in instance.badges:
                badge.assign(instance, c.user)

        model.meta.Session.commit()
        post_update(instance, model.update.UPDATE)
        if format == 'ajax':
            obj = {
                'html':
                render_def('/badge/tiles.html',
                           'badges',
                           badges=instance.badges)
            }
            return render_json(obj)
Ejemplo n.º 2
0
    def update_badges(self, id):
        user = get_entity_or_abort(model.User, id)
        badges = self.form_result.get('badge')

        if not has('global.admin'):
            # instance admins may only add user badges limited to this instance

            for badge in badges:
                if not badge.instance == c.instance:
                    h.flash(_(u'Invalid badge choice.'), u'error')
                    redirect(h.entity_url(user))

        creator = c.user

        added = []
        removed = []
        for badge in user.badges:
            if badge not in badges:
                removed.append(badge)
                user.badges.remove(badge)

        for badge in badges:
            if badge not in user.badges:
                badge.assign(user, creator)
                added.append(badge)

        model.meta.Session.flush()
        # FIXME: needs commit() cause we do an redirect() which raises
        # an Exception.
        model.meta.Session.commit()
        post_update(user, model.update.UPDATE)
        redirect(h.entity_url(user, instance=c.instance))
Ejemplo n.º 3
0
    def post_update(self, entity, operation):
        '''
        Post an update task for the entity and any related objects.
        '''
        from adhocracy import model
        from adhocracy.lib import queue
        queue.post_update(entity, operation)

        ## Do subsequent updates to reindex related content
        # NOTE: This may post duplicate update tasks if an entity
        # is part of the session, and also updated depending on
        # another entity. Ignored for now cause the real work
        # is asynchronous and (probably) not expensive.
        # NOTE: Move the decisions about which other objects to
        # update to the models
        if isinstance(entity, model.Poll):
            queue.post_update(entity.scope, UPDATE)
Ejemplo n.º 4
0
    def post_update(self, entity, operation):
        '''
        Post an update task for the entity and any related objects.
        '''
        from adhocracy import model
        from adhocracy.lib import queue
        queue.post_update(entity, operation)

        ## Do subsequent updates to reindex related content
        # NOTE: This may post duplicate update tasks if an entity
        # is part of the session, and also updated depending on
        # another entity. Ignored for now cause the real work
        # is asyncronous and (probably) not expensive.
        # NOTE: Move the decisions about which other objects to
        # update to the models
        if isinstance(entity, model.Poll):
            queue.post_update(entity.scope, UPDATE)
Ejemplo n.º 5
0
    def update_badges(self, id):
        user = get_entity_or_abort(model.User, id)
        badges = self.form_result.get('badge')
        creator = c.user

        added = []
        removed = []
        for badge in user.badges:
            if badge not in badges:
                removed.append(badge)
                user.badges.remove(badge)

        for badge in badges:
            if badge not in user.badges:
                model.UserBadge(user, badge, creator)
                added.append(badge)

        model.meta.Session.commit()
        post_update(user, model.update.UPDATE)
        redirect(h.entity_url(user))
Ejemplo n.º 6
0
    def update_badges(self, id):
        user = get_entity_or_abort(model.User, id)
        badges = self.form_result.get('badge')
        creator = c.user

        added = []
        removed = []
        for badge in user.badges:
            if badge not in badges:
                removed.append(badge)
                user.badges.remove(badge)

        for badge in badges:
            if badge not in user.badges:
                model.UserBadge(user, badge, creator)
                added.append(badge)

        model.meta.Session.commit()
        post_update(user, model.update.UPDATE)
        redirect(h.entity_url(user))
Ejemplo n.º 7
0
    def update_badges(self, id, format="html"):
        instance = get_entity_or_abort(model.Instance, id)
        editable_badges = self._editable_badges(instance)
        badges = self.form_result.get("badge")
        # remove badges
        for badge in instance.badges:
            if badge not in editable_badges:
                # the user can not edit the badge, so we don't remove it
                continue
            if badge not in badges:
                instance.badges.remove(badge)
        # add badges
        for badge in badges:
            if badge not in instance.badges:
                badge.assign(instance, c.user)

        model.meta.Session.commit()
        post_update(instance, model.update.UPDATE)
        if format == "ajax":
            obj = {"html": render_def("/badge/tiles.html", "badges", badges=instance.badges)}
            return render_json(obj)
Ejemplo n.º 8
0
    def update_badges(self, id):
        user = get_entity_or_abort(model.User, id)
        badges = self.form_result.get('badge')
        creator = c.user

        added = []
        removed = []
        for badge in user.badges:
            if badge not in badges:
                removed.append(badge)
                user.badges.remove(badge)

        for badge in badges:
            if badge not in user.badges:
                badge.assign(user, creator)
                added.append(badge)

        model.meta.Session.flush()
        # FIXME: needs commit() cause we do an redirect() which raises
        # an Exception.
        model.meta.Session.commit()
        post_update(user, model.update.UPDATE)
        redirect(h.entity_url(user))
Ejemplo n.º 9
0
    def update_badges(self, id):
        user = get_entity_or_abort(model.User, id)
        badges = self.form_result.get('badge')
        creator = c.user

        added = []
        removed = []
        for badge in user.badges:
            if badge not in badges:
                removed.append(badge)
                user.badges.remove(badge)

        for badge in badges:
            if badge not in user.badges:
                badge.assign(user, creator)
                added.append(badge)

        model.meta.Session.flush()
        # FIXME: needs commit() cause we do an redirect() which raises
        # an Exception.
        model.meta.Session.commit()
        post_update(user, model.update.UPDATE)
        redirect(h.entity_url(user))