def test_form(self): eq_( form(url="http://www.example.com"), u'<form action="http://www.example.com" method="post">' ) eq_( form(url="http://www.example.com", method='GET'), u'<form action="http://www.example.com" method="GET">' ) eq_( form('/test/edit/1'), u'<form action="/test/edit/1" method="post">' )
def _secure_form(action, method="POST", multipart=False, **kwargs): """Start a form tag that points the action to an url. This form tag will also include the hidden field containing the auth token. The ``action`` option should be given either as a string, or as a ``request.route_url()`` function. The method for the form defaults to POST. Options: ``multipart`` If set to True, the enctype is set to "multipart/form-data". ``method`` The method to use when submitting the form, usually either "GET" or "POST". If "PUT", "DELETE", or another verb is used, a hidden input with name _method is added to simulate the verb over POST. """ #token = request.session.get_csrf_token() #token = hidden(CSRF_TOKEN_KEY, token) #token = HTML.div(token, style="display:none;") #token = '' #form = tags.form(action, method, multipart, **kwargs) #return literal("{}\n{}".format(form, token)) return literal(tags.form(action, method, multipart, **kwargs))
def begin(self, url=None, **attrs): """ Creates the opening <form> tags. By default URL will be current path. """ url = url or self.form.request.path multipart = attrs.pop('multipart', self.form.multipart) return tags.form(url, multipart=multipart, **attrs)
def start(self, url, method="POST", multipart=False, **options): """ Starts a form tag that points the action to an url. The url options should be given either as a string, or as a ``url()`` function. The method for the form defaults to POST. Options: ``multipart`` If set to True, the enctype is set to "multipart/form-data". ``method`` The method to use when submitting the form, usually either "GET" or "POST". If "PUT", "DELETE", or another verb is used, a hidden input with name _method is added to simulate the verb over POST. """ if callable(url): url = url() else: url = html_escape(url) return tags.form(url, method, multipart, **options)
def begin(self, url=None, **attrs): attrs.setdefault('multipart', self.multipart()) attrs.setdefault('method', self.method()) return tags.form(url, **attrs)
def test_form_multipart(self): eq_( form(url='http://www.example.com', multipart=True), u'<form action="http://www.example.com" enctype="multipart/form-data" method="post">' )