contentdb/app/views/__init__.py

41 lines
1.2 KiB
Python
Raw Normal View History

2018-05-14 14:46:41 +01:00
from app import app, pages
2018-03-18 17:43:30 +00:00
from flask import *
from flask_user import *
from flask_login import login_user, logout_user
from app.models import *
2018-03-18 18:05:53 +00:00
import flask_menu as menu
from flask.ext import markdown
2018-03-18 17:43:30 +00:00
from sqlalchemy import func
from werkzeug.contrib.cache import SimpleCache
2018-03-20 02:17:33 +00:00
from urllib.parse import urlparse
2018-03-18 17:43:30 +00:00
cache = SimpleCache()
2018-03-20 02:17:33 +00:00
@app.template_filter()
def domain(url):
2018-03-23 17:05:07 +00:00
return urlparse(url).netloc
2018-03-20 02:17:33 +00:00
2018-03-23 17:05:07 +00:00
# Use nginx to serve files on production instead
2018-03-21 22:03:37 +00:00
@app.route("/static/<path:path>")
2018-03-18 17:43:30 +00:00
def send_static(path):
2018-03-21 22:03:37 +00:00
return send_from_directory("static", path)
2018-03-18 17:43:30 +00:00
2018-03-23 17:05:07 +00:00
@app.route("/uploads/<path:path>")
def send_upload(path):
import os
return send_from_directory(os.path.abspath(app.config["UPLOAD_FOLDER"]), path)
2018-03-21 22:03:37 +00:00
@app.route("/")
@menu.register_menu(app, ".", "Home")
2018-03-18 17:43:30 +00:00
def home_page():
2018-05-09 18:35:36 +01:00
packages = Package.query.filter_by(approved=True).all()
return render_template("index.html", packages=packages)
2018-03-20 00:44:47 +00:00
2018-05-13 17:55:28 +01:00
from . import users, githublogin, packages, sass, tasks, admin, notifications
2018-05-14 14:46:41 +01:00
@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)