aboutsummaryrefslogtreecommitdiff
path: root/app/views/__init__.py
blob: 37474de03b32badd63ebfd354fab59bf21e63e8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Content DB
# Copyright (C) 2018  rubenwardy
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.


from app import app, pages
from flask import *
from flask_user import *
from flask_login import login_user, logout_user
from app.models import *
import flask_menu as menu
from flask.ext import markdown
from sqlalchemy import func
from werkzeug.contrib.cache import SimpleCache
from urllib.parse import urlparse
cache = SimpleCache()

@app.template_filter()
def domain(url):
	return urlparse(url).netloc

# Use nginx to serve files on production instead
@app.route("/static/<path:path>")
def send_static(path):
	return send_from_directory("public/static", path)

@app.route("/uploads/<path:path>")
def send_upload(path):
	return send_from_directory("public/uploads", path)

@app.route("/")
@menu.register_menu(app, ".", "Home")
def home_page():
	query = Package.query.filter_by(approved=True)
	count = query.count()
	packages = query.order_by(db.desc(Package.created_at)).limit(15).all()
	return render_template("index.html", packages=packages, count=count)

from . import users, githublogin, packages, sass, tasks, admin, notifications

@menu.register_menu(app, ".help", "Help", order=19, endpoint_arguments_constructor=lambda: { 'path': 'help' })
@app.route('/<path:path>/')
def flatpage(path):
    page = pages.get_or_404(path)
    template = page.meta.get('template', 'flatpage.html')
    return render_template(template, page=page)