def hide(request, element=None, name=None): """ Hides the given DOM element. The DOM element is specified using css identifiers. Some javascript libraries may have an extended syntax, which can be used if you don't value portability. """ get_store(request).hide(element, name)
def replace(request, element=None, html=None, name=None, value=None): """ Replace the given DOM element with the given html. The DOM element is specified using css identifiers. Some javascript libraries may have an extended syntax, which can be used if you don't value portability. """ get_store(request).replace(element, html, name, value)
def wrapper(request, *args, **kw): output = func(request, *args, **kw) store = get_store(request) # If a dict is given, add that to the output if output is None: output = {} elif isinstance(output, dict): output = output.copy() output.pop('request', None) for key, val in output.items(): store.extra(key, val) # Intercept redirects elif isinstance(output, HttpResponse) and output.status_code in (301, 302): store.redirect(output['Location']) if request.is_ajax(): return store.json_response(include_messages=True) if isinstance(output, dict): # If we have a template, render that if template_name: output.setdefault(ADJAX_CONTEXT_KEY, store) return render_to_response(template_name, output, context_instance=RequestContext(request)) # Try and redirect somewhere useful if 'HTTP_REFERER' in request.META: return redirect(request.META['HTTP_REFERER']) elif DEFAULT_REDIRECT: return redirect(DEFAULT_REDIRECT) else: return HttpResponse() return output
def update(request, obj, attributes=None): """ Sends the updated version of the given attributes on the given object. If no attributes are given, all attributes are sent (be careful if you don't want all data to be public). If a minus sign is in front of an attribute, it is omitted. A mix of attribtue names with and without minus signs is just silly. No other attributes will be included. """ store = get_store(request) if not attributes or all(map(lambda s: s.startswith("-"), attributes)): attributes = obj.__dict__.keys() store.update(obj, (a for a in attributes if not a.startswith("-")))
def wrapper(request, *args, **kw): output = func(request, *args, **kw) store = get_store(request) # If a dict is given, add that to the output if output is None: output = {} elif isinstance(output, dict): output = output.copy() output.pop('request', None) for key, val in output.items(): store.extra(key, val) # Intercept redirects elif isinstance(output, HttpResponse) and output.status_code in (301, 302): store.redirect(output['Location']) if request.is_ajax(): return store.json_response(include_messages=True) if isinstance(output, dict): # If we have a template, render that if template_name: output.setdefault(ADJAX_CONTEXT_KEY, store) return render_to_response( template_name, output, context_instance=RequestContext(request)) # Try and redirect somewhere useful if 'HTTP_REFERER' in request.META: return redirect(request.META['HTTP_REFERER']) elif DEFAULT_REDIRECT: return redirect(DEFAULT_REDIRECT) else: return HttpResponse() return output
def form(request, form_obj): """ Validate the given form and send errors to browser. """ get_store(request).form(form_obj)
def response(request, include_messages=False): """ Provide an appropriate HTTP response. """ return get_store(request).response(include_messages=include_messages)
def render(request, template_name, context=None, prefix=None): """ Update any included templates. """ get_store(request).render_to_response(template_name, context, prefix)
def extra(request, key, value): """ Send additional information to the browser. """ get_store(request).extra(key, value)
def redirect(request, path): """ Redirect the browser dynamically to another page. """ return get_store(request).redirect(path)