2 # Copyright (C) 2018 rubenwardy
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.
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.
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/>.
18 from app import app, pages
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
30 @app.template_filter()
34 @app.template_filter()
36 return urlparse(url).netloc
38 @app.template_filter()
40 return value.strftime("%Y-%m-%d %H:%M") + " UTC"
42 @app.route("/uploads/<path:path>")
43 def send_upload(path):
44 return send_from_directory("public/uploads", path)
47 @menu.register_menu(app, ".", "Home")
49 query = Package.query.filter_by(approved=True, soft_deleted=False)
51 packages = query.order_by(db.desc(Package.created_at)).limit(15).all()
52 return render_template("index.html", packages=packages, count=count)
54 from . import users, githublogin, packages, sass, tasks, admin, notifications, tagseditor, meta
56 @menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
57 @app.route('/<path:path>/')
59 page = pages.get_or_404(path)
60 template = page.meta.get('template', 'flatpage.html')
61 return render_template(template, page=page)
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")
68 return redirect(url_for('user.login'))