Source code for

# -*- coding: utf-8 -*-
"""CherryPy Metadata Migration Class for Instrument Entities."""
from cherrypy import tools
from peewee import prefetch
from pacifica.metadata.orm import Projects
from pacifica.metadata.orm import ProjectInstrument, ProjectUser
from import QueryBase as ProjQueryBase

[docs]class MigrateProjects(object): """Generate a streamlined query for importing project entities and linkages.""" exposed = True
[docs] @staticmethod def generate_project_list(): """Generate project objects with linkages.""" project_list = {} proj_collection = (Projects .select() .order_by( .where(Projects.deleted.is_null())) instrument_collection = ( ).order_by(ProjectInstrument.instrument)) user_collection = ( ).order_by(ProjectUser.user)) projects_with_links = prefetch( proj_collection, instrument_collection, user_collection) for proj in projects_with_links: proj_entry = ProjQueryBase.format_project_block(proj) proj_entry['abstract'] = proj.abstract proj_entry['instruments'] = [ for inst in proj.instruments] proj_entry['users'] = [ for user_entry in proj.users] project_list[] = proj_entry return project_list
# CherryPy requires these named methods # pylint: disable=invalid-name
[docs] @staticmethod @tools.json_out() def GET(): """CherryPy GET Method.""" return MigrateProjects.generate_project_list()