예제 #1
0
파일: poll_tiles.py 프로젝트: alkadis/vcv
def widget(poll, cls="", deactivated=False, delegate_url=None):
    """
    FIXME: fix caching. Poll objects don't change. Tallies are
    generated for every vote. Ask @pudo about this.

    Render a rating widget for an :class:`adhocracy.model.poll.Poll`.
    It is rendered based on the permission of the current user to
    vote for the poll.

    TODO: Add support for helpful tooltips for the voting buttons.

    *cls* (str)
        The type that will be rendered as css class in the widget.
        By default it is a small widget. Using 'big' will render a
        big one.
    *deactivated*
        Render the widget deactivated which does not show vote buttons
        or the current position of the user, but still the vote count.
    *delegate_url* (unicode or None)
        An URL if a delegate button should be shown beside the vote
        widget. If *None* (default) no button will be shown.
    """
    t = PollTile(poll, deactivated, widget_class=cls)
    return render_tile(
        "/poll/tiles.html",
        "widget",
        t,
        poll=poll,
        user=c.user,
        widget_class=cls,
        delegate_url=delegate_url,
        deactivated=deactivated,
        cached=True,
        cache_csrf_token=token_id(),
    )
예제 #2
0
def widget(poll, cls='', deactivated=False, delegate_url=None):
    '''
    FIXME: fix caching. Poll objects don't change. Tallies are
    generated for every vote. Ask @pudo about this.

    Render a rating widget for an :class:`adhocracy.model.poll.Poll`.
    It is rendered based on the permission of the current user to
    vote for the poll.

    TODO: Add support for helpful tooltips for the voting buttons.

    *cls* (str)
        The type that will be rendered as css class in the widget.
        By default it is a small widget. Using 'big' will render a
        big one.
    *deactivated*
        Render the widget deactivated which does not show vote buttons
        or the current position of the user, but still the vote count.
    *delegate_url* (unicode or None)
        An URL if a delegate button should be shown beside the vote
        widget. If *None* (default) no button will be shown.
    '''
    t = PollTile(poll, deactivated, widget_class=cls)
    return render_tile('/poll/tiles.html',
                       'widget',
                       t,
                       poll=poll,
                       user=c.user,
                       widget_class=cls,
                       delegate_url=delegate_url,
                       deactivated=deactivated,
                       cached=True,
                       cache_csrf_token=token_id())
예제 #3
0
파일: instance.py 프로젝트: vigri/adhocracy
 def settings_appearance(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     return htmlfill.render(
         self.settings_appearance_form(id),
         defaults={"_method": "PUT", "css": c.page_instance.css, "_tok": csrf.token_id()},
     )
예제 #4
0
    def edit(self, id):
        c.page_instance = self._get_current_instance(id)
        require.instance.edit(c.page_instance)

        c._Group = model.Group
        c.locales = i18n.LOCALES
        default_group = c.page_instance.default_group.code if \
                        c.page_instance.default_group else \
                        model.Group.INSTANCE_DEFAULT
        return htmlfill.render(render("/instance/edit.html"),
                               defaults={
                                   '_method': 'PUT',
                                   'label': c.page_instance.label,
                                   'description': c.page_instance.description,
                                   'css': c.page_instance.css,
                                   'required_majority':
                                   c.page_instance.required_majority,
                                   'activation_delay':
                                   c.page_instance.activation_delay,
                                   'allow_adopt': c.page_instance.allow_adopt,
                                   'allow_delegate':
                                   c.page_instance.allow_delegate,
                                   'allow_propose':
                                   c.page_instance.allow_propose,
                                   'allow_index': c.page_instance.allow_index,
                                   'hidden': c.page_instance.hidden,
                                   'milestones': c.page_instance.milestones,
                                   'frozen': c.page_instance.frozen,
                                   'locale': c.page_instance.locale,
                                   'use_norms': c.page_instance.use_norms,
                                   '_tok': csrf.token_id(),
                                   'default_group': default_group
                               })
예제 #5
0
def show(comment, recurse=True, ret_url=''):
    can_edit = can.comment.edit(comment)
    groups = sorted(c.user.groups if c.user else [])
    return render_tile('/comment/tiles.html', 'show', CommentTile(comment),
                       comment=comment, cached=True, can_edit=can_edit,
                       groups=groups, ret_url=ret_url, recurse=recurse,
                       cache_csrf_token=token_id())
예제 #6
0
def show(comment, recurse=True, came_from=''):
    can_edit = can.comment.edit(comment)
    groups = sorted(c.user.groups if c.user else [])
    return render_tile('/comment/tiles.html', 'show', CommentTile(comment),
                       comment=comment, cached=True, can_edit=can_edit,
                       groups=groups, came_from=came_from, recurse=recurse,
                       cache_csrf_token=token_id())
예제 #7
0
    def edit(self, id):
        c.page_instance = self._get_current_instance(id)
        require.instance.edit(c.page_instance)

        c._Group = model.Group
        c.locales = i18n.LOCALES
        default_group = c.page_instance.default_group.code if \
                        c.page_instance.default_group else \
                        model.Group.INSTANCE_DEFAULT
        return htmlfill.render(
            render("/instance/edit.html"),
            defaults={
                '_method': 'PUT',
                'label': c.page_instance.label,
                'description': c.page_instance.description,
                'css': c.page_instance.css,
                'required_majority': c.page_instance.required_majority,
                'activation_delay': c.page_instance.activation_delay,
                'allow_adopt': c.page_instance.allow_adopt,
                'allow_delegate': c.page_instance.allow_delegate,
                'allow_propose': c.page_instance.allow_propose,
                'allow_index': c.page_instance.allow_index,
                'hidden': c.page_instance.hidden,
                'milestones': c.page_instance.milestones,
                'frozen': c.page_instance.frozen,
                'locale': c.page_instance.locale,
                'use_norms': c.page_instance.use_norms,
                '_tok': csrf.token_id(),
                'default_group': default_group})
예제 #8
0
 def settings_sname(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     return htmlfill.render(
         self.settings_sname_form(id),
         defaults={
             '_method': 'PUT',
             '_tok': csrf.token_id()})
예제 #9
0
 def settings_sname(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     return htmlfill.render(
         self.settings_sname_form(id),
         defaults={
             '_method': 'PUT',
             '_tok': csrf.token_id()})
예제 #10
0
파일: static.py 프로젝트: whausen/part
 def new(self, errors=None):
     data = {
         'all_language_infos': list(all_language_infos())
     }
     defaults = dict(request.params)
     defaults['_tok'] = csrf.token_id()
     return htmlfill.render(render('/static/new.html', data),
                            defaults=defaults, errors=errors)
예제 #11
0
 def new(self, errors=None, format=u'html'):
     data = {'all_language_infos': list(all_language_infos())}
     defaults = dict(request.params)
     defaults['_tok'] = csrf.token_id()
     return htmlfill.render(render('/static/new.html',
                                   data,
                                   overlay=format == u'overlay'),
                            defaults=defaults,
                            errors=errors)
예제 #12
0
파일: static.py 프로젝트: alkadis/vcv
 def new(self, errors=None, format=u'html'):
     data = {
         'all_language_infos': list(i18n.all_language_infos())
     }
     defaults = dict(request.params)
     defaults['_tok'] = csrf.token_id()
     return htmlfill.render(render('/static/new.html', data,
                                   overlay=format == u'overlay'),
                            defaults=defaults, errors=errors)
예제 #13
0
 def settings_voting(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     return htmlfill.render(
         self.settings_voting_form(id),
         defaults={
             '_method': 'PUT',
             'required_majority': c.page_instance.required_majority,
             'activation_delay': c.page_instance.activation_delay,
             'allow_adopt': c.page_instance.allow_adopt,
             'allow_delegate': c.page_instance.allow_delegate,
             '_tok': csrf.token_id()})
예제 #14
0
 def settings_voting(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     return htmlfill.render(
         self.settings_voting_form(id),
         defaults={
             '_method': 'PUT',
             'required_majority': c.page_instance.required_majority,
             'activation_delay': c.page_instance.activation_delay,
             'allow_adopt': c.page_instance.allow_adopt,
             'allow_delegate': c.page_instance.allow_delegate,
             '_tok': csrf.token_id()})
예제 #15
0
 def settings_appearance(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     return htmlfill.render(
         self._settings_appearance_form(id),
         defaults={
             '_method': 'PUT',
             'css': c.page_instance.css,
             'thumbnailbadges_width':
             c.page_instance.thumbnailbadges_width,
             'thumbnailbadges_height':
             c.page_instance.thumbnailbadges_height,
             '_tok': csrf.token_id()})
예제 #16
0
파일: static.py 프로젝트: whausen/part
 def edit(self, key, lang, errors=None):
     backend = get_backend()
     sp = backend.get(key, lang)
     if not sp:
         return ret_abort(_('Cannot find static page to edit'), code=404)
     data = {'staticpage': sp}
     defaults = {
         'title': sp.title,
         'body': sp.body,
     }
     defaults.update(dict(request.params))
     defaults['_tok'] = csrf.token_id()
     return htmlfill.render(render('/static/edit.html', data),
                            defaults=defaults, errors=errors)
예제 #17
0
파일: instance.py 프로젝트: vigri/adhocracy
 def settings_voting(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     return htmlfill.render(
         self.settings_voting_form(id),
         defaults={
             "_method": "PUT",
             "required_majority": c.page_instance.required_majority,
             "activation_delay": c.page_instance.activation_delay,
             "allow_adopt": c.page_instance.allow_adopt,
             "allow_delegate": c.page_instance.allow_delegate,
             "_tok": csrf.token_id(),
         },
     )
예제 #18
0
 def settings_contents(self, id):
     instance = self._get_current_instance(id)
     require.instance.edit(instance)
     c.page_instance = instance
     return htmlfill.render(
         self.settings_contents_form(id),
         defaults={
             '_method': 'PUT',
             'allow_propose': instance.allow_propose,
             'milestones': instance.milestones,
             'use_norms': instance.use_norms,
             'require_selection': instance.require_selection,
             'frozen': instance.frozen,
             '_tok': csrf.token_id()})
예제 #19
0
 def settings_general(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     form_content = self.settings_general_form(id)
     return htmlfill.render(
         form_content,
         defaults={
             '_method': 'PUT',
             'label': c.page_instance.label,
             'description': c.page_instance.description,
             'default_group': c.default_group,
             'hidden': c.page_instance.hidden,
             'locale': c.page_instance.locale,
             'is_authenticated': c.page_instance.is_authenticated,
             '_tok': csrf.token_id()})
예제 #20
0
 def settings_contents(self, id):
     instance = self._get_current_instance(id)
     require.instance.edit(instance)
     c.page_instance = instance
     return htmlfill.render(self.settings_contents_form(id),
                            defaults={
                                '_method': 'PUT',
                                'allow_propose': instance.allow_propose,
                                'milestones': instance.milestones,
                                'use_norms': instance.use_norms,
                                'require_selection':
                                instance.require_selection,
                                'frozen': instance.frozen,
                                '_tok': csrf.token_id()
                            })
예제 #21
0
 def settings_general(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     form_content = self.settings_general_form(id)
     return htmlfill.render(
         form_content,
         defaults={
             '_method': 'PUT',
             'label': c.page_instance.label,
             'description': c.page_instance.description,
             'default_group': c.default_group,
             'hidden': c.page_instance.hidden,
             'locale': c.page_instance.locale,
             'is_authenticated': c.page_instance.is_authenticated,
             '_tok': csrf.token_id()})
예제 #22
0
파일: instance.py 프로젝트: whausen/part
 def settings_voting(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     defaults = {
         '_method': 'PUT',
         'required_majority': c.page_instance.required_majority,
         'activation_delay': c.page_instance.activation_delay,
         'allow_adopt': c.page_instance.allow_adopt,
         'allow_delegate': c.page_instance.allow_delegate,
         '_tok': csrf.token_id()}
     if model.votedetail.is_enabled():
         defaults['votedetail_badges'] = [
             b.id for b in c.page_instance.votedetail_userbadges]
     return htmlfill.render(
         self.settings_voting_form(id),
         defaults=defaults)
예제 #23
0
 def settings_voting(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     defaults = {
         '_method': 'PUT',
         'required_majority': c.page_instance.required_majority,
         'activation_delay': c.page_instance.activation_delay,
         'allow_adopt': c.page_instance.allow_adopt,
         'allow_delegate': c.page_instance.allow_delegate,
         '_tok': csrf.token_id()}
     if votedetail.is_enabled():
         defaults['votedetail_badges'] = [
             b.id for b in c.page_instance.votedetail_userbadges]
     return htmlfill.render(
         self._settings_voting_form(id),
         defaults=defaults)
예제 #24
0
파일: instance.py 프로젝트: vigri/adhocracy
 def settings_general(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     form_content = self.settings_general_form(id)
     return htmlfill.render(
         form_content,
         defaults={
             "_method": "PUT",
             "label": c.page_instance.label,
             "description": c.page_instance.description,
             "default_group": c.default_group,
             "hidden": c.page_instance.hidden,
             "locale": c.page_instance.locale,
             "is_authenticated": c.page_instance.is_authenticated,
             "_tok": csrf.token_id(),
         },
     )
예제 #25
0
파일: instance.py 프로젝트: vigri/adhocracy
 def settings_contents(self, id):
     instance = self._get_current_instance(id)
     require.instance.edit(instance)
     c.page_instance = instance
     return htmlfill.render(
         self.settings_contents_form(id),
         defaults={
             "_method": "PUT",
             "allow_propose": instance.allow_propose,
             "milestones": instance.milestones,
             "use_norms": instance.use_norms,
             "require_selection": instance.require_selection,
             "hide_global_categories": instance.hide_global_categories,
             "frozen": instance.frozen,
             "_tok": csrf.token_id(),
         },
     )
예제 #26
0
 def edit(self, key, lang, errors=None, format=u'html'):
     backend = get_backend()
     sp = backend.get(key, lang)
     if not sp:
         return ret_abort(_('Cannot find static page to edit'), code=404)
     data = {'staticpage': sp}
     defaults = {
         'title': sp.title,
         'body': sp.body,
     }
     defaults.update(dict(request.params))
     defaults['_tok'] = csrf.token_id()
     return htmlfill.render(render('/static/edit.html',
                                   data,
                                   overlay=format == u'overlay'),
                            defaults=defaults,
                            errors=errors)
예제 #27
0
파일: instance.py 프로젝트: whausen/part
    def badges(self, id, errors=None, format='html'):
        instance = get_entity_or_abort(model.Instance, id)
        c.badges = self._editable_badges(instance)
        defaults = {
            'badge': [str(badge.id) for badge in instance.badges],
            '_tok': csrf.token_id(),
        }
        if format == 'ajax':
            checked = [badge.id for badge in instance.badges]
            json = {'title': instance.label,
                    'badges': [{
                        'id': badge.id,
                        'description': badge.description,
                        'title': badge.title,
                        'checked': badge.id in checked} for badge in c.badges]}
            return render_json(json)

        return formencode.htmlfill.render(
            render("/instance/badges.html"),
            defaults=defaults)
예제 #28
0
 def badges(self, id, errors=None, format='html'):
     c.page_instance = get_entity_or_abort(model.Instance, id)
     c.badges = self._editable_badges(c.page_instance)
     defaults = {
         'badge': [str(badge.id) for badge in c.page_instance.badges],
         '_tok': csrf.token_id(),
     }
     if format == 'ajax':
         checked = [badge.id for badge in c.page_instance.badges]
         json = {'title': c.page_instance.label,
                 'badges': [{
                     'id': badge.id,
                     'description': badge.description,
                     'title': badge.title,
                     'checked': badge.id in checked} for badge in c.badges]}
         return render_json(json)
     else:
         return formencode.htmlfill.render(
             render("/instance/badges.html", overlay=format == u'overlay'),
             defaults=defaults)
예제 #29
0
 def settings_contents(self, id):
     instance = self._get_current_instance(id)
     require.instance.edit(instance)
     c.page_instance = instance
     return htmlfill.render(
         self._settings_contents_form(id),
         defaults={
             '_method': 'PUT',
             'allow_propose': instance.allow_propose,
             'allow_propose_changes': instance.allow_propose_changes,
             'milestones': instance.milestones,
             'use_norms': instance.use_norms,
             'allow_thumbnailbadges': instance.allow_thumbnailbadges,
             'require_selection': instance.require_selection,
             'hide_global_categories': instance.hide_global_categories,
             'editable_comments_default':
             instance.editable_comments_default,
             'editable_proposals_default':
             instance.editable_proposals_default,
             'show_norms_navigation': instance.show_norms_navigation,
             'show_proposals_navigation':
             instance.show_proposals_navigation,
             'frozen': instance.frozen,
             '_tok': csrf.token_id()})
예제 #30
0
파일: instance.py 프로젝트: vigri/adhocracy
 def settings_members_import(self, id):
     c.page_instance = self._get_current_instance(id)
     require.instance.edit(c.page_instance)
     return htmlfill.render(
         self.settings_members_import_form(id), defaults={"_method": "PUT", "_tok": csrf.token_id()}
     )