]> git.lizzy.rs Git - cheatdb.git/blob - app/views/__init__.py
Fix empty release titles being allowed
[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 throw(err):
32         raise Exception(err)
33
34 @app.template_filter()
35 def domain(url):
36         return urlparse(url).netloc
37
38 @app.template_filter()
39 def datetime(value):
40     return value.strftime("%Y-%m-%d %H:%M") + " UTC"
41
42 @app.route("/uploads/<path:path>")
43 def send_upload(path):
44         return send_from_directory("public/uploads", path)
45
46 @app.route("/")
47 @menu.register_menu(app, ".", "Home")
48 def home_page():
49         query = Package.query.filter_by(approved=True, soft_deleted=False)
50         count = query.count()
51         packages = query.order_by(db.desc(Package.created_at)).limit(15).all()
52         return render_template("index.html", packages=packages, count=count)
53
54 from . import users, githublogin, packages, sass, tasks, admin, notifications, tagseditor, meta
55
56 @menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
57 @app.route('/<path:path>/')
58 def flatpage(path):
59     page = pages.get_or_404(path)
60     template = page.meta.get('template', 'flatpage.html')
61     return render_template(template, page=page)
62
63 @app.before_request
64 def do_something_whenever_a_request_comes_in():
65         if current_user.is_authenticated and current_user.rank == UserRank.BANNED:
66                 flash("You have been banned.", "error")
67                 logout_user()
68                 return redirect(url_for('user.login'))