import os
from flask import jsonify, current_app, request
from sqlalchemy.exc import SQLAlchemyError

from . import status
from . import utils
from dmutils.status import get_flags


@status.route('/_status')
def status_no_db():

    if 'ignore-dependencies' in request.args:
        return jsonify(
            status="ok",
        ), 200

    version = current_app.config['VERSION']

    try:
        return jsonify(
            status="ok",
            version=version,
            db_version=utils.get_db_version(),
            flags=get_flags(current_app)
        )

    except SQLAlchemyError:
        current_app.logger.exception('Error connecting to database')
        return jsonify(
            status="error",
            version=version,
            message="Error connecting to database",
            flags=get_flags(current_app)
        ), 500

from flask import jsonify, current_app, request
from sqlalchemy.exc import SQLAlchemyError

from . import status
from . import utils
from ..models import Framework
from dmutils.status import get_flags


@status.route('/_status')
def status_no_db():

    if 'ignore-dependencies' in request.args:
        return jsonify(
            status="ok",
        ), 200

    version = current_app.config['VERSION']

    try:
        return jsonify(
            status="ok",
            frameworks={f.slug: f.status for f in Framework.query.all()},
            version=version,
            db_version=utils.get_db_version(),
            flags=get_flags(current_app)
        )

    except SQLAlchemyError:
        current_app.logger.exception('Error connecting to database')
        return jsonify(
            status="error",
            version=version,
            message="Error connecting to database",
            flags=get_flags(current_app)
        ), 500

Add framework status to API /_status
Add framework status to API /_status

To figure out current framework statuses for the given environment
you either need access to the API token or you'd have to look through
a number of frontend pages to infer the status from.

Framework status is a part of almost every request to the API, so
it should always be available for a working API instance and it makes
sense to add it to the /_status page.

Adding it to the /_status page creates an easier way to get the list
of all framework statuses.

- import os
  from flask import jsonify, current_app, request
  from sqlalchemy.exc import SQLAlchemyError
  
  from . import status
  from . import utils
+ from ..models import Framework
  from dmutils.status import get_flags
  
  
  @status.route('/_status')
  def status_no_db():
  
      if 'ignore-dependencies' in request.args:
          return jsonify(
              status="ok",
          ), 200
  
      version = current_app.config['VERSION']
  
      try:
          return jsonify(
              status="ok",
+             frameworks={f.slug: f.status for f in Framework.query.all()},
              version=version,
              db_version=utils.get_db_version(),
              flags=get_flags(current_app)
          )
  
      except SQLAlchemyError:
          current_app.logger.exception('Error connecting to database')
          return jsonify(
              status="error",
              version=version,
              message="Error connecting to database",
              flags=get_flags(current_app)
          ), 500
  
Add framework status to API /_status
## Code Before:
import os
from flask import jsonify, current_app, request
from sqlalchemy.exc import SQLAlchemyError

from . import status
from . import utils
from dmutils.status import get_flags


@status.route('/_status')
def status_no_db():

    if 'ignore-dependencies' in request.args:
        return jsonify(
            status="ok",
        ), 200

    version = current_app.config['VERSION']

    try:
        return jsonify(
            status="ok",
            version=version,
            db_version=utils.get_db_version(),
            flags=get_flags(current_app)
        )

    except SQLAlchemyError:
        current_app.logger.exception('Error connecting to database')
        return jsonify(
            status="error",
            version=version,
            message="Error connecting to database",
            flags=get_flags(current_app)
        ), 500

## Instruction:
Add framework status to API /_status
## Code After:
from flask import jsonify, current_app, request
from sqlalchemy.exc import SQLAlchemyError

from . import status
from . import utils
from ..models import Framework
from dmutils.status import get_flags


@status.route('/_status')
def status_no_db():

    if 'ignore-dependencies' in request.args:
        return jsonify(
            status="ok",
        ), 200

    version = current_app.config['VERSION']

    try:
        return jsonify(
            status="ok",
            frameworks={f.slug: f.status for f in Framework.query.all()},
            version=version,
            db_version=utils.get_db_version(),
            flags=get_flags(current_app)
        )

    except SQLAlchemyError:
        current_app.logger.exception('Error connecting to database')
        return jsonify(
            status="error",
            version=version,
            message="Error connecting to database",
            flags=get_flags(current_app)
        ), 500
