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()
32 return urlparse(url).netloc
34 @app.route("/uploads/<path:path>")
35 def send_upload(path):
36 return send_from_directory("public/uploads", path)
39 @menu.register_menu(app, ".", "Home")
41 query = Package.query.filter_by(approved=True, soft_deleted=False)
43 packages = query.order_by(db.desc(Package.created_at)).limit(15).all()
44 return render_template("index.html", packages=packages, count=count)
46 from . import users, githublogin, packages, sass, tasks, admin, notifications
48 @menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
49 @app.route('/<path:path>/')
51 page = pages.get_or_404(path)
52 template = page.meta.get('template', 'flatpage.html')
53 return render_template(template, page=page)