"""RomeConventionCountry and RomeConventionUnsigned Models. Model RomeConventionCountry and RomeConventionUnsigned use sqlalchemy. """ from oto import response from sqlalchemy import Column from sqlalchemy.dialects.mysql import SMALLINT from sqlalchemy.dialects.mysql import TINYINT from prs.connectors import mysql class RomeConventionCountry(mysql.ppb_model): """Table definition for rome_convention_country table.""" __tablename__ = 'rome_convention_country' country_id = Column( 'country_id', SMALLINT(unsigned=True), primary_key=True, nullable=False) active = Column( 'active', TINYINT(unsigned=True), nullable=False, default=1) class RomeConventionUnsigned(mysql.ppb_model): """Table definition for rome_convention_unsigned table.""" __tablename__ = 'rome_convention_unsigned' country_id = Column( 'country_id', SMALLINT(unsigned=True), primary_key=True, nullable=False) active = Column( 'active', TINYINT(unsigned=True), nullable=False, default=1) @mysql.wrap_db_errors def get_rome_convention_countries(): """Get the list of Rome Convention mandatory territories. Returns: response.Response: Response contains dict with list describing country id/ids. """ column = RomeConventionCountry.country_id return get_rome_convention_data(column) @mysql.wrap_db_errors def get_rome_convention_unsigned(): """Get territories that disregard the Rome Convention stipulations. Returns: response.Response: Response contains dict with list describing country id/ids. """ column = RomeConventionUnsigned.country_id return get_rome_convention_data(column) @mysql.wrap_db_errors def get_rome_convention_data(column): """Get Rome Convention related territories as per given column. Returns: response.Response: Response contains dict with list describing country id/ids based on given column. """ with mysql.ppb_db_session() as session: country_ids = session.query(column).filter_by(active=1).all() return response.Response(message={'country_ids': country_ids})