]> git.lizzy.rs Git - cheatdb.git/blob - app/views/__init__.py
Fix user list sort order
[cheatdb.git] / app / views / __init__.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 app import app, pages
19 from flask import *
20 from flask_user import *
21 from flask_login import login_user, logout_user
22 from app.models import *
23 import flask_menu as menu
24 from flask.ext import markdown
25 from sqlalchemy import func
26 from werkzeug.contrib.cache import SimpleCache
27 from urllib.parse import urlparse
28 cache = SimpleCache()
29
30 @app.template_filter()
31 def domain(url):
32         return urlparse(url).netloc
33
34 # Use nginx to serve files on production instead
35 @app.route("/static/<path:path>")
36 def send_static(path):
37         return send_from_directory("static", path)
38
39 @app.route("/uploads/<path:path>")
40 def send_upload(path):
41         import os
42         return send_from_directory(os.path.abspath(app.config["UPLOAD_FOLDER"]), path)
43
44 @app.route("/")
45 @menu.register_menu(app, ".", "Home")
46 def home_page():
47         packages = Package.query.filter_by(approved=True).all()
48         return render_template("index.html", packages=packages)
49
50 from . import users, githublogin, packages, sass, tasks, admin, notifications
51
52 @menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
53 @app.route('/<path:path>/')
54 def flatpage(path):
55     page = pages.get_or_404(path)
56     template = page.meta.get('template', 'flatpage.html')
57     return render_template(template, page=page)