diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-05-13 18:19:50 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-05-13 18:19:50 +0100 |
commit | 0dc02ed67fff593b6d85fba916d79089aebf5b93 (patch) | |
tree | b0809e843caf61ab5fa7eec79adaf9822fda783f /app/views/utils.py | |
parent | 4fdafefcd5b0267e3b9958f3dcc6b05a6eeb0906 (diff) | |
download | cheatdb-0dc02ed67fff593b6d85fba916d79089aebf5b93.tar.xz |
Add is_package_page decorate to pass in package obj
Diffstat (limited to 'app/views/utils.py')
-rw-r--r-- | app/views/utils.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/views/utils.py b/app/views/utils.py index 345d5c1..f6e345a 100644 --- a/app/views/utils.py +++ b/app/views/utils.py @@ -92,6 +92,32 @@ def rank_required(rank): return decorated_function return decorator +def getPackageByInfo(author, name): + user = User.query.filter_by(username=author).first() + if user is None: + abort(404) + + package = Package.query.filter_by(name=name, author_id=user.id).first() + if package is None: + abort(404) + + return package + +def is_package_page(f): + @wraps(f) + def decorated_function(*args, **kwargs): + if not ("author" in kwargs and "name" in kwargs): + abort(400) + + package = getPackageByInfo(kwargs["author"], kwargs["name"]) + + del kwargs["author"] + del kwargs["name"] + + return f(package=package, *args, **kwargs) + + return decorated_function + def triggerNotif(owner, causer, title, url): if owner.rank.atLeast(UserRank.NEW_MEMBER) and owner != causer: Notification.query.filter_by(user=owner, url=url).delete() |