Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactoring code
  • Loading branch information
proost committed Feb 16, 2017
1 parent dd0570e commit 1bada7a
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 112 deletions.
221 changes: 110 additions & 111 deletions planet/__init__.py
Expand Up @@ -40,33 +40,7 @@ def create_app(config):


app.config.from_object(config) app.config.from_object(config)


db.app = app configure_extensions(app)
db.init_app(app)

# Enable login manager

login_manager.init_app(app)
login_manager.login_view = 'auth.login'

# Enable cach
cache.init_app(app)

# Enable Compress
compress.init_app(app)

# Enable HTMLMIN
htmlmin.init_app(app)

# Enable DebugToolBar
toolbar.init_app(app)

LOGIN_ENABLED = app.config['LOGIN_ENABLED']
BLAST_ENABLED = app.config['BLAST_ENABLED']
TWITTER_HANDLE = app.config['TWITTER_HANDLE'] if 'TWITTER_HANDLE' in app.config.keys() else None

# Enable BLAST
if BLAST_ENABLED:
blast_thread.init_app(app)


# Import all models here # Import all models here
from planet.models.users import User from planet.models.users import User
Expand Down Expand Up @@ -96,59 +70,10 @@ def create_app(config):
from planet.models.relationships.sequence_xref import SequenceXRefAssociation from planet.models.relationships.sequence_xref import SequenceXRefAssociation
from planet.models.relationships.family_xref import FamilyXRefAssociation from planet.models.relationships.family_xref import FamilyXRefAssociation


# Import controllers and register as blueprint configure_blueprints(app)
from planet.controllers.main import main
from planet.controllers.auth import auth, no_login
from planet.controllers.blast import blast
from planet.controllers.sequence import sequence
from planet.controllers.species import species
from planet.controllers.go import go
from planet.controllers.interpro import interpro
from planet.controllers.family import family
from planet.controllers.expression_cluster import expression_cluster
from planet.controllers.expression_profile import expression_profile
from planet.controllers.expression_network import expression_network
from planet.controllers.search import search
from planet.controllers.help import help
from planet.controllers.heatmap import heatmap
from planet.controllers.profile_comparison import profile_comparison
from planet.controllers.custom_network import custom_network
from planet.controllers.graph_comparison import graph_comparison
from planet.controllers.clade import clade
from planet.controllers.ecc import ecc
from planet.controllers.specificity_comparison import specificity_comparison
from planet.controllers.admin.controls import admin_controls

app.register_blueprint(main)
if LOGIN_ENABLED:
app.register_blueprint(auth, url_prefix='/auth')
app.register_blueprint(admin_controls, url_prefix='/admin_controls')
else:
app.register_blueprint(no_login, url_prefix='/auth')
app.register_blueprint(no_login, url_prefix='/admin_controls')

if BLAST_ENABLED:
app.register_blueprint(blast, url_prefix='/blast')

app.register_blueprint(sequence, url_prefix='/sequence')
app.register_blueprint(species, url_prefix='/species')
app.register_blueprint(go, url_prefix='/go')
app.register_blueprint(interpro, url_prefix='/interpro')
app.register_blueprint(family, url_prefix='/family')
app.register_blueprint(expression_cluster, url_prefix='/cluster')
app.register_blueprint(expression_profile, url_prefix='/profile')
app.register_blueprint(expression_network, url_prefix='/network')
app.register_blueprint(search, url_prefix='/search')
app.register_blueprint(help, url_prefix='/help')
app.register_blueprint(heatmap, url_prefix='/heatmap')
app.register_blueprint(profile_comparison, url_prefix='/profile_comparison')
app.register_blueprint(custom_network, url_prefix='/custom_network')
app.register_blueprint(graph_comparison, url_prefix='/graph_comparison')
app.register_blueprint(clade, url_prefix='/clade')
app.register_blueprint(ecc, url_prefix='/ecc')
app.register_blueprint(specificity_comparison, url_prefix='/specificity_comparison')


# Admin panel # Admin panel
LOGIN_ENABLED = app.config['LOGIN_ENABLED']
if LOGIN_ENABLED: if LOGIN_ENABLED:
from planet.controllers.admin.views import MyAdminIndexView from planet.controllers.admin.views import MyAdminIndexView
from planet.controllers.admin.views import SpeciesAdminView, GeneFamilyMethodAdminView, ExpressionNetworkMethodAdminView, \ from planet.controllers.admin.views import SpeciesAdminView, GeneFamilyMethodAdminView, ExpressionNetworkMethodAdminView, \
Expand Down Expand Up @@ -251,30 +176,108 @@ def create_app(config):
admin.add_view(ExpressionSpecificityMethodAdminView(ExpressionSpecificityMethod, db.session, url='specificity/', admin.add_view(ExpressionSpecificityMethodAdminView(ExpressionSpecificityMethod, db.session, url='specificity/',
category="Browse", name='Expression Specificity')) category="Browse", name='Expression Specificity'))


configure_error_handlers(app)

configure_hooks(app)

return app


def configure_extensions(app):
db.app = app
db.init_app(app)

# Enable login manager

login_manager.init_app(app)
login_manager.login_view = 'auth.login'

# Enable cach
cache.init_app(app)

# Enable Compress
compress.init_app(app)

# Enable HTMLMIN
htmlmin.init_app(app)

# Enable DebugToolBar
toolbar.init_app(app)

BLAST_ENABLED = app.config['BLAST_ENABLED']

# Enable BLAST
if BLAST_ENABLED:
blast_thread.init_app(app)

from planet.models.users import User

@login_manager.user_loader
def load_user(user_id):
return User.get(user_id)

@login_manager.unauthorized_handler
def unauthorized():
return render_template('error/403.html'), 403


def configure_blueprints(app):
# Import controllers and register as blueprint
from planet.controllers.main import main
from planet.controllers.auth import auth, no_login
from planet.controllers.blast import blast
from planet.controllers.sequence import sequence
from planet.controllers.species import species
from planet.controllers.go import go
from planet.controllers.interpro import interpro
from planet.controllers.family import family
from planet.controllers.expression_cluster import expression_cluster
from planet.controllers.expression_profile import expression_profile
from planet.controllers.expression_network import expression_network
from planet.controllers.search import search
from planet.controllers.help import help
from planet.controllers.heatmap import heatmap
from planet.controllers.profile_comparison import profile_comparison
from planet.controllers.custom_network import custom_network
from planet.controllers.graph_comparison import graph_comparison
from planet.controllers.clade import clade
from planet.controllers.ecc import ecc
from planet.controllers.specificity_comparison import specificity_comparison
from planet.controllers.admin.controls import admin_controls

LOGIN_ENABLED = app.config['LOGIN_ENABLED']
BLAST_ENABLED = app.config['LOGIN_ENABLED']

app.register_blueprint(main)
if LOGIN_ENABLED:
app.register_blueprint(auth, url_prefix='/auth')
app.register_blueprint(admin_controls, url_prefix='/admin_controls')
else:
app.register_blueprint(no_login, url_prefix='/auth')
app.register_blueprint(no_login, url_prefix='/admin_controls')


# ______________________________ if BLAST_ENABLED:
# < Beware, code overrides below > app.register_blueprint(blast, url_prefix='/blast')
# ------------------------------
# \ , ,
# \ /( )`
# \ \ \___ / |
# /- _ `-/ '
# (/\/ \ \ /\
# / / | ` \
# O O ) / |
# `-^--'`< '
# (_.) _ ) /
# `.___/` /
# `-----' /
# <----. __ / __ \
# <----|====O)))==) \) /====
# <----' `--' `.__,' \
# | |
# \ /
# ______( (_ / \______
# ,' ,-----' | \
# `--{__________) \/


app.register_blueprint(sequence, url_prefix='/sequence')
app.register_blueprint(species, url_prefix='/species')
app.register_blueprint(go, url_prefix='/go')
app.register_blueprint(interpro, url_prefix='/interpro')
app.register_blueprint(family, url_prefix='/family')
app.register_blueprint(expression_cluster, url_prefix='/cluster')
app.register_blueprint(expression_profile, url_prefix='/profile')
app.register_blueprint(expression_network, url_prefix='/network')
app.register_blueprint(search, url_prefix='/search')
app.register_blueprint(help, url_prefix='/help')
app.register_blueprint(heatmap, url_prefix='/heatmap')
app.register_blueprint(profile_comparison, url_prefix='/profile_comparison')
app.register_blueprint(custom_network, url_prefix='/custom_network')
app.register_blueprint(graph_comparison, url_prefix='/graph_comparison')
app.register_blueprint(clade, url_prefix='/clade')
app.register_blueprint(ecc, url_prefix='/ecc')
app.register_blueprint(specificity_comparison, url_prefix='/specificity_comparison')

def configure_error_handlers(app):
# Custom error handler for 404 errors # Custom error handler for 404 errors


@app.errorhandler(405) @app.errorhandler(405)
Expand All @@ -289,9 +292,15 @@ def page_not_found(e):
def access_denied(e): def access_denied(e):
return render_template('error/403.html'), 403 return render_template('error/403.html'), 403



def configure_hooks(app):
# Register form for basic searches, needs to be done here as it is included on every page! # Register form for basic searches, needs to be done here as it is included on every page!
from planet.forms.search import BasicSearchForm from planet.forms.search import BasicSearchForm


LOGIN_ENABLED = app.config['LOGIN_ENABLED']
BLAST_ENABLED = app.config['BLAST_ENABLED']
TWITTER_HANDLE = app.config['TWITTER_HANDLE'] if 'TWITTER_HANDLE' in app.config.keys() else None

@app.before_request @app.before_request
def before_request(): def before_request():
g.login_enabled = LOGIN_ENABLED g.login_enabled = LOGIN_ENABLED
Expand All @@ -306,14 +315,4 @@ def before_request():
g.msg = app.config['GLOB_MSG'] g.msg = app.config['GLOB_MSG']
g.msg_title = app.config['GLOB_MSG_TITLE'] if 'GLOB_MSG_TITLE' in app.config else 'info' g.msg_title = app.config['GLOB_MSG_TITLE'] if 'GLOB_MSG_TITLE' in app.config else 'info'
else: else:
g.msg = None g.msg = None

@login_manager.user_loader
def load_user(user_id):
return User.get(user_id)

@login_manager.unauthorized_handler
def unauthorized():
return render_template('error/403.html'), 403

return app
2 changes: 1 addition & 1 deletion run_unittest.py
Expand Up @@ -4,7 +4,7 @@
import unittest import unittest
import os import os


cov = coverage(branch=True, omit=['virtualenv/*', 'tests/*', 'config.py', 'utils/benchmark.py']) cov = coverage(branch=True, omit=['venv/*', 'tests/*', 'config.py', 'utils/benchmark.py'])
cov.start() cov.start()




Expand Down

0 comments on commit 1bada7a

Please sign in to comment.