diff options
author | Simo Sorce <simo@redhat.com> | 2014-08-01 08:14:58 -0400 |
---|---|---|
committer | Patrick Uiterwijk <puiterwijk@redhat.com> | 2014-09-24 20:29:19 +0200 |
commit | a511d8ab35cc0f2872eac640ed4120766f92704a (patch) | |
tree | 9b25758ca8ad37e6f97db1138be04ae3191cc8be /ipsilon/login/common.py | |
parent | 32bb6d8b38b9147143074710ba2dcb7f45cd4157 (diff) | |
download | ipsilon-a511d8ab35cc0f2872eac640ed4120766f92704a.tar.gz ipsilon-a511d8ab35cc0f2872eac640ed4120766f92704a.tar.xz ipsilon-a511d8ab35cc0f2872eac640ed4120766f92704a.zip |
Create common form handler page
Reduce duplication
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Diffstat (limited to 'ipsilon/login/common.py')
-rwxr-xr-x | ipsilon/login/common.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ipsilon/login/common.py b/ipsilon/login/common.py index 5470626..b451550 100755 --- a/ipsilon/login/common.py +++ b/ipsilon/login/common.py @@ -126,6 +126,41 @@ class LoginPageBase(Page): raise cherrypy.HTTPError(500) +class LoginFormBase(LoginPageBase): + + def __init__(self, site, mgr, page, template=None): + super(LoginFormBase, self).__init__(site, mgr) + self.formpage = page + self.formtemplate = template or 'login/form.html' + + def GET(self, *args, **kwargs): + context = self.create_tmpl_context() + # pylint: disable=star-args + return self._template(self.formtemplate, **context) + + def root(self, *args, **kwargs): + op = getattr(self, cherrypy.request.method, self.GET) + if callable(op): + return op(*args, **kwargs) + + def create_tmpl_context(self, **kwargs): + next_url = None + if self.lm.next_login is not None: + next_url = self.lm.next_login.path + + context = { + "title": 'Login', + "action": '%s/%s' % (self.basepath, self.formpage), + "service_name": self.lm.service_name, + "username_text": self.lm.username_text, + "password_text": self.lm.password_text, + "description": self.lm.help_text, + "next_url": next_url, + } + context.update(kwargs) + return context + + FACILITY = 'login_config' |