diff options
| author | Alexis Metaireau <alexis@notmyidea.org> | 2011-09-11 22:11:36 +0200 |
|---|---|---|
| committer | Alexis Metaireau <alexis@notmyidea.org> | 2011-09-11 22:11:36 +0200 |
| commit | 4bb96b28dee16e78d68f16f5bf158f1e879a0523 (patch) | |
| tree | efabe3db1bdf7b885c2d4f196d490d935105dc67 /budget/utils.py | |
| parent | 20f6f204cfc704b7486cfd9f36a643073fdc57fa (diff) | |
| download | ihatemoney-mirror-4bb96b28dee16e78d68f16f5bf158f1e879a0523.zip ihatemoney-mirror-4bb96b28dee16e78d68f16f5bf158f1e879a0523.tar.gz ihatemoney-mirror-4bb96b28dee16e78d68f16f5bf158f1e879a0523.tar.bz2 | |
API first draft: utils. (related to #27)
Introduces the "rest" module, with reusable utils for flask applications (will be packaged as a flask extension later on).
Diffstat (limited to 'budget/utils.py')
| -rw-r--r-- | budget/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/budget/utils.py b/budget/utils.py index 262ebfe..8d67410 100644 --- a/budget/utils.py +++ b/budget/utils.py @@ -1,4 +1,6 @@ from functools import wraps +import inspect + from flask import redirect, url_for, session, request from werkzeug.routing import HTTPException, RoutingException @@ -34,3 +36,12 @@ class Redirect303(HTTPException, RoutingException): def get_response(self, environ): return redirect(self.new_url, 303) + +def for_all_methods(decorator): + """Apply a decorator to all the methods of a class""" + def decorate(cls): + for name, method in inspect.getmembers(cls, inspect.ismethod): + setattr(cls, name, decorator(method)) + return cls + return decorate + |
