1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-10 04:02:17 +00:00
supysonic/web.py

57 lines
1.4 KiB
Python
Raw Normal View History

2012-10-13 09:29:48 +00:00
# coding: utf-8
2012-11-17 01:09:20 +00:00
from flask import Flask, request, session, flash, render_template, redirect, url_for
2012-10-13 09:29:48 +00:00
app = Flask(__name__)
app.secret_key = '?9huDM\\H'
import db
2012-11-17 17:09:35 +00:00
from user_manager import UserManager
2012-10-13 09:29:48 +00:00
@app.before_request
2012-11-17 01:09:20 +00:00
def init_and_login_check():
if request.path.startswith('/rest/'):
return
2012-11-17 01:09:20 +00:00
admin_count = db.User.query.filter(db.User.admin == True).count()
if admin_count == 0 and request.endpoint != 'add_user':
flash('Not configured. Please create the first admin user')
return redirect(url_for('add_user'))
2012-11-17 17:09:35 +00:00
if not (admin_count == 0 and request.endpoint == 'add_user') and request.endpoint != 'login':
should_login = False
if not session.get('userid'):
should_login = True
elif UserManager.get(session.get('userid'))[0] != UserManager.SUCCESS:
session.clear()
should_login = True
if should_login:
flash('Please login')
return redirect(url_for('login', returnUrl = request.url[len(request.url_root)-1:]))
2012-11-17 01:09:20 +00:00
2012-10-13 09:29:48 +00:00
@app.teardown_request
def teardown(exception):
db.session.remove()
2012-10-13 09:29:48 +00:00
@app.route('/')
def index():
2012-11-17 17:30:30 +00:00
return render_template('home.html',
2012-10-13 12:53:09 +00:00
artists = db.Artist.query.order_by(db.Artist.name).all(),
albums = db.Album.query.join(db.Album.artist).order_by(db.Artist.name, db.Album.name).all())
@app.route('/resetdb')
def reset_db():
db.recreate_db()
return redirect(url_for('index'))
2012-10-13 09:29:48 +00:00
import user
2012-11-17 17:30:30 +00:00
import folder
2012-10-13 09:29:48 +00:00
import api.system
import api.browse
2012-10-14 17:04:39 +00:00
import api.user
import api.albums_songs
2012-10-20 18:05:39 +00:00
import api.media
2012-10-13 09:29:48 +00:00