def _button_to(name, url='', **html_options): """ Creates the button_to html but leaves out the </form> to allow the secure_button_to() (webhelpers.rails.secure_form_tag.secure_button_to) to use this function as well. """ if html_options: convert_boolean_attributes(html_options, ['disabled']) method_tag = '' method = html_options.pop('method', '') if method.upper() in ['PUT', 'DELETE']: method_tag = tags.tag('input', type_='hidden', id='_method', name_='_method', value=method) form_method = (method.upper() == 'GET' and method) or 'POST' confirm = html_options.get('confirm') if confirm: del html_options['confirm'] html_options['onclick'] = "return %s;" % confirm_javascript_function( confirm) if callable(url): ur = url() url, name = ur, name or tags.escape_once(ur) else: url, name = url, name or url submit_type = html_options.get('type') img_source = html_options.get('src') if submit_type == 'image' and img_source: html_options.update( dict(type=submit_type, value=name, alt=html_options.get('alt', name))) html_options['src'] = compute_public_path(img_source, 'images', 'png') else: html_options.update(dict(type='submit', value=name)) return """<form method="%s" action="%s" class="button-to"><div>""" % \ (form_method, tags.escape_once(url)) + method_tag + \ tags.tag("input", **html_options) + "</div>"
def importg(self, name): with open(name) as f: nb_nodes, nb_nt = 0, 0 for line in f: vertex = line.strip()[:-1] if use_tags: vertex = tag(vertex, self.k) self.addvertex(vertex) nb_nodes, nb_nt = nb_nodes + 1, nb_nt + len(vertex) graph_stats.new_graph(nb_nt, nb_nodes, name)
def _button_to(name, url='', **html_options): """ Creates the button_to html but leaves out the </form> to allow the secure_button_to() (webhelpers.rails.secure_form_tag.secure_button_to) to use this function as well. """ if html_options: convert_boolean_attributes(html_options, ['disabled']) method_tag = '' method = html_options.pop('method', '') if method.upper() in ['PUT', 'DELETE']: method_tag = tags.tag('input', type_='hidden', id='_method', name_='_method', value=method) form_method = (method.upper() == 'GET' and method) or 'POST' confirm = html_options.get('confirm') if confirm: del html_options['confirm'] html_options['onclick'] = "return %s;" % confirm_javascript_function(confirm) if callable(url): ur = url() url, name = ur, name or tags.escape_once(ur) else: url, name = url, name or url submit_type = html_options.get('type') img_source = html_options.get('src') if submit_type == 'image' and img_source: html_options.update(dict(type=submit_type, value=name, alt=html_options.get('alt', name))) html_options['src'] = compute_public_path(img_source, 'images', 'png') else: html_options.update(dict(type='submit', value=name)) return """<form method="%s" action="%s" class="button-to"><div>""" % \ (form_method, tags.escape_once(url)) + method_tag + \ tags.tag("input", **html_options) + "</div>"
def submit_to_remote(name, value, **options): """ A submit button that submits via an XMLHttpRequest call Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular reloading POST arrangement. Keyword args are the same as in ``form_remote_tag``. """ options['with'] = options.get('form') or 'Form.serialize(this.form)' options['html'] = options.get('html') or {} options['html']['type'] = 'button' options['html']['onclick'] = "%s; return false;" % remote_function(**options) options['html']['name_'] = name options['html']['value'] = str(value) return tag("input", open=False, **options['html'])
def submit_to_remote(name, value, **options): """ A submit button that submits via an XMLHttpRequest call Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular reloading POST arrangement. Keyword args are the same as in ``form_remote_tag``. """ options['with_'] = options.get('form') or 'Form.serialize(this.form)' options['html'] = options.get('html') or {} options['html']['type'] = 'button' options['html']['onclick'] = "%s; return false;" % remote_function( **options) options['html']['name_'] = name options['html']['value'] = '%s' % value return tag("input", open=False, **options['html'])
def button_to(name, url='', **html_options): """ Generates a form containing a sole button that submits to the URL given by ``url``. Use this method instead of ``link_to`` for actions that do not have the safe HTTP GET semantics implied by using a hypertext link. The parameters are the same as for ``link_to``. Any ``html_options`` that you pass will be applied to the inner ``input`` element. In particular, pass disabled = True/False as part of ``html_options`` to control whether the button is disabled. The generated form element is given the class 'button-to', to which you can attach CSS styles for display purposes. Example 1:: # inside of controller for "feeds" >>> button_to("Edit", url(action='edit', id=3)) <form method="post" action="/feeds/edit/3" class="button-to"> <div><input value="Edit" type="submit" /></div> </form> Example 2:: >> button_to("Destroy", url(action='destroy', id=3), confirm="Are you sure?") <form method="post" action="/feeds/destroy/3" class="button-to"> <div><input onclick="return confirm('Are you sure?');" value="Destroy" type="submit" /> </div> </form> *NOTE*: This method generates HTML code that represents a form. Forms are "block" content, which means that you should not try to insert them into your HTML where only inline content is expected. For example, you can legally insert a form inside of a ``div`` or ``td`` element or in between ``p`` elements, but not in the middle of a run of text, nor can you place a form within another form. (Bottom line: Always validate your HTML before going public.) """ if html_options: convert_boolean_attributes(html_options, ['disabled']) confirm = html_options.get('confirm') if confirm: del html_options['confirm'] html_options['onclick'] = "return %s;" % confirm_javascript_function( confirm) if callable(url): ur = url() url, name = ur, name or html_escape(ur) else: url, name = url, name or url html_options.update(dict(type='submit', value=name)) return """<form method="post" action="%s" class="button-to"><div>""" % html_escape(url) + \ tags.tag("input", **html_options) + "</div></form>"
def button_to(name, url='', **html_options): """ Generates a form containing a sole button that submits to the URL given by ``url``. Use this method instead of ``link_to`` for actions that do not have the safe HTTP GET semantics implied by using a hypertext link. The parameters are the same as for ``link_to``. Any ``html_options`` that you pass will be applied to the inner ``input`` element. In particular, pass disabled = True/False as part of ``html_options`` to control whether the button is disabled. The generated form element is given the class 'button-to', to which you can attach CSS styles for display purposes. Example 1:: # inside of controller for "feeds" >>> button_to("Edit", url(action='edit', id=3)) <form method="post" action="/feeds/edit/3" class="button-to"> <div><input value="Edit" type="submit" /></div> </form> Example 2:: >> button_to("Destroy", url(action='destroy', id=3), confirm="Are you sure?") <form method="post" action="/feeds/destroy/3" class="button-to"> <div><input onclick="return confirm('Are you sure?');" value="Destroy" type="submit" /> </div> </form> *NOTE*: This method generates HTML code that represents a form. Forms are "block" content, which means that you should not try to insert them into your HTML where only inline content is expected. For example, you can legally insert a form inside of a ``div`` or ``td`` element or in between ``p`` elements, but not in the middle of a run of text, nor can you place a form within another form. (Bottom line: Always validate your HTML before going public.) """ if html_options: convert_boolean_attributes(html_options, ['disabled']) confirm = html_options.get('confirm') if confirm: del html_options['confirm'] html_options['onclick'] = "return %s;" % confirm_javascript_function(confirm) if callable(url): ur = url() url, name = ur, name or html_escape(ur) else: url, name = url, name or url html_options.update(dict(type='submit', value=name)) return """<form method="post" action="%s" class="button-to"><div>""" % html_escape(url) + \ tags.tag("input", **html_options) + "</div></form>"
def setFields(self, title, description): self.insertContents(tag(title,'', name='media:title')) self.insertContents(tag(description, name='media:description'))
def button_to(name, url='', **html_options): """ Generates a form containing a sole button that submits to the URL given by ``url``. Use this method instead of ``link_to`` for actions that do not have the safe HTTP GET semantics implied by using a hypertext link. The parameters are the same as for ``link_to``. Any ``html_options`` that you pass will be applied to the inner ``input`` element. In particular, pass disabled = True/False as part of ``html_options`` to control whether the button is disabled. The generated form element is given the class 'button-to', to which you can attach CSS styles for display purposes. The submit button itself will be displayed as an image if you provide both ``type`` and ``src`` as followed: type='image', src='icon_delete.gif' The ``src`` path will be computed as the image_tag() computes it's ``source`` argument. Example 1:: # inside of controller for "feeds" >> button_to("Edit", url(action='edit', id=3)) <form method="POST" action="/feeds/edit/3" class="button-to"> <div><input value="Edit" type="submit" /></div> </form> Example 2:: >> button_to("Destroy", url(action='destroy', id=3), confirm="Are you sure?", method='DELETE') <form method="POST" action="/feeds/destroy/3" class="button-to"> <div> <input type="hidden" name="_method" value="DELETE" /> <input onclick="return confirm('Are you sure?');" value="Destroy" type="submit" /> </div> </form> Example 3:: # Button as an image. >> button_to("Edit", url(action='edit', id=3), type='image', src='icon_delete.gif') <form method="POST" action="/feeds/edit/3" class="button-to"> <div><input alt="Edit" src="/images/icon_delete.gif" type="image" value="Edit" /></div> </form> *NOTE*: This method generates HTML code that represents a form. Forms are "block" content, which means that you should not try to insert them into your HTML where only inline content is expected. For example, you can legally insert a form inside of a ``div`` or ``td`` element or in between ``p`` elements, but not in the middle of a run of text, nor can you place a form within another form. (Bottom line: Always validate your HTML before going public.) """ if html_options: convert_boolean_attributes(html_options, ['disabled']) method_tag = '' method = html_options.pop('method', '') if method.upper() in ['PUT', 'DELETE']: method_tag = tags.tag('input', type_='hidden', id='_method', name_='_method', value=method) form_method = (method.upper() == 'GET' and method) or 'POST' confirm = html_options.get('confirm') if confirm: del html_options['confirm'] html_options['onclick'] = "return %s;" % confirm_javascript_function(confirm) if callable(url): ur = url() url, name = ur, name or tags.escape_once(ur) else: url, name = url, name or url submit_type = html_options.get('type') img_source = html_options.get('src') if submit_type == 'image' and img_source: html_options.update(dict(type=submit_type, value=name, alt=html_options.get('alt', name))) html_options['src'] = compute_public_path(img_source, 'images', 'png') else: html_options.update(dict(type='submit', value=name)) return """<form method="%s" action="%s" class="button-to"><div>""" % \ (form_method, tags.escape_once(url)) + method_tag + \ tags.tag("input", **html_options) + "</div></form>"
def button_to(name, url='', **html_options): """ Generates a form containing a sole button that submits to the URL given by ``url``. Use this method instead of ``link_to`` for actions that do not have the safe HTTP GET semantics implied by using a hypertext link. The parameters are the same as for ``link_to``. Any ``html_options`` that you pass will be applied to the inner ``input`` element. In particular, pass disabled = True/False as part of ``html_options`` to control whether the button is disabled. The generated form element is given the class 'button-to', to which you can attach CSS styles for display purposes. The submit button itself will be displayed as an image if you provide both ``type`` and ``src`` as followed: type='image', src='icon_delete.gif' The ``src`` path will be computed as the image_tag() computes it's ``source`` argument. Example 1:: # inside of controller for "feeds" >> button_to("Edit", url(action='edit', id=3)) <form method="POST" action="/feeds/edit/3" class="button-to"> <div><input value="Edit" type="submit" /></div> </form> Example 2:: >> button_to("Destroy", url(action='destroy', id=3), confirm="Are you sure?", method='DELETE') <form method="POST" action="/feeds/destroy/3" class="button-to"> <div> <input type="hidden" name="_method" value="DELETE" /> <input onclick="return confirm('Are you sure?');" value="Destroy" type="submit" /> </div> </form> Example 3:: # Button as an image. >> button_to("Edit", url(action='edit', id=3), type='image', src='icon_delete.gif') <form method="POST" action="/feeds/edit/3" class="button-to"> <div><input alt="Edit" src="/images/icon_delete.gif" type="image" value="Edit" /></div> </form> *NOTE*: This method generates HTML code that represents a form. Forms are "block" content, which means that you should not try to insert them into your HTML where only inline content is expected. For example, you can legally insert a form inside of a ``div`` or ``td`` element or in between ``p`` elements, but not in the middle of a run of text, nor can you place a form within another form. (Bottom line: Always validate your HTML before going public.) """ if html_options: convert_boolean_attributes(html_options, ['disabled']) method_tag = '' method = html_options.pop('method', '') if method.upper() in ['PUT', 'DELETE']: method_tag = tags.tag('input', type_='hidden', id='_method', name_='_method', value=method) form_method = (method.upper() == 'GET' and method) or 'POST' confirm = html_options.get('confirm') if confirm: del html_options['confirm'] html_options['onclick'] = "return %s;" % confirm_javascript_function( confirm) if callable(url): ur = url() url, name = ur, name or tags.escape_once(ur) else: url, name = url, name or url submit_type = html_options.get('type') img_source = html_options.get('src') if submit_type == 'image' and img_source: html_options.update( dict(type=submit_type, value=name, alt=html_options.get('alt', name))) html_options['src'] = compute_public_path(img_source, 'images', 'png') else: html_options.update(dict(type='submit', value=name)) return """<form method="%s" action="%s" class="button-to"><div>""" % \ (form_method, tags.escape_once(url)) + method_tag + \ tags.tag("input", **html_options) + "</div></form>"