Skip to content

Commit

Permalink
Issue #218: Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois-Werbrouck committed Nov 29, 2024
1 parent 4ecf7ed commit dd33d55
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 161 deletions.
21 changes: 15 additions & 6 deletions fertiscan/db/metadata/inspection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class Specifications(ValidatedModel):
fr: List[Specification]


# Awkwardly named so to avoid name conflict this represents the inspection object in the database
# and not the inspection object used as a form on the application
# Awkwardly named so to avoid name conflict this represents the inspection object in the database
# and not the inspection object used as a form on the application
class DBInspection(ValidatedModel):
id: UUID4
verified: bool = False
Expand Down Expand Up @@ -188,7 +188,7 @@ def build_inspection_import(analysis_form: dict,user_id) -> str:
website=org.get("website"),
phone_number=org.get("phone_number"),
edited=False,
is_main_contact = False
is_main_contact=False,
)
)

Expand Down Expand Up @@ -225,7 +225,6 @@ def build_inspection_import(analysis_form: dict,user_id) -> str:
record_keeping=None,
)


cautions = SubLabel(
en=analysis_form.get("cautions_en", []),
fr=analysis_form.get("cautions_fr", []),
Expand Down Expand Up @@ -360,12 +359,22 @@ def build_inspection_export(cursor, inspection_id) -> str:
metrics.density = metrics.density or Metric()
product_info.metrics = metrics

# Retrieve the registration numbers
reg_numbers = registration_number.get_registration_numbers_json(
cursor, label_info_id
)
reg_number_model_list = []
for reg_number in reg_numbers["registration_numbers"]:

reg_number_model_list.append(RegistrationNumber.model_validate(reg_number))
product_info.registration_numbers = reg_number_model_list

# get the organizations information (Company and Manufacturer)
orgs = organization.get_organizations_info_json(cursor, label_info_id)
org_list = []
if len(orgs["organizations"])>0:
if len(orgs["organizations"]) > 0:
for org in orgs["organizations"]:
org_list.append(OrganizationInformation.model_validate(org))
org_list.append(OrganizationInformation.model_validate(org))

# Get all the sub labels
sub_labels = sub_label.get_sub_label_json(cursor, label_info_id)
Expand Down
1 change: 1 addition & 0 deletions fertiscan/db/queries/inspection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def is_inspection_verified(cursor: Cursor, inspection_id):
"Failed to check inspection verification status. No data returned."
)


VERIFIED = 0
UPLOAD_DATE = 1
UPDATED_AT = 2
Expand Down
5 changes: 3 additions & 2 deletions fertiscan/db/queries/label/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def new_label_information(
title_en: str,
title_fr: str,
is_minimal: bool,
record_keeping:bool,
record_keeping: bool,
):
"""
This function create a new label_information in the database.
Expand Down Expand Up @@ -183,7 +183,8 @@ def get_label_dimension(cursor, label_id):
)
return data

def delete_label_info(cursor:Cursor, label_id:str):

def delete_label_info(cursor: Cursor, label_id: str):
"""
This function deletes a label information from the database.
Expand Down
35 changes: 28 additions & 7 deletions fertiscan/db/queries/organization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ def new_organization(cursor: Cursor, name, website, phone_number, address):

@handle_query_errors(OrganizationInformationCreationError)
def new_organization_information(
cursor: Cursor, address: str, name: str, website: str, phone_number: str, label_id: UUID, edited: bool = False, is_main_contact: bool = False
cursor: Cursor,
address: str,
name: str,
website: str,
phone_number: str,
label_id: UUID,
edited: bool = False,
is_main_contact: bool = False,
):
"""
This function create a new organization information in the database using function.
Expand All @@ -81,7 +88,9 @@ def new_organization_information(
- str: The UUID of the organization information
"""
if label_id is None:
raise OrganizationInformationCreationError("Label ID is required for organization information creation.")
raise OrganizationInformationCreationError(
"Label ID is required for organization information creation."
)
query = """
SELECT new_organization_information(%s, %s, %s, %s, %s, %s, %s);
"""
Expand All @@ -101,6 +110,7 @@ def new_organization_information(
return result[0]
raise OrganizationCreationError("Failed to create Organization. No data returned.")


@handle_query_errors(OrganizationInformationRetrievalError)
def get_organization_info(cursor: Cursor, information_id):
"""
Expand Down Expand Up @@ -134,6 +144,7 @@ def get_organization_info(cursor: Cursor, information_id):
"Organization information not found with information_id: " + information_id
)


def get_organizations_info_label(cursor: Cursor, label_id: UUID):
"""
This function get a organization information from the database.
Expand Down Expand Up @@ -188,7 +199,8 @@ def get_organizations_info_json(cursor: Cursor, label_id: UUID) -> dict:
raise OrganizationInformationRetrievalError(
"Failed to get Registration Numbers with the given label_id. No data returned."
)



def get_organization_json(cursor: Cursor, fertilizer_id: UUID) -> dict:
"""
This function get a organization information from the database.
Expand Down Expand Up @@ -217,9 +229,10 @@ def get_organization_json(cursor: Cursor, fertilizer_id: UUID) -> dict:
else:
return {}


@handle_query_errors(OrganizationInformationUpdateError)
def update_organization_info(
cursor: Cursor, information_id:UUID, name, website, phone_number
cursor: Cursor, information_id: UUID, name, website, phone_number
):
"""
This function update a organization information in the database.
Expand Down Expand Up @@ -255,6 +268,7 @@ def update_organization_info(
)
return information_id


def upsert_organization_info(cursor: Cursor, organization_info, label_id: UUID):
"""
This function upserts an organization information in the database.
Expand All @@ -269,9 +283,16 @@ def upsert_organization_info(cursor: Cursor, organization_info, label_id: UUID):
query = """
SELECT upsert_organization_info(%s, %s);
"""
cursor.execute(query, (organization_info, str(label_id),))
cursor.execute(
query,
(
organization_info,
str(label_id),
),
)
return cursor.fetchone()[0]


def upsert_organization(cursor: Cursor, organization_info_id: UUID):
"""
This function upserts an organization information in the database.
Expand All @@ -286,12 +307,12 @@ def upsert_organization(cursor: Cursor, organization_info_id: UUID):
query = """
SELECT upsert_organization(%s);
"""
cursor.execute(query, ( str(organization_info_id),))
cursor.execute(query, (str(organization_info_id),))
return cursor.fetchone()[0]


@handle_query_errors(OrganizationRetrievalError)
def get_organization(cursor: Cursor, organization_id:UUID):
def get_organization(cursor: Cursor, organization_id: UUID):
"""
This function get a organization from the database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def setUp(self):

self.inspection_id = inspection_data["inspection_id"]
self.label_info_id = inspection_data["product"]["label_id"]
#self.company_info_id = inspection_data["company"]["id"]
#self.manufacturer_info_id = inspection_data["manufacturer"]["id"]
# self.company_info_id = inspection_data["company"]["id"]
# self.manufacturer_info_id = inspection_data["manufacturer"]["id"]

# Update the inspection to verified true
inspection_data["verified"] = True
Expand Down
Loading

0 comments on commit dd33d55

Please sign in to comment.