"""LabelBlacklist Model. This LabelBlacklist model is used to get information about bad labels. """ from oto import response from sqlalchemy import Column from sqlalchemy import SmallInteger from sqlalchemy.dialects.mysql import SMALLINT from prs.connectors import mysql class LabelBlacklist(mysql.ppb_model): """Table definition for label Blacklist table.""" __tablename__ = 'label_blacklist' bad_label_id = Column( SMALLINT(unsigned=True), primary_key=True, autoincrement=True, nullable=False) vendor_id = Column(SmallInteger, default=None, nullable=False) label_blacklist_type_id = Column(SMALLINT(unsigned=True), nullable=False) @mysql.wrap_db_errors def get_bad_label_ids_by_blacklist_type_id(blacklist_type_id_list): """Get bad label ids by blacklist type ids. Args: blacklist_type_id_list (list): Blacklist type ids for which bad label ids are required. Returns: response.Response: Response containing bad label ids. """ with mysql.ppb_db_session() as session: label_ids = session.query(LabelBlacklist.vendor_id).filter( LabelBlacklist.label_blacklist_type_id.in_( blacklist_type_id_list)).all() return response.Response(message={ 'label_ids': [tuple(label) for label in label_ids]})