tgext.ajaxforms / tgext / ajaxforms / tw_compat.py

try:
    from tw.api import JSLink as Tw1JSLink, Link as Tw1Link
    from tw.jquery import jquery_js as tw1_jquery_js
    class TW1:
        JSLink = Tw1JSLink
        Link = Tw1Link

        jquery_js = tw1_jquery_js
        jquery_form_js = Tw1JSLink(modname=__name__, filename='statics/jquery.form.js')
        spinner_icon = Tw1Link(modname=__name__, filename='statics/spinner.gif')
except ImportError:
    class TW1:
        pass

try:
    from tw2.core.resources import JSLink as Tw2JSLink, Link as Tw2Link
    from tw2.jquery import jquery_js as tw2_jquery_js
    class TW2:
        JSLink = Tw2JSLink
        Link = Tw2Link

        jquery_js = tw2_jquery_js
        jquery_form_js = Tw2JSLink(modname=__name__, filename='statics/jquery.form.js')
        spinner_icon = Tw2Link(modname=__name__, filename='statics/spinner.gif')
except ImportError:
    class TW2:
        pass

def is_tw2_form(w):
    return hasattr(w, 'req')

def inject_widget_resources(w):
    if is_tw2_form(w):
        resources = [r.req() for r in w.resources]
        for r in resources:
            r.prepare()

        for c in w.children_deep():
            #Some widgets modify the resources during prepare
            c = c.req()
            c.prepare()

            resources = [r.req() for r in c.resources]
            for r in resources:
                r.prepare()
    else:
        w.register_resources()

def form_class_name(w):
    if is_tw2_form(w):
        return w.__name__
    else:
        return w.__class__.__name__
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.