]> git.lizzy.rs Git - cheatdb.git/blob - app/views/__init__.py
Add package soft deletion
[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 @app.route("/uploads/<path:path>")
35 def send_upload(path):
36         return send_from_directory("public/uploads", path)
37
38 @app.route("/")
39 @menu.register_menu(app, ".", "Home")
40 def home_page():
41         query = Package.query.filter_by(approved=True, soft_deleted=False)
42         count = query.count()
43         packages = query.order_by(db.desc(Package.created_at)).limit(15).all()
44         return render_template("index.html", packages=packages, count=count)
45
46 from . import users, githublogin, packages, sass, tasks, admin, notifications
47
48 @menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
49 @app.route('/<path:path>/')
50 def flatpage(path):
51     page = pages.get_or_404(path)
52     template = page.meta.get('template', 'flatpage.html')
53     return render_template(template, page=page)