def action(self, action, args, with_request=False, permissions=None, subject=None, **kw): """Register an action In: - ``action`` -- action - ``args``, ``kw`` -- ``action`` parameters - ``with_request`` -- will the request and response object be passed to the action? - ``permissions`` -- permissions needed to execute the action - ``subject`` -- subject to test the permissions on Return: - ``self`` """ # The content sent to the action will have the '\r' characters deleted if not isinstance(action, ajax.Update): f = self.clean_input_with_request if with_request else self.clean_input action = partial.Partial(f, action, args) args = () return super(TextArea, self).action(action, with_request=with_request, permissions=permissions, subject=subject, *args, **kw)
def action(self, action, args, with_request=False, permissions=None, subject=None, **kw): """Register an action In: - ``action`` -- action - ``args``, ``kw`` -- ``action`` parameters - ``with_request`` -- will the request and response object be passed to the action? - ``permissions`` -- permissions needed to execute the action - ``subject`` -- subject to test the permissions on Return: - ``self`` """ if (self.get('multiple') is not None) and not isinstance(action, ajax.Update): # If this is a multiple select, the value sent to the action will # always be a list, even if only 1 item was selected f = self.normalize_input_with_request if with_request else self.normalize_input action = partial.Partial(f, action, args) args = () return super(Select, self).action(action, with_request=with_request, permissions=permissions, subject=subject, *args, **kw)
def action(self, action, args, with_request=False, permissions=None, subject=None, **kw): """Register an action In: - ``action`` -- action - ``args``, ``kw`` -- ``action`` parameters - ``with_request`` -- will the request and response objects be passed to the action? - ``permissions`` -- permissions needed to execute the action - ``subject`` -- subject to test the permissions on Return: - ``self`` """ if isinstance(action, ajax.Update): self._async_action(self.renderer, action, with_request) else: # Wrap the ``action`` into a wrapper that will check the user permissions action = security.wrapper(action, permissions, subject or self.renderer.component()) action = partial.Partial(action, *args, **kw) # Double dispatch with the renderer self.renderer.action(self, action, with_request) return self
def _action(self, action, priority, args, with_request, permissions, subject, **kw): """Register an action In: - ``action`` -- action - ``priority`` - ``action`` priority - ``args``, ``kw`` -- ``action`` parameters - ``with_request`` -- will the request and response objects be passed to the action? - ``permissions`` -- permissions needed to execute the action - ``subject`` -- subject to test the permissions on Return: - ``self`` """ action = security.wrapper(action, permissions, subject or self.renderer.component()) action = partial.Partial(action, *args, **kw) # Generate a hidden field with the action attached self.append( self.renderer.div( self.renderer.input(type='hidden', name=self.renderer.register_callback( priority, action, with_request)))) return self
def __init__(self, render='', action=None, component_to_update=None, with_request=False, permissions=None, subject=None, args=(), **kw): """Initialisation In: - ``render`` -- can be: - a string -- name of the view that will be rendered on the current component - a function -- this function will be called and the result sent back to the client - ``action`` -- action to call - ``args``, ``kw`` -- ``action`` parameters - ``component_to_update`` -- can be: - ``None`` -- the current view will be updated - a string -- the DOM id of the HTML to update - a tag -- this tag will be updated - ``with_request`` -- will the request and response objects be passed to the action? - ``permissions`` -- permissions needed to execute the action - ``subject`` -- subject to test the permissions on """ self.render = render self.with_request = with_request self.component_to_update = component_to_update # Wrap the ``action`` into a wrapper that will check the user permissions action = security.wrapper(action or self.no_action, permissions, subject) self.action = partial.Partial(action, *args, **kw)
def on_answer(self, f, *args, **kw): """ Register a function to listen to my answer In: - ``f`` -- function to call with my answer - ``args``, ``kw`` -- ``f`` parameters """ self._on_answer = partial.Partial(f, *args, **kw) if args or kw else f return self
def sort_by(self, name, reverse=False): """Criteria of the sort In: - ``name`` -- name of the column to sort - ``reverse`` -- sort in ascendant or descendant order """ self.sort_header = name self.reverse = reverse i = self.headers.index(name) self.sort_criteria = partial.Partial(self.itemgetter, i=i)
def _generate_render(self, renderer): """Generate the rendering function In: - ``renderer`` -- the current renderer Return: - the rendering function """ renders = [update._generate_render(renderer) for update in self._updates] return partial.Partial(self._generate_response, renders=renders)
def wrapper(action, perm, subject): """Wrap a function or method into a wrapper that will check the user permissions In: - ``action`` -- function or method to wrapper - ``perm`` -- permission(s) to check - ``subject`` -- object to check the permissions on Return: - new action """ if perm is not None: action = partial.Partial(call_with_permissions, None, action, perm, subject) return action
def sync_action(self, renderer, action, with_request): """Register a synchronous action The action will have to return the image data In: - ``renderer`` -- the current renderer - ``action`` -- action - ``with_request`` -- will the request and response objects be passed to the action? - ``permissions`` -- permissions needed to execute the action - ``subject`` -- subject to test the permissions on """ f = partial.Partial(self._set_content_type, _action=action, with_request=with_request) self.set( 'src', renderer.add_sessionid_in_url(sep=';') + ';' + renderer.register_callback(2, f, with_request=True))
def _generate_render(self, renderer): """Generate the rendering function In: - ``renderer`` -- the current renderer Return: - the rendering function """ request = renderer.request if request and not request.is_xhr and ('_a' not in request.params): javascript_dependencies(renderer) renderer.head.javascript_url('/static/nagare/ajax.js') js = 'nagare_updateNode' component_to_update = self.component_to_update if component_to_update is None: async_root = renderer.get_async_root() # Remember to wrap the root view into a ``<div>`` component_to_update = async_root.id async_root.wrapper_to_generate = True js = 'nagare_replaceNode' # Get the ``id`` attribute of the target element or, else, generate one if isinstance(component_to_update, namespaces.xml._Tag): id_ = component_to_update.get('id') if id_ is None: id_ = renderer.generate_id('id') component_to_update.set('id', id_) component_to_update = id_ render = self.render model = () if not callable(render): model = (render if render != '' else async_root.model,) render = renderer.get_async_root().component.render return partial.Partial(self._generate_response, render, model, js, component_to_update)
# # This software is licensed under the BSD License, as described in # the file LICENSE.txt, which you should have received as part of # this distribution. # -- """Set of validating objects Suitable to be the validating functions of ``editor.property`` objects """ import re import functools from nagare import i18n, partial _L = partial.Partial(i18n._L, domain='nagare') class DualCallable(type): """"A hackish metaclass to allow both direct and deferred calls of methods For compatibility with the old and new way to built a validation chain. Examples: - Old validation with direct calls: valid = lambda v: IntValidator(v).greater_than(10) - New validation with lazy calls: valid = IntValidator().greater_than(10) """ def __new__(cls, name, bases, ns): """Class Initialization