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(), )
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())
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()}, )
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 })
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())
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())
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})
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()})
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)
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)
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)
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()})
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()})
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)
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(), }, )
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()})
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()})
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() })
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)
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)
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(), }, )
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(), }, )
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)
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)
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)
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()})
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()} )