Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18281 implement black #2286

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,38 @@
from .models.user import User, UserRoles



__all__ = ('db',
'Address', 'Alias', 'AlternateName', 'ColinEntity', 'ColinLastUpdate', 'Comment',
'ConsentContinuationOut', 'CorpType', 'DCConnection', 'DCDefinition', 'DCIssuedCredential', 'Document',
'DocumentType', 'EntityRole', 'Filing', 'LegalEntity', 'LegalEntityIdentifier', 'LegalEntityType',
'Office', 'OfficeType', 'Party', 'RegistrationBootstrap',
'RequestTracker', 'Resolution', 'RoleAddress', 'PartyRole', 'ShareClass', 'ShareSeries', 'User', 'UserRoles',
'NaicsStructure', 'NaicsElement',
)
__all__ = (
"db",
"Address",
"Alias",
"AlternateName",
"ColinEntity",
"ColinLastUpdate",
"Comment",
"ConsentContinuationOut",
"CorpType",
"DCConnection",
"DCDefinition",
"DCIssuedCredential",
"Document",
"DocumentType",
"EntityRole",
"Filing",
"LegalEntity",
"LegalEntityIdentifier",
"LegalEntityType",
"Office",
"OfficeType",
"Party",
"RegistrationBootstrap",
"RequestTracker",
"Resolution",
"RoleAddress",
"PartyRole",
"ShareClass",
"ShareSeries",
"User",
"UserRoles",
"NaicsStructure",
"NaicsElement",
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@


__all__ = (
'ApiConnectionException',
'BusinessException',
'ErrorCode',
'get_error_message',
"ApiConnectionException",
"BusinessException",
"ErrorCode",
"get_error_message",
)


class ApiConnectionException(Exception):
"""Api Connection exception."""

def __init__(self, code: int, detail: List[Dict]):
"""Initialize the error object."""
super(ApiConnectionException, self).__init__()
self.code = code
self.detail = detail
self.detail = detail
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@


__all__ = (
'ErrorCode',
'get_error_message',
"ErrorCode",
"get_error_message",
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
class AutoName(str, Enum):
"""Replace autoname from Enum class."""

#pragma warning disable S5720; # noqa: E265
# pragma warning disable S5720; # noqa: E265
# disable sonar cloud complaining about this signature
def _generate_next_value_(name, start, count, last_values): # pylint: disable=W0221,E0213 # noqa: N805
def _generate_next_value_(
name, start, count, last_values
): # pylint: disable=W0221,E0213 # noqa: N805
"""Return the name of the key, but in lowercase."""
return name.lower()
#pragma warning enable S5720; # noqa: E265

# pragma warning enable S5720; # noqa: E265


class ErrorCode(AutoName):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


ERROR_MESSAGES: dict = {
ErrorCode.MISSING_BUSINESS: 'Business not found for identifier: {identifier}',
ErrorCode.FILING_NOT_FOUND: 'Filing: {filing_id} not found for: {identifier}',
ErrorCode.NOT_AUTHORIZED: 'Not authorized to access business: {identifier}',
ErrorCode.MISSING_BUSINESS: "Business not found for identifier: {identifier}",
ErrorCode.FILING_NOT_FOUND: "Filing: {filing_id} not found for: {identifier}",
ErrorCode.NOT_AUTHORIZED: "Not authorized to access business: {identifier}",
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,36 @@
from .user import User, UserRoles


__all__ = ('db',
'Address', 'Alias', 'AlternateName', 'ColinEntity', 'LegalEntity', 'ColinLastUpdate', 'Comment',
'ConsentContinuationOut', 'CorpType', 'DCConnection', 'DCDefinition', 'DCIssuedCredential', 'Document',
'DocumentType', 'EntityRole', 'Filing', 'Office', 'OfficeType', 'Party', 'RegistrationBootstrap',
'RequestTracker', 'Resolution', 'RoleAddress', 'PartyRole', 'ShareClass', 'ShareSeries', 'User', 'UserRoles',
'NaicsStructure', 'NaicsElement')
__all__ = (
"db",
"Address",
"Alias",
"AlternateName",
"ColinEntity",
"LegalEntity",
"ColinLastUpdate",
"Comment",
"ConsentContinuationOut",
"CorpType",
"DCConnection",
"DCDefinition",
"DCIssuedCredential",
"Document",
"DocumentType",
"EntityRole",
"Filing",
"Office",
"OfficeType",
"Party",
"RegistrationBootstrap",
"RequestTracker",
"Resolution",
"RoleAddress",
"PartyRole",
"ShareClass",
"ShareSeries",
"User",
"UserRoles",
"NaicsStructure",
"NaicsElement",
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,65 +31,69 @@ class Address(Versioned, db.Model): # pylint: disable=too-many-instance-attribu
and are in the ADDRESS_TYPES List for ease of checking.
"""

MAILING = 'mailing'
DELIVERY = 'delivery'
MAILING = "mailing"
DELIVERY = "delivery"
ADDRESS_TYPES = [MAILING, DELIVERY]
JSON_MAILING = 'mailingAddress'
JSON_DELIVERY = 'deliveryAddress'
JSON_MAILING = "mailingAddress"
JSON_DELIVERY = "deliveryAddress"
JSON_ADDRESS_TYPES = [JSON_MAILING, JSON_DELIVERY]

__tablename__ = 'addresses'
__tablename__ = "addresses"
__mapper_args__ = {
'include_properties': [
'id',
'address_type',
'legal_entity_id',
'city',
'change_filing_id',
'country',
'delivery_instructions',
'office_id',
'postal_code',
'region',
'street',
'street_additional',
"include_properties": [
"id",
"address_type",
"legal_entity_id",
"city",
"change_filing_id",
"country",
"delivery_instructions",
"office_id",
"postal_code",
"region",
"street",
"street_additional",
]
}

id = db.Column(db.Integer, primary_key=True)
address_type = db.Column('address_type', db.String(4096), index=True)
street = db.Column('street', db.String(4096), index=True)
street_additional = db.Column('street_additional', db.String(4096))
city = db.Column('city', db.String(4096))
region = db.Column('region', db.String(4096))
country = db.Column('country', db.String(2))
postal_code = db.Column('postal_code', db.String(15))
delivery_instructions = db.Column('delivery_instructions', db.String(4096))
address_type = db.Column("address_type", db.String(4096), index=True)
street = db.Column("street", db.String(4096), index=True)
street_additional = db.Column("street_additional", db.String(4096))
city = db.Column("city", db.String(4096))
region = db.Column("region", db.String(4096))
country = db.Column("country", db.String(2))
postal_code = db.Column("postal_code", db.String(15))
delivery_instructions = db.Column("delivery_instructions", db.String(4096))

# parent keys
legal_entity_id = db.Column('legal_entity_id',
db.Integer,
db.ForeignKey('legal_entities.id'),
index=True)
change_filing_id = db.Column('change_filing_id',
db.Integer,
db.ForeignKey('filings.id'),
index=True)
office_id = db.Column('office_id',
db.Integer,
db.ForeignKey('offices.id', ondelete='CASCADE'),
nullable=True)
legal_entity_id = db.Column(
"legal_entity_id", db.Integer, db.ForeignKey("legal_entities.id"), index=True
)
change_filing_id = db.Column(
"change_filing_id", db.Integer, db.ForeignKey("filings.id"), index=True
)
office_id = db.Column(
"office_id",
db.Integer,
db.ForeignKey("offices.id", ondelete="CASCADE"),
nullable=True,
)
# Relationships - Users
# business_mailing_address = db.relationship('Business',
# backref=backref('business_mailing_address', uselist=False),
# foreign_keys=[legal_entity_id])

legal_entity_delivery_address = db.relationship('LegalEntity',
back_populates='entity_delivery_address',
foreign_keys='LegalEntity.delivery_address_id')
legal_entity_mailing_address = db.relationship('LegalEntity',
back_populates='entity_mailing_address',
foreign_keys='LegalEntity.mailing_address_id')
legal_entity_delivery_address = db.relationship(
"LegalEntity",
back_populates="entity_delivery_address",
foreign_keys="LegalEntity.delivery_address_id",
)
legal_entity_mailing_address = db.relationship(
"LegalEntity",
back_populates="entity_mailing_address",
foreign_keys="LegalEntity.mailing_address_id",
)

def save(self):
"""Render a Business to the local cache."""
Expand All @@ -100,29 +104,31 @@ def save(self):
def json(self):
"""Return a dict of this object, with keys in JSON format."""
return {
'id': self.id,
'streetAddress': self.street,
'streetAddressAdditional': self.street_additional,
'addressType': self.address_type,
'addressCity': self.city,
'addressRegion': self.region,
'addressCountry': self.country,
'postalCode': self.postal_code,
'deliveryInstructions': self.delivery_instructions
"id": self.id,
"streetAddress": self.street,
"streetAddressAdditional": self.street_additional,
"addressType": self.address_type,
"addressCity": self.city,
"addressRegion": self.region,
"addressCountry": self.country,
"postalCode": self.postal_code,
"deliveryInstructions": self.delivery_instructions,
}

@staticmethod
def create_address(new_info: dict):
"""Create an address object from dict/json."""
address = Address()

address.street = new_info.get('streetAddress')
address.street_additional = new_info.get('streetAddressAdditional')
address.city = new_info.get('addressCity')
address.region = new_info.get('addressRegion')
address.country = pycountry.countries.search_fuzzy(new_info.get('addressCountry'))[0].alpha_2
address.postal_code = new_info.get('postalCode')
address.delivery_instructions = new_info.get('deliveryInstructions')
address.street = new_info.get("streetAddress")
address.street_additional = new_info.get("streetAddressAdditional")
address.city = new_info.get("addressCity")
address.region = new_info.get("addressRegion")
address.country = pycountry.countries.search_fuzzy(
new_info.get("addressCountry")
)[0].alpha_2
address.postal_code = new_info.get("postalCode")
address.delivery_instructions = new_info.get("deliveryInstructions")

return address

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,33 @@ class Alias(Versioned, db.Model): # pylint: disable=too-many-instance-attribute
class AliasType(Enum):
"""Render an Enum of the types of aliases."""

TRANSLATION = 'TRANSLATION'
DBA = 'DBA'
TRANSLATION = "TRANSLATION"
DBA = "DBA"

__tablename__ = 'aliases'
__tablename__ = "aliases"
__mapper_args__ = {
'include_properties': [
'id',
'alias',
'change_filing_id',
'legal_entity_id',
'type',
"include_properties": [
"id",
"alias",
"change_filing_id",
"legal_entity_id",
"type",
]
}

id = db.Column(db.Integer, primary_key=True)
alias = db.Column('alias', db.String(1000), index=True, nullable=False)
type = db.Column('type', db.String(20), default=AliasType.TRANSLATION, nullable=False)
alias = db.Column("alias", db.String(1000), index=True, nullable=False)
type = db.Column(
"type", db.String(20), default=AliasType.TRANSLATION, nullable=False
)

# parent keys
legal_entity_id = db.Column('legal_entity_id', db.Integer, db.ForeignKey('legal_entities.id'))
change_filing_id = db.Column('change_filing_id', db.Integer, db.ForeignKey('filings.id'), index=True)
legal_entity_id = db.Column(
"legal_entity_id", db.Integer, db.ForeignKey("legal_entities.id")
)
change_filing_id = db.Column(
"change_filing_id", db.Integer, db.ForeignKey("filings.id"), index=True
)

def save(self):
"""Save the object to the database immediately."""
Expand All @@ -57,11 +63,7 @@ def save(self):
@property
def json(self):
"""Return a dict of this object, with keys in JSON format."""
alias = {
'id': str(self.id),
'name': self.alias,
'type': self.type
}
alias = {"id": str(self.id), "name": self.alias, "type": self.type}
return alias

@classmethod
Expand All @@ -75,8 +77,10 @@ def find_by_id(cls, alias_id: int) -> Alias:
@classmethod
def find_by_type(cls, legal_entity_id: int, alias_type: str):
"""Return the aliases matching the type."""
aliases = db.session.query(Alias). \
filter(Alias.legal_entity_id == legal_entity_id). \
filter(Alias.type == alias_type). \
all()
aliases = (
db.session.query(Alias)
.filter(Alias.legal_entity_id == legal_entity_id)
.filter(Alias.type == alias_type)
.all()
)
return aliases
Loading
Loading