defnull/bottle — pull request #331 by tonyseek (2012-06-07 14:29:57+00:00)
Title: Use only a argument to view function

As we known, some bottle plugins such as `bottle.ext.sqlite` need to provide a request scoped object to the view function. If a application has a large number of the installed plugins, the arguments of view function will become too long.

For example:

```python
@app.get("/article/:id")
def article(db, current_user, cache, taskmanager, id):
cursor = db.execute("SELECT * FROM article WHERE id = ?", id)
article = Article.from_cursor(cursor.fetchone() or bottle.abort(404))
if article.need_destory_cache(current_user):
taskmanager.put(lambda: cache.destory("article-%d" % id))
return bottle.template("article.html", article=article)
```

I thought that it's possible to make view functions be more concise, if we put all request scoped object into one argument. Just like this:

```python
@app.get("/article/:id")
def article(context, id):
cursor = context.db.execute("SELECT * FROM article WHERE id = ?", id)
article = Article.from_cursor(cursor.fetchone() or bottle.abort(404))
if article.need_destory_cache(context.current_user):
task = lambda: context.cache.destory("article-%d" % id)
context.taskmanager.put(task)
return bottle.template("article.html", article=article)
```

If a view argument has not argument named "context", the context object will not be created.