]> git.lizzy.rs Git - cheatdb.git/blob - app/views/api.py
Add default title to screenshots
[cheatdb.git] / app / views / api.py
1 # Content DB
2 # Copyright (C) 2018  rubenwardy
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17
18 from flask import *
19 from flask_user import *
20 from app import app
21 from app.models import *
22 from app.utils import is_package_page
23 from .packages import build_packages_query
24
25 @app.route("/api/packages/")
26 def api_packages_page():
27         query, _ = build_packages_query()
28         pkgs = [package.getAsDictionaryShort(app.config["BASE_URL"]) \
29                         for package in query.all() if package.getDownloadRelease() is not None]
30         return jsonify(pkgs)
31
32 @app.route("/api/packages/<author>/<name>/")
33 @is_package_page
34 def api_package_page(package):
35         return jsonify(package.getAsDictionary(app.config["BASE_URL"]))
36
37
38 @app.route("/api/topics/")
39 def api_topics_page():
40         query = ForumTopic.query \
41                         .order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title))
42         pkgs = [t.getAsDictionary() for t in query.all()]
43         return jsonify(pkgs)