2018-05-17 16:18:20 +02:00
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
|
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-05-27 22:31:11 +02:00
|
|
|
@app.template_filter()
|
|
|
|
def throw(err):
|
|
|
|
raise Exception(err)
|
|
|
|
|
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-05-28 00:45:12 +02:00
|
|
|
@app.template_filter()
|
|
|
|
def datetime(value):
|
|
|
|
return value.strftime("%Y-%m-%d %H:%M") + " UTC"
|
|
|
|
|
2018-03-23 18:05:07 +01:00
|
|
|
@app.route("/uploads/<path:path>")
|
|
|
|
def send_upload(path):
|
2018-05-23 22:12:52 +02:00
|
|
|
return send_from_directory("public/uploads", path)
|
2018-03-23 18:05:07 +01:00
|
|
|
|
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-07-04 02:20:55 +02:00
|
|
|
query = Package.query.filter_by(approved=True, soft_deleted=False)
|
|
|
|
count = query.count()
|
|
|
|
new = query.order_by(db.desc(Package.created_at)).limit(15).all()
|
|
|
|
popular = query.order_by(db.desc(Package.score)).limit(6).all()
|
2018-07-04 02:05:32 +02:00
|
|
|
return render_template("index.html", new=new, popular=popular, count=count)
|
2018-03-20 01:44:47 +01:00
|
|
|
|
2018-06-15 23:57:43 +02:00
|
|
|
from . import users, githublogin, packages, meta, threads, api
|
2018-07-28 18:26:28 +02:00
|
|
|
from . import tasks, admin, notifications, tagseditor, licenseseditor
|
|
|
|
from . import sass, thumbnails
|
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)
|
2018-05-26 02:58:56 +02:00
|
|
|
|
|
|
|
@app.before_request
|
|
|
|
def do_something_whenever_a_request_comes_in():
|
2018-05-29 19:27:33 +02:00
|
|
|
if current_user.is_authenticated:
|
|
|
|
if current_user.rank == UserRank.BANNED:
|
|
|
|
flash("You have been banned.", "error")
|
|
|
|
logout_user()
|
|
|
|
return redirect(url_for('user.login'))
|
|
|
|
elif current_user.rank == UserRank.NOT_JOINED:
|
|
|
|
current_user.rank = UserRank.MEMBER
|
|
|
|
db.session.commit()
|