perhaps this way: project = db.project(request.args(0,cast=int)) step = db.project_step(request.args(1,cast=int))
if not project: url = URL('default', 'index') elif auth.user_id != project.created_by or not step: url = URL('project', 'show', args=request.args(0) else: url = None tender_form = SQLFORM(db.tender) if url: session.flash = T('Something went wrong.') redirect(url) On Tuesday, 24 September 2013 04:04:44 UTC-5, Andreas Wienes wrote: > > Hey guys, > > in my current project I need to perform some checks before showing a form > to the user. I'm not sure if I've done this in the best possible way. It > looks a bit complicated to me. > > project = db.project(request.args(0)) > step = db.project_step(request.args(1)) > > # Is the project existing? > if project: > # Is the current logged in user the owner of the project? > if auth.user_id == project.created_by: > # Is the step, we want to work with, existing? > if step: > tender_form = SQLFORM(db.tender) > else: > session.flash = T('Something went wrong.') > redirect(URL('project', 'show', args=request.args(0))) > else: > session.flash = T('Something went wrong.') > redirect(URL('project', 'show', args=request.args(0))) > else: > session.flash = T('Something went wrong.') > redirect(URL('default', 'index')) > > > I got three IFs what doesn't look elegant for me. Is it possible to > combine the IF project and IF step statements? > > Thanks for your help > Andreas > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.