1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-13 21:52:18 +00:00
supysonic/frontend/__init__.py

58 lines
1.8 KiB
Python
Raw Normal View History

2014-03-04 21:56:53 +00:00
# coding: utf-8
# This file is part of Supysonic.
#
# Supysonic is a Python implementation of the Subsonic server API.
# Copyright (C) 2014 Alban 'spl0k' Féron
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2014-03-16 17:51:19 +00:00
from flask import session
from web import app, store
from db import Artist, Album, Track
2014-03-04 21:56:53 +00:00
from managers.user import UserManager
app.add_template_filter(str)
@app.before_request
def login_check():
if request.path.startswith('/rest/'):
return
if request.endpoint != 'login':
should_login = False
if not session.get('userid'):
should_login = True
2014-03-16 17:51:19 +00:00
elif UserManager.get(store, session.get('userid'))[0] != UserManager.SUCCESS:
2014-03-04 21:56:53 +00:00
session.clear()
should_login = True
if should_login:
flash('Please login')
return redirect(url_for('login', returnUrl = request.script_root + request.url[len(request.url_root)-1:]))
@app.route('/')
def index():
stats = {
2014-03-16 17:51:19 +00:00
'artists': store.find(Artist).count(),
'albums': store.find(Album).count(),
'tracks': store.find(Track).count()
2014-03-04 21:56:53 +00:00
}
2014-03-16 17:51:19 +00:00
return render_template('home.html', stats = stats, admin = UserManager.get(store, session.get('userid'))[1].admin)
2014-03-04 21:56:53 +00:00
from .user import *
from .folder import *
from .playlist import *