Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
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)
Exemple #5
0
    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
Exemple #6
0
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("-")))
Exemple #7
0
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("-")))
Exemple #8
0
    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
Exemple #9
0
def form(request, form_obj):
    """ Validate the given form and send errors to browser. """
    get_store(request).form(form_obj)
Exemple #10
0
def response(request, include_messages=False):
    """ Provide an appropriate HTTP response. """
    return get_store(request).response(include_messages=include_messages)
Exemple #11
0
def render(request, template_name, context=None, prefix=None):
    """ Update any included templates. """
    get_store(request).render_to_response(template_name, context, prefix)
Exemple #12
0
def extra(request, key, value):
    """ Send additional information to the browser. """
    get_store(request).extra(key, value)
Exemple #13
0
def redirect(request, path):
    """ Redirect the browser dynamically to another page. """
    return get_store(request).redirect(path)
Exemple #14
0
def redirect(request, path):
    """ Redirect the browser dynamically to another page. """
    return get_store(request).redirect(path)
Exemple #15
0
def extra(request, key, value):
    """ Send additional information to the browser. """
    get_store(request).extra(key, value)
Exemple #16
0
def form(request, form_obj):
    """ Validate the given form and send errors to browser. """
    get_store(request).form(form_obj)
Exemple #17
0
def response(request, include_messages=False):
    """ Provide an appropriate HTTP response. """
    return get_store(request).response(include_messages=include_messages)
Exemple #18
0
def render(request, template_name, context=None, prefix=None):
    """ Update any included templates. """
    get_store(request).render_to_response(template_name, context, prefix)