def form_remote_tag(**options): """ Create a form tag using a remote function to submit the request Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it's using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side. The options for specifying the target with ``url`` and defining callbacks is the same as `link_to_remote <#link_to_remote>`_. A "fall-through" target for browsers that doesn't do JavaScript can be specified with the ``action/method`` options on ``html``. Example:: form_remote_tag(html=dict(action=url( controller="some", action="place"))) By default the fall-through action is the same as the one specified in the ``url`` (and the default method is ``post``). """ options['form'] = True if 'html' not in options: options['html'] = {} options['html']['onsubmit'] = "%s; return false;" % remote_function(**options) action = options['html'].get('action', get_url(options['url'])) options['html']['method'] = options['html'].get('method', 'post') return form(action, **options['html'])
def form_remote_tag(**options): """ Create a form tag using a remote function to submit the request. Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it's using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side. The options for specifying the target with ``url`` and defining callbacks is the same as `link_to_remote <#link_to_remote>`_. A "fall-through" target for browsers that doesn't do JavaScript can be specified with the ``action/method`` options on ``html``. Example:: form_remote_tag(html=dict(action=url( controller="some", action="place"))) By default the fall-through action is the same as the one specified in the ``url`` (and the default method is ``POST``). """ options['form'] = True if 'html' not in options: options['html'] = {} options['html']['onsubmit'] = "%s; return false;" % remote_function( **options) action = options['html'].get('action', get_url(options['url'])) options['html']['method'] = options['html'].get('method', 'POST') return form(action, **options['html'])
def init(): global url_index, p p += 1 product_list = get_data(get_url(url_index, p)) if len(product_list) > 0: insert(conn=conn, data=product_list) time.sleep(1) init() else: url_index += 1 p = 0 if (len(category_index_list) - 1 < url_index): conn.close() else: init()
def remote_function(**options): """ Return the JavaScript needed for a remote function. Takes the same options that can be passed as ``options`` to `link_to_remote <#link_to_remote>`_. Example:: <select id="options" onchange="<% remote_function(update="options", url=url(action='update_options')) %>"> <option value="0">Hello</option> <option value="1">World</option> </select> """ javascript_options = options_for_ajax(options) update = '' if options.get('update') and isinstance(options['update'], dict): update = [] if options['update'].has_key('success'): update.append("success:'%s'" % options['update']['success']) if options['update'].has_key('failure'): update.append("failure:'%s'" % options['update']['failure']) update = '{' + ','.join(update) + '}' elif options.get('update'): update += "'%s'" % options['update'] function = "new Ajax.Request(" if update: function = "new Ajax.Updater(%s, " % update function += "'%s'" % get_url(options['url']) function += ", %s)" % javascript_options if options.get('before'): function = "%s; %s" % (options['before'], function) if options.get('after'): function = "%s; %s" % (function, options['after']) if options.get('condition'): function = "if (%s) { %s; }" % (options['condition'], function) if options.get('confirm'): function = "if (confirm('%s')) { %s; }" % (escape_javascript( options['confirm']), function) return function
def remote_function(**options): """ Return the JavaScript needed for a remote function. Takes the same options that can be passed as ``options`` to `link_to_remote <#link_to_remote>`_. Example:: <select id="options" onchange="<% remote_function(update="options", url=url(action='update_options')) %>"> <option value="0">Hello</option> <option value="1">World</option> </select> """ javascript_options = options_for_ajax(options) update = '' if options.get('update') and isinstance(options['update'], dict): update = [] if options['update'].has_key('success'): update.append("success:'%s'" % options['update']['success']) if options['update'].has_key('failure'): update.append("failure:'%s'" % options['update']['failure']) update = '{' + ','.join(update) + '}' elif options.get('update'): update += "'%s'" % options['update'] function = "new Ajax.Request(" if update: function = "new Ajax.Updater(%s, " % update function += "'%s'" % get_url(options['url']) function += ", %s)" % javascript_options if options.get('before'): function = "%s; %s" % (options['before'], function) if options.get('after'): function = "%s; %s" % (function, options['after']) if options.get('condition'): function = "if (%s) { %s; }" % (options['condition'], function) if options.get('confirm'): function = "if (confirm('%s')) { %s; }" % (escape_javascript(options['confirm']), function) return function
def return_url(url_id): return redirect(get_url(url_id))