from flask_admin import Admin from requests import Session # type: ignore from src.config import ENVIRONMENT from src.constants import ENVS from src.db import db from src.external_clients.cms.client import CMSClient from src.external_clients.cms.client import Config as CMSConfig from src.models import Artist, Label, WeeklyReport from src.views import (ArtistView, HomeView, LabelView, LoginMenuLink, LogoutMenuLink, SignedArtistReportView, SyncView, UploadView) def init_app(app): admin = Admin( app, index_view=HomeView(name="Home", template="admin/index.html", url="/"), name="DNA CMS", template_mode="bootstrap3", ) admin.add_view(ArtistView(Artist, db.session, name='Artist', endpoint='/artist')) admin.add_view(LabelView(Label, db.session, name='Label', endpoint='/label')) admin.add_view(SignedArtistReportView( WeeklyReport, db.session, name='Signed Artist Report', endpoint='/signed_artist_report' )) admin.add_link(LoginMenuLink(name="Login", category="", url="/login")) admin.add_link(LogoutMenuLink(name="Logout", category="", url="/logout")) # sync and upload functional only for non prod environment if any(env in ENVIRONMENT for env in ENVS): from src.config import CMS_API_PROD_CONFIG admin.add_view(UploadView(name='Upload', endpoint='upload')) session = Session() cms_api = CMSClient(session=session, config=CMSConfig(**CMS_API_PROD_CONFIG)) admin.add_view(SyncView(name='Sync', endpoint='sync', cms_api=cms_api))