contentdb/app/views/__init__.py

41 lines
1.2 KiB
Python
Raw Normal View History

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