Ejemplo n.º 1
0
def badge(badge, force_visible=False):
    from adhocracy.lib.templating import render_def
    return render_def('/badge/tiles.html',
                      'badge',
                      badge=badge,
                      force_visible=force_visible,
                      cached=True)
Ejemplo n.º 2
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.º 3
0
    def votes(self, id, format='html'):
        c.poll = get_entity_or_abort(model.Poll, id)

        # cover over data inconsistency because of a bug where pages (norms)
        # were deleted when a proposal was deleted.
        # Fixes http://trac.adhocracy.de/ticket/262
        if (c.poll.action == model.Poll.SELECT and
                c.poll.selection is None):
            logmsg = ('Poll: "%s" is a model.Poll.rate poll, which should '
                      'have a selection, but the selection is None. Subject '
                      'of the Poll is %s') % (c.poll, c.poll.subject)
            log.error(logmsg)
            raise abort(404)

        require.poll.show(c.poll)
        decisions = democracy.Decision.for_poll(c.poll)
        if (hasattr(self, 'form_result') and
                self.form_result.get('result') is not None):
            result_form = self.form_result.get('result')
            decisions = filter(lambda d: d.result == result_form, decisions)
        c.decisions_pager = pager.scope_decisions(decisions)

        if format == 'json':
            return render_json(c.decisions_pager)
        elif format == 'ajax':
            return render_def('/pager.html', 'overlay_pager',
                              pager=c.decisions_pager,
                              render_facets=False)
        elif format == 'overlay':
            return render("/poll/votes.html", overlay=True)
        else:
            return render("/poll/votes.html")
Ejemplo n.º 4
0
    def all(self, format='html'):
        events = model.Event.all_q(
            include_hidden=False,
            event_filter=request.params.getall('event_filter'))\
            .order_by(model.Event.time.desc())\
            .limit(min(int(request.params.get('count', 50)), 100)).all()

        if format == 'rss':
            return event.rss_feed(events,
                                  _('%s News' % h.site.name()),
                                  h.base_url(instance=None),
                                  _("News from %s") % h.site.name())

        elif format == 'ajax':
            query_params = request.params.copy()
            while True:
                try:
                    query_params.pop('count')
                except KeyError:
                    break

            more_url = h.base_url(instance=None,
                                  member='event/all',
                                  query_params=query_params)
            return render_def('/event/tiles.html', 'carousel',
                              events=events, more_url=more_url)
        else:
            c.event_pager = pager.events(events, count=50)

            if format == 'overlay':
                return render('/event/all.html', overlay=True,
                              overlay_size=OVERLAY_SMALL)
            else:
                return render('/event/all.html')
Ejemplo n.º 5
0
Archivo: poll.py Proyecto: whausen/part
    def votes(self, id, format='html'):
        c.poll = get_entity_or_abort(model.Poll, id)

        # cover over data inconsistency because of a bug where pages (norms)
        # where deleted when a proposal was deleted.
        # Fixes http://trac.adhocracy.de/ticket/262
        if (c.poll.action == model.Poll.SELECT and
                c.poll.selection is None):
            logmsg = ('Poll: "%s" is a model.Poll.rate poll, which should '
                      'have a selection, but the selection is None. Subject '
                      'of the Poll is %s') % (c.poll, c.poll.subject)
            log.error(logmsg)
            raise abort(404)

        require.poll.show(c.poll)
        decisions = democracy.Decision.for_poll(c.poll)
        if (hasattr(self, 'form_result') and
                self.form_result.get('result') != None):
            result_form = self.form_result.get('result')
            decisions = filter(lambda d: d.result == result_form, decisions)
        c.decisions_pager = pager.scope_decisions(decisions)

        if format == 'overlay':
            return render_def('/pager.html', 'overlay_pager',
                              pager=c.decisions_pager,
                              render_facets=False)

        if format == 'json':
            return render_json(c.decisions_pager)

        return render("/poll/votes.html")
Ejemplo n.º 6
0
Archivo: event.py Proyecto: alkadis/vcv
    def all(self, format="html"):
        if c.instance is None:
            require.perm("event.index_all")

        events = (
            model.Event.all_q(
                instance=c.instance, include_hidden=False, event_filter=request.params.getall("event_filter")
            )
            .order_by(model.Event.time.desc())
            .limit(min(int(request.params.get("count", 50)), 100))
            .all()
        )

        if format == "rss":
            return event.rss_feed(
                events, _("%s News" % h.site.name()), h.base_url(instance=None), _("News from %s") % h.site.name()
            )

        elif format == "ajax":
            query_params = request.params.copy()
            while True:
                try:
                    query_params.pop("count")
                except KeyError:
                    break

            more_url = h.base_url(instance=c.instance, member="event/all", query_params=query_params)
            return render_def("/event/tiles.html", "carousel", events=events, more_url=more_url)
        else:
            c.event_pager = pager.events(events, count=50)

            if format == "overlay":
                return render("/event/all.html", overlay=True, overlay_size=OVERLAY_SMALL)
            else:
                return render("/event/all.html")
Ejemplo n.º 7
0
    def render_navigation_item(item, path='', toplevel=False):
        from adhocracy.lib.templating import render_def

        if path != '':
            path = '%s/%s' % (path, item['name'])
        else:
            path = item['name']

        url = '/static/%s.html' % path

        contains_current = (path == current_key)
        if item['children']:
            children, contained_list = izip(
                *map(lambda child: render_navigation_item(child, path),
                     item['children']))
            contains_current = contains_current or any(contained_list)
        else:
            children = []

        html = render_def('static/tiles.html', 'navigation_item',
                          href=url,
                          title=item['title'],
                          current=toplevel and contains_current,
                          children=children)

        return (html, contains_current)
Ejemplo n.º 8
0
 def edit(self, id, format='html'):
     c.comment = get_entity_or_abort(model.Comment, id)
     require.comment.edit(c.comment)
     if format == 'ajax':
         return render_def('/comment/tiles.html', 'edit_form',
                           {'comment': c.comment})
     return render('/comment/edit.html')
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
 def edit(self, id, format='html'):
     c.comment = get_entity_or_abort(model.Comment, id)
     require.comment.edit(c.comment)
     extra_vars = {'comment': c.comment}
     if c.came_from != u'':
         extra_vars[u'came_from'] = c.came_from
     if format == 'ajax':
         return render_def('/comment/tiles.html', 'edit_form',
                           extra_vars=extra_vars)
     elif format == 'overlay':
         return render('/comment/edit.html', overlay=True)
     else:
         return render('/comment/edit.html')
Ejemplo n.º 13
0
 def edit(self, id, format='html'):
     c.comment = get_entity_or_abort(model.Comment, id)
     require.comment.edit(c.comment)
     extra_vars = {'comment': c.comment}
     if c.came_from != u'':
         extra_vars[u'came_from'] = c.came_from
     if format == 'ajax':
         return render_def('/comment/tiles.html',
                           'edit_form',
                           extra_vars=extra_vars)
     elif format == 'overlay':
         return render('/comment/edit.html', overlay=True)
     else:
         return render('/comment/edit.html')
Ejemplo n.º 14
0
 def edit(self, id, format='html'):
     c.comment = get_entity_or_abort(model.Comment, id)
     require.comment.edit(c.comment)
     extra_vars = {'comment': c.comment}
     ret_url = request.params.get(u'ret_url', u'')
     if validate_ret_url(ret_url):
         extra_vars[u'ret_url'] = ret_url
         c.ret_url = ret_url
     if format == 'ajax':
         return render_def('/comment/tiles.html',
                           'edit_form',
                           extra_vars=extra_vars)
     elif format == 'overlay':
         return render('/comment/edit.html', overlay=True)
     else:
         return render('/comment/edit.html')
Ejemplo n.º 15
0
 def _render_ajax_create_form(self, parent, topic, variant):
     '''
     render a create form fragment that can be inserted loaded
     into another page.
     '''
     # FIXME: uncomment the format parameter when we have javascript
     # code to submit the form with ajax and replace the form with the
     # response
     # For now, it renders the form with error messages or redirects
     # the user to the new comments anchor on success
     template_args = dict(parent=parent,
                          topic=topic,
                          variant=variant,
                          #format="ajax"
                          )
     return render_def('/comment/tiles.html', 'create_form',
                       template_args)
Ejemplo n.º 16
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.º 17
0
Archivo: event.py Proyecto: alkadis/vcv
    def all(self, format='html'):
        if c.instance is None:
            require.perm('event.index_all')

        events = model.Event.all_q(
            instance=c.instance,
            include_hidden=False,
            event_filter=request.params.getall('event_filter'))\
            .order_by(model.Event.time.desc())\
            .limit(min(int(request.params.get('count', 50)), 100)).all()

        if format == 'rss':
            return event.rss_feed(events, _('%s News' % h.site.name()),
                                  h.base_url(instance=None),
                                  _("News from %s") % h.site.name())

        elif format == 'ajax':
            query_params = request.params.copy()
            while True:
                try:
                    query_params.pop('count')
                except KeyError:
                    break

            more_url = h.base_url(instance=c.instance,
                                  member='event/all',
                                  query_params=query_params)
            return render_def('/event/tiles.html',
                              'carousel',
                              events=events,
                              more_url=more_url)
        else:
            c.event_pager = pager.events(events, count=50)

            if format == 'overlay':
                return render('/event/all.html',
                              overlay=True,
                              overlay_size=OVERLAY_SMALL)
            else:
                return render('/event/all.html')
Ejemplo n.º 18
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()
        update_entity(instance, model.UPDATE)
        if format == 'ajax':
            obj = {'html': render_def('/badge/tiles.html', 'badges',
                                      badges=instance.badges)}
            return render_json(obj)
Ejemplo n.º 19
0
 def render(self):
     return render_def(self.template, self.mako_def, sorts=self)
Ejemplo n.º 20
0
def badge(badge, force_visible=False):
    from adhocracy.lib.templating import render_def
    return render_def('/badge/tiles.html', 'badge', badge=badge,
                        force_visible=force_visible, cached=True)
Ejemplo n.º 21
0
 def render_facets(self):
     '''
     render all facets
     '''
     return render_def('/pager.html', 'facets', pager=self)
Ejemplo n.º 22
0
 def render():
     return templating.render_def(template_name, def_name,
                                  tile=tile, **kwargs)
Ejemplo n.º 23
0
def badge_selector(badges, field_name):
    from adhocracy.lib.templating import render_def
    return render_def('/badge/tiles.html', 'badge_selector',
                    badges=badges, field_name=field_name)
Ejemplo n.º 24
0
def badge_selector(badges, field_name):
    from adhocracy.lib.templating import render_def
    return render_def('/badge/tiles.html',
                      'badge_selector',
                      badges=badges,
                      field_name=field_name)
Ejemplo n.º 25
0
def cloud(tags, plain=True, show_count=False, link_more=True):
    from adhocracy.lib.templating import render_def
    return render_def('/tag/tiles.html', 'cloud', tags=tags, plain=plain,
                      show_count=show_count, link_more=link_more, cached=True)
Ejemplo n.º 26
0
 def render_pager(self):
     '''
     render the template for the pager (without facets)
     '''
     return render_def('/pager.html', 'namedpager', pager=self)
Ejemplo n.º 27
0
 def render(self):
     return render_def(self.template, 'facet', facet=self)
Ejemplo n.º 28
0
 def render_facets(self):
     '''
     render all facets
     '''
     return render_def('/pager.html', 'facets', pager=self)
Ejemplo n.º 29
0
 def render(self):
     return render_def(self.template, self.mako_def, sorts=self)
Ejemplo n.º 30
0
def badge(badge):
    from adhocracy.lib.templating import render_def

    return render_def("/badge/tiles.html", "badge", badge=badge, cached=True)
Ejemplo n.º 31
0
def badges(badges):
    from adhocracy.lib.templating import render_def
    return render_def('/badge/tiles.html', 'badges', badges=badges,
                      cached=True)
Ejemplo n.º 32
0
 def render():
     return templating.render_def(template_name, def_name,
                                  tile=tile, **kwargs)
Ejemplo n.º 33
0
 def render_pager(self):
     '''
     render the template for the pager (without facets)
     '''
     return render_def('/pager.html', 'namedpager', pager=self)
Ejemplo n.º 34
0
def sidebar(delegateable):
    from adhocracy.lib.templating import render_def
    return render_def('/tag/tiles.html', 'sidebar',
                      delegateable=delegateable, cached=True)
Ejemplo n.º 35
0
 def render(self):
     return render_def(self.template, 'facet', facet=self)
Ejemplo n.º 36
0
def badges(badges):
    from adhocracy.lib.templating import render_def
    return render_def('/badge/tiles.html',
                      'badges',
                      badges=badges,
                      cached=True)