From 4ce3958cbbe751c18e2bbcc101af1aa84a04d187 Mon Sep 17 00:00:00 2001 From: spl0k Date: Tue, 4 Mar 2014 22:56:53 +0100 Subject: [PATCH] Reworked imports --- api/__init__.py | 10 ++++++ api/annotation.py | 2 +- api/browse.py | 2 +- api/media.py | 2 +- frontend/__init__.py | 55 +++++++++++++++++++++++++++++ folder.py => frontend/folder.py | 0 playlist.py => frontend/playlist.py | 0 user.py => frontend/user.py | 0 web.py | 44 ++--------------------- 9 files changed, 70 insertions(+), 45 deletions(-) create mode 100644 frontend/__init__.py rename folder.py => frontend/folder.py (100%) rename playlist.py => frontend/playlist.py (100%) rename user.py => frontend/user.py (100%) diff --git a/api/__init__.py b/api/__init__.py index 4072a2f..d4bdc90 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -190,3 +190,13 @@ def get_entity(req, ent, param = 'id'): return True, entity +from .system import * +from .browse import * +from .user import * +from .albums_songs import * +from .media import * +from .annotation import * +from .chat import * +from .search import * +from .playlists import * + diff --git a/api/annotation.py b/api/annotation.py index 406cbe5..39943cb 100644 --- a/api/annotation.py +++ b/api/annotation.py @@ -22,7 +22,7 @@ import time import uuid from flask import request from web import app -from api import get_entity +from . import get_entity from lastfm import LastFm from db import * diff --git a/api/browse.py b/api/browse.py index f6d15e1..c5ffd5c 100644 --- a/api/browse.py +++ b/api/browse.py @@ -21,7 +21,7 @@ from flask import request from web import app from db import Folder, Artist, Album, Track -from api import get_entity +from . import get_entity import uuid, time, string @app.route('/rest/getMusicFolders.view', methods = [ 'GET', 'POST' ]) diff --git a/api/media.py b/api/media.py index 5bf5154..3ff1be2 100644 --- a/api/media.py +++ b/api/media.py @@ -29,7 +29,7 @@ from xml.etree import ElementTree import config, scanner from web import app from db import Track, Album, Artist, Folder, User, ClientPrefs, now, session -from api import get_entity +from . import get_entity from sqlalchemy import func diff --git a/frontend/__init__.py b/frontend/__init__.py new file mode 100644 index 0000000..ea1a21f --- /dev/null +++ b/frontend/__init__.py @@ -0,0 +1,55 @@ +# 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 . + +from web import app +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 + 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.script_root + request.url[len(request.url_root)-1:])) + +@app.route('/') +def index(): + stats = { + 'artists': db.Artist.query.count(), + 'albums': db.Album.query.count(), + 'tracks': db.Track.query.count() + } + return render_template('home.html', stats = stats, admin = UserManager.get(session.get('userid'))[1].admin) + +from .user import * +from .folder import * +from .playlist import * + diff --git a/folder.py b/frontend/folder.py similarity index 100% rename from folder.py rename to frontend/folder.py diff --git a/playlist.py b/frontend/playlist.py similarity index 100% rename from playlist.py rename to frontend/playlist.py diff --git a/user.py b/frontend/user.py similarity index 100% rename from user.py rename to frontend/user.py diff --git a/web.py b/web.py index 1495826..1ce3beb 100644 --- a/web.py +++ b/web.py @@ -23,33 +23,9 @@ from flask import Flask, request, session, flash, render_template, redirect, url import config -def login_check(): - if request.path.startswith('/rest/'): - return - - if 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.script_root + request.url[len(request.url_root)-1:])) - def teardown(exception): db.session.remove() -def index(): - stats = { - 'artists': db.Artist.query.count(), - 'albums': db.Album.query.count(), - 'tracks': db.Track.query.count() - } - return render_template('home.html', stats = stats, admin = UserManager.get(session.get('userid'))[1].admin) - def create_application(): global app, db, UserManager @@ -72,26 +48,10 @@ def create_application(): handler.setLevel(logging.WARNING) app.logger.addHandler(handler) - from managers.user import UserManager - - app.before_request(login_check) app.teardown_request(teardown) - app.add_template_filter(str) - app.add_url_rule('/', view_func = index) - import user - import folder - import playlist - - import api.system - import api.browse - import api.user - import api.albums_songs - import api.media - import api.annotation - import api.chat - import api.search - import api.playlists + import frontend + import api return app