コード例 #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
ファイル: decorators.py プロジェクト: firefoxxy8/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
コード例 #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)