from flask import session, render_template, Blueprint

from lexos.helpers import constants
from lexos.managers import session_manager
from lexos.models.dendro_model import DendrogramModel
from lexos.models.filemanager_model import FileManagerModel
from lexos.views.base_view import detect_active_docs

# this is a flask blue print
# it helps us to manage groups of views
# see here for more detail:
# http://exploreflask.com/en/latest/blueprints.html
# http://flask.pocoo.org/docs/0.12/blueprints/
dendrogram_blueprint = Blueprint('dendrogram', __name__)


@dendrogram_blueprint.route("/dendrogram", methods=['GET'])
def dendrogram():
    # Detect the number of active documents.
    num_active_docs = detect_active_docs()
    if 'analyoption' not in session:
        session['analyoption'] = constants.DEFAULT_ANALYZE_OPTIONS
    if 'hierarchyoption' not in session:
        session['hierarchyoption'] = constants.DEFAULT_HIERARCHICAL_OPTIONS
    labels = FileManagerModel().load_file_manager().get_active_labels()
    return render_template(
        'dendrogram.html',
        labels=labels,
        numActiveDocs=num_active_docs,
        itm="hierarchical")


@dendrogram_blueprint.route("/dendrogramDiv", methods=['POST'])
def dendrogram_div():
    """Send the dendrogram div that is generated by plotly to frontend

    :return: an html string of the dendrogram div
    """
    session_manager.cache_analysis_option()
    session_manager.cache_hierarchy_option()
    return DendrogramModel().get_dendrogram_div()

from flask import session, render_template, Blueprint

from lexos.helpers import constants
from lexos.managers import session_manager
from lexos.models.dendro_model import DendrogramModel
from lexos.models.filemanager_model import FileManagerModel
from lexos.views.base_view import detect_active_docs

# this is a flask blue print
# it helps us to manage groups of views
# see here for more detail:
# http://exploreflask.com/en/latest/blueprints.html
# http://flask.pocoo.org/docs/0.12/blueprints/
dendrogram_blueprint = Blueprint('dendrogram', __name__)


@dendrogram_blueprint.route("/dendrogram", methods=['GET'])
def dendrogram():
    # Detect the number of active documents.
    num_active_docs = detect_active_docs()
    if 'analyoption' not in session:
        session['analyoption'] = constants.DEFAULT_ANALYZE_OPTIONS
    if 'hierarchyoption' not in session:
        session['hierarchyoption'] = constants.DEFAULT_HIERARCHICAL_OPTIONS
    labels = FileManagerModel().load_file_manager().get_active_labels()
    return render_template(
        'dendrogram.html',
        labels=labels,
        numActiveDocs=num_active_docs)


@dendrogram_blueprint.route("/dendrogramDiv", methods=['POST'])
def dendrogram_div():
    """Send the dendrogram div that is generated by plotly to frontend

    :return: an html string of the dendrogram div
    """
    session_manager.cache_analysis_option()
    session_manager.cache_hierarchy_option()
    return DendrogramModel().get_dendrogram_div()

remove the itm