2011/9/19 michael kapelko <[email protected]>:
> Hi.
>
> I have lots of classes that look like this:
>
> class PAGE_NAME:
> def GET(self, param):
> if (session.get("login", None)):
> i = web.input()
> c = db()
> return render.PAGE_NAME(session.login, c, i)
> else:
> raise web.seeother("/")
>
> If user is not logged it, it redirects to login page. Otherwise it
> displays necessary info.
> I have about 10 classes already and more to come. The code is all the
> same except for PAGE_NAME. Is there a way not to duplicate things?
>
> Also, for every such page I also must add the following to urls:
> "/PAGE_NAME(.*)", PAGE_NAME
> Is there a way to automate this as well?
How about this:
urls = (
"(pagename1|pagename2)/(.*)", "page"
)
def render_template(name, *a, **kw):
t = getattr(render, name)
return t(*a, **kw)
class page:
def GET(self, templatename, param):
...
return render_template(templatename, ...)
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.