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 Instruments
from pacifica.metadata.orm import ProjectInstrument
from import QueryBase as InstQueryBase

[docs]class MigrateInstruments(object): """Generate a streamlined query for importing instrument entities and linkages.""" exposed = True
[docs] @staticmethod def generate_instrument_list(): """Generate instrument objects with linkages.""" instrument_list = {} inst_collection = (Instruments .select(Instruments) .order_by( .where(Instruments.deleted.is_null())) project_collection = ( ).order_by(ProjectInstrument.project)) instruments_with_projects = prefetch( inst_collection, project_collection) for inst in instruments_with_projects: inst_entry = InstQueryBase.format_instrument_block(inst) inst_entry['projects'] = [ for proj in inst.projects] instrument_list[] = inst_entry return instrument_list
# CherryPy requires these named methods # pylint: disable=invalid-name
[docs] @staticmethod @tools.json_out() def GET(): """CherryPy GET Method.""" return MigrateInstruments.generate_instrument_list()