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