create Download report ui page commit
This commit is contained in:
@@ -52,7 +52,7 @@ class FileService:
|
||||
|
||||
# Manhole and Domestic Chamber Construction save
|
||||
if file_type == "manhole_domestic_chamber":
|
||||
return self.process_manhole_excavation(df, subcontractor_id)
|
||||
return self.process_manhole_domestic_chamber(df, subcontractor_id)
|
||||
|
||||
|
||||
return True, "File uploaded successfully."
|
||||
@@ -64,17 +64,12 @@ class FileService:
|
||||
|
||||
# Trench Excavation save method (TrenchExcavation model)
|
||||
def process_trench_excavation(self, df, subcontractor_id):
|
||||
|
||||
# Clean column names (strip whitespace)
|
||||
df.columns = [str(c).strip() for c in df.columns]
|
||||
|
||||
# If the sheet has merged cells -> forward fill Location
|
||||
if "Location" in df.columns:
|
||||
df["Location"] = df["Location"].ffill()
|
||||
|
||||
# REMOVE empty rows
|
||||
df = df.dropna(how="all")
|
||||
|
||||
df = df.dropna(how="all") # REMOVE empty rows
|
||||
# Identify missing location rows before insert
|
||||
missing_loc = df[df["Location"].isna() | (df["Location"].astype(str).str.strip() == "")]
|
||||
if not missing_loc.empty:
|
||||
@@ -84,14 +79,11 @@ class FileService:
|
||||
|
||||
try:
|
||||
for index, row in df.iterrows():
|
||||
|
||||
record_data = {}
|
||||
|
||||
# Insert only fields that exist in model
|
||||
for col in df.columns:
|
||||
if hasattr(TrenchExcavation, col):
|
||||
value = row[col]
|
||||
|
||||
# Normalize empty values
|
||||
if pd.isna(value) or str(value).strip() in ["", "-", "—", "nan", "NaN"]:
|
||||
value = None
|
||||
@@ -116,17 +108,14 @@ class FileService:
|
||||
|
||||
# Manhole Excavation save method (ManholeExcavation model)
|
||||
def process_manhole_excavation(self, df, subcontractor_id):
|
||||
|
||||
# Clean column names (strip whitespace)
|
||||
df.columns = [str(c).strip() for c in df.columns]
|
||||
|
||||
# If the sheet has merged cells -> forward fill Location
|
||||
if "Location" in df.columns:
|
||||
df["Location"] = df["Location"].ffill()
|
||||
|
||||
# REMOVE empty rows
|
||||
df = df.dropna(how="all")
|
||||
|
||||
# Identify missing location rows before insert
|
||||
missing_loc = df[df["Location"].isna() | (df["Location"].astype(str).str.strip() == "")]
|
||||
if not missing_loc.empty:
|
||||
@@ -136,9 +125,7 @@ class FileService:
|
||||
|
||||
try:
|
||||
for index, row in df.iterrows():
|
||||
|
||||
record_data = {}
|
||||
|
||||
# Insert only fields that exist in model
|
||||
for col in df.columns:
|
||||
if hasattr(ManholeExcavation, col):
|
||||
@@ -167,18 +154,15 @@ class FileService:
|
||||
|
||||
|
||||
# Manhole and Domestic Chamber Construction save method (ManholeDomesticChamber model)
|
||||
def process_manhole_excavation(self, df, subcontractor_id):
|
||||
|
||||
def process_manhole_domestic_chamber(self, df, subcontractor_id):
|
||||
# Clean column names (strip whitespace)
|
||||
df.columns = [str(c).strip() for c in df.columns]
|
||||
|
||||
# If the sheet has merged cells -> forward fill Location
|
||||
if "Location" in df.columns:
|
||||
df["Location"] = df["Location"].ffill()
|
||||
|
||||
# REMOVE empty rows
|
||||
df = df.dropna(how="all")
|
||||
|
||||
# Identify missing location rows before insert
|
||||
missing_loc = df[df["Location"].isna() | (df["Location"].astype(str).str.strip() == "")]
|
||||
if not missing_loc.empty:
|
||||
@@ -188,14 +172,12 @@ class FileService:
|
||||
|
||||
try:
|
||||
for index, row in df.iterrows():
|
||||
|
||||
record_data = {}
|
||||
|
||||
# Insert only fields that exist in model
|
||||
for col in df.columns:
|
||||
if hasattr(ManholeDomesticChamber, col):
|
||||
value = row[col]
|
||||
|
||||
# Normalize empty values
|
||||
if pd.isna(value) or str(value).strip() in ["", "-", "—", "nan", "NaN"]:
|
||||
value = None
|
||||
@@ -222,4 +204,3 @@ class FileService:
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user