diff --git a/pyramid_formalchemy/actions.py b/pyramid_formalchemy/actions.py index 97f830a..fa6264e 100644 --- a/pyramid_formalchemy/actions.py +++ b/pyramid_formalchemy/actions.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from chameleon.zpt.template import PageTemplate from pyramid.util import DottedNameResolver +from pyramid.security import has_permission from pyramid_formalchemy.i18n import TranslationString from pyramid_formalchemy.i18n import get_localizer from pyramid_formalchemy.i18n import _ @@ -95,9 +96,10 @@ class Action(object): """ - def __init__(self, id, content="", alt="", attrs=None, **rcontext): + def __init__(self, id, content="", alt="", permission=None, attrs=None, **rcontext): self.id = id self.attrs = attrs or {} + self.permission = permission self.rcontext = rcontext if 'id' not in self.attrs: self.attrs['id'] = repr(id) @@ -275,7 +277,11 @@ class Actions(list): list.__init__(self, [res.maybe_resolve(a) for a in args]) def render(self, request, **kwargs): - return self.sep.join([a.render(request, **kwargs) for a in self]) + allowed_permissions = [] + for a in self: + if a.permission is None or has_permission(a.permission, request.context, request): + allowed_permissions.append(a) + return self.sep.join([a.render(request, **kwargs) for a in allowed_permissions]) def __add__(self, other): actions = list(self)+list(other) @@ -317,7 +323,7 @@ class Languages(Actions): } def __init__(self, *args, **kwargs): - list.__init__(self) + Actions.__init__(self) klass=kwargs.get('class_', ListItem) for l in args: self.append( @@ -331,6 +337,7 @@ class Languages(Actions): new = UIButton( id='new', content=_('New ${model_label}'), + permission='new', icon='ui-icon-circle-plus', attrs=dict(href="request.fa_url(request.model_name, 'new')"), ) @@ -339,6 +346,7 @@ new = UIButton( save = UIButton( id='save', content=_('Save'), + permission='edit', icon='ui-icon-check', attrs=dict(onclick="jQuery(this).parents('form').submit();"), ) @@ -346,6 +354,7 @@ save = UIButton( save_and_add_another = UIButton( id='save_and_add_another', content=_('Save and add another'), + permission='edit', icon='ui-icon-check', attrs=dict(onclick=("var f = jQuery(this).parents('form');" "jQuery('#next', f).val(window.location.href);" @@ -355,6 +364,7 @@ save_and_add_another = UIButton( edit = UIButton( id='edit', content=_('Edit'), + permission='edit', icon='ui-icon-check', attrs=dict(href="request.fa_url(request.model_name, request.model_id, 'edit')"), ) @@ -368,18 +378,17 @@ back = UIButton( delete = UIButton( id='delete', - views='edit', content=_('Delete'), + permission='delete', state='ui-state-error', icon='ui-icon-trash', - attrs=dict(onclick=("string:var f = jQuery(this).parents('form');" + attrs=dict(onclick=("var f = jQuery(this).parents('form');" "f.attr('action', window.location.href.replace('/edit', '/delete'));" "f.submit();")), ) cancel = UIButton( id='cancel', - views='edit', content=_('Cancel'), icon='ui-icon-circle-arrow-w', attrs=dict(href="request.fa_url(request.model_name)"), diff --git a/pyramid_formalchemy/templates/admin/edit.pt b/pyramid_formalchemy/templates/admin/edit.pt index 23faf45..17a4d9a 100644 --- a/pyramid_formalchemy/templates/admin/edit.pt +++ b/pyramid_formalchemy/templates/admin/edit.pt @@ -4,18 +4,8 @@
diff --git a/pyramid_formalchemy/templates/admin/edit.pt.py b/pyramid_formalchemy/templates/admin/edit.pt.py index b1843d5..7adcccc 100644 --- a/pyramid_formalchemy/templates/admin/edit.pt.py +++ b/pyramid_formalchemy/templates/admin/edit.pt.py @@ -3,19 +3,13 @@ def bind(): from cPickle import loads as _loads _lookup_attr = _loads('cchameleon.core.codegen\nlookup_attr\np1\n.') _init_scope = _loads('cchameleon.core.utils\necontext\np1\n.') - _re_amp = _loads("cre\n_compile\np1\n(S'&(?!([A-Za-z]+|#[0-9]+);)'\np2\nI0\ntRp3\n.") - _attrs_4359005584 = _loads('(dp1\n.') - _attrs_4359005840 = _loads('(dp1\nVname\np2\nV_method\np3\nsVtype\np4\nVhidden\np5\nsVvalue\np6\nVPUT\np7\ns.') - _attrs_4359006416 = _loads('(dp1\nVclass\np2\nVfa_field\np3\ns.') - _attrs_4359006672 = _loads('(dp1\nVclass\np2\nVui-widget-header ui-widget-link ui-corner-all\np3\ns.') - _attrs_4359005008 = _loads('(dp1\nVclass\np2\nVui-icon ui-icon-circle-arrow-w\np3\ns.') + _attrs_4356242384 = _loads('(dp1\n.') + _attrs_4356371600 = _loads('(dp1\n.') _init_stream = _loads('cchameleon.core.generation\ninitialize_stream\np1\n.') - _attrs_4359005968 = _loads('(dp1\n.') + _attrs_4356243152 = _loads('(dp1\nVclass\np2\nVfa_field\np3\ns.') _init_default = _loads('cchameleon.core.generation\ninitialize_default\np1\n.') - _attrs_4359006544 = _loads('(dp1\nVhref\np2\nV#\nsVclass\np3\nVui-widget-header ui-widget-link ui-widget-button ui-corner-all\np4\ns.') - _attrs_4359005520 = _loads('(dp1\nVaction\np2\nV\nsVmethod\np3\nVPOST\np4\nsVenctype\np5\nVmultipart/form-data\np6\ns.') - _attrs_4359006736 = _loads("(dp1\nVtype\np2\nVsubmit\np3\nsVvalue\np4\nV${F_('Save')}\np5\ns.") - _attrs_4359005776 = _loads('(dp1\n.') + _attrs_4356370704 = _loads('(dp1\nVaction\np2\nV\nsVmethod\np3\nVPOST\np4\nsVenctype\np5\nVmultipart/form-data\np6\ns.') + _attrs_4356239504 = _loads('(dp1\nVname\np2\nV_method\np3\nsVtype\np4\nVhidden\np5\nsVvalue\np6\nVPUT\np7\ns.') _init_tal = _loads('cchameleon.core.generation\ninitialize_tal\np1\n.') def render(econtext, rcontext=None): macros = econtext.get('macros') @@ -37,15 +31,15 @@ def bind(): def _callback_main(econtext, _repeat, _out=_out, _write=_write, _domain=_domain, **_ignored): if _repeat: repeat.update(_repeat) - attrs = _attrs_4359005584 + attrs = _attrs_4356371600 _write(u'
\n') + _write(u'
\n \n \n') u"{'main': _callback_main}" _tmp = {'main': _callback_main, } u"main.macros['master']" diff --git a/pyramid_formalchemy/templates/admin/listing.pt b/pyramid_formalchemy/templates/admin/listing.pt index 66f66dd..e0bf70d 100644 --- a/pyramid_formalchemy/templates/admin/listing.pt +++ b/pyramid_formalchemy/templates/admin/listing.pt @@ -3,12 +3,7 @@
diff --git a/pyramid_formalchemy/templates/admin/listing.pt.py b/pyramid_formalchemy/templates/admin/listing.pt.py index 6a5a24a..173f22a 100644 --- a/pyramid_formalchemy/templates/admin/listing.pt.py +++ b/pyramid_formalchemy/templates/admin/listing.pt.py @@ -3,16 +3,13 @@ def bind(): from cPickle import loads as _loads _lookup_attr = _loads('cchameleon.core.codegen\nlookup_attr\np1\n.') _init_scope = _loads('cchameleon.core.utils\necontext\np1\n.') - _re_amp = _loads("cre\n_compile\np1\n(S'&(?!([A-Za-z]+|#[0-9]+);)'\np2\nI0\ntRp3\n.") - _attrs_4359083472 = _loads('(dp1\nVclass\np2\nVui-widget-header ui-widget-link ui-corner-all\np3\ns.') - _attrs_4359083344 = _loads('(dp1\n.') - _attrs_4359083216 = _loads('(dp1\nVclass\np2\nVui-pager\np3\ns.') + _attrs_4353960208 = _loads('(dp1\nVclass\np2\nVlayout-grid\np3\ns.') + _attrs_4353960144 = _loads('(dp1\nVclass\np2\nVui-pager\np3\ns.') _init_stream = _loads('cchameleon.core.generation\ninitialize_stream\np1\n.') - _attrs_4359083600 = _loads('(dp1\nVclass\np2\nVui-icon ui-icon-circle-plus\np3\ns.') - _attrs_4359083088 = _loads('(dp1\n.') + _attrs_4353960272 = _loads('(dp1\nVclass\np2\nVfa_field\np3\ns.') _init_default = _loads('cchameleon.core.generation\ninitialize_default\np1\n.') + _attrs_4353960016 = _loads('(dp1\n.') _init_tal = _loads('cchameleon.core.generation\ninitialize_tal\np1\n.') - _attrs_4359083280 = _loads('(dp1\nVclass\np2\nVlayout-grid\np3\ns.') def render(econtext, rcontext=None): macros = econtext.get('macros') _translate = econtext.get('_translate') @@ -33,13 +30,13 @@ def bind(): def _callback_main(econtext, _repeat, _out=_out, _write=_write, _domain=_domain, **_ignored): if _repeat: repeat.update(_repeat) - attrs = _attrs_4359083088 + attrs = _attrs_4353960016 u"''" _write(u'
\n') u"{'main': _callback_main}" _tmp = {'main': _callback_main, } u"main.macros['master']" diff --git a/pyramid_formalchemy/templates/admin/master.pt b/pyramid_formalchemy/templates/admin/master.pt index f0d5d49..cec236a 100644 --- a/pyramid_formalchemy/templates/admin/master.pt +++ b/pyramid_formalchemy/templates/admin/master.pt @@ -2,6 +2,7 @@
+