def index(self, *args, **kwargs): """return index page""" username = kwargs.get('username', '') user = zoom.get_user() referrer_url = kwargs.get('referrer') if referrer_url: referrer = html.hidden( id="referrer", name="referrer", value=referrer_url, ) else: referrer = '' original_url = kwargs.get('original_url') if original_url: origin = html.hidden( id="original-url", name="original_url", value=original_url, ) else: origin = '' form = LoginForm( username=username, user=user, referrer=referrer, origin=origin, ) return zoom.page(form, template='login')
def form_for(*args, **kwargs): """returns a form with optional hidden values >>> print(form_for('test')) <form action="<dz:request_path>" class="clearfix" enctype="application/x-www-form-urlencoded" id="zoom_form" method="POST" name="zoom_form"> <input name="csrf_token" type="hidden" value="<dz:csrf_token>" /> test </form> """ params = kwargs.copy() name = params.pop('form_name', 'zoom_form') _id = params.pop('id', 'zoom_form') method = params.pop('method', 'POST') action = params.pop('action', '<dz:request_path>') enctype = params.pop('enctype', 'application/x-www-form-urlencoded') classed = params.pop('classed', 'clearfix') t = [] if method == 'POST': request = zoom.system.request if hasattr(request, 'session'): request.session.csrf_token = create_csrf_token() t.append(html.hidden(name='csrf_token', value='<dz:csrf_token>')) content = [] for arg in args: if arg: content.append(type(arg) == str and arg or arg.edit()) if hasattr(arg, 'requires_multipart_form' ) and arg.requires_multipart_form(): enctype = "multipart/form-data" for key, value in params.items(): t.append(html.hidden(name=key, value=value)) return html.tag( 'form', '\n' + '\n'.join(t + content) + '\n', action=action, name=name, id=_id, method=method, enctype=enctype, classed=classed, )
def index(self, *a, **k): username = k.get('username', '') user = self.model.user referrer_url = k.get('referrer') if referrer_url: referrer = html.hidden( id="referrer", name="referrer", value=referrer_url, ) else: referrer = '' form = LoginForm(username=username, user=user, referrer=referrer) return page(form)