Fix upload detection for model class names and add States/Printers/Setup import
- Enhanced get_import_type_from_filename() to recognize model class names (LegacyFile, FilesR, etc.) in addition to legacy CSV names - Added import functions for States, Printers, and Setup reference tables - Updated VALID_IMPORT_TYPES and IMPORT_ORDER to include new tables - Updated admin panel table counts to display new reference tables - Created UPLOAD_FIX.md documentation explaining the changes and how to handle existing unknown files This fixes the issue where files uploaded with model class names (e.g., LegacyFile.csv) were being categorized as 'unknown' instead of being properly detected.
This commit is contained in:
81
app/main.py
81
app/main.py
@@ -246,7 +246,7 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
VALID_IMPORT_TYPES: List[str] = [
|
||||
# Reference tables
|
||||
'trnstype', 'trnslkup', 'footers', 'filestat', 'employee',
|
||||
'gruplkup', 'filetype', 'fvarlkup', 'rvarlkup',
|
||||
'gruplkup', 'filetype', 'fvarlkup', 'rvarlkup', 'states', 'printers', 'setup',
|
||||
# Core data tables
|
||||
'rolodex', 'phone', 'rolex_v', 'files', 'files_r', 'files_v',
|
||||
'filenots', 'ledger', 'deposits', 'payments',
|
||||
@@ -259,11 +259,11 @@ VALID_IMPORT_TYPES: List[str] = [
|
||||
# Centralized import order for auto-import after upload
|
||||
# Reference tables first, then core tables, then specialized tables
|
||||
IMPORT_ORDER: List[str] = [
|
||||
# Reference tables
|
||||
'trnstype', 'trnslkup', 'footers', 'filestat', 'employee', 'gruplkup', 'filetype', 'fvarlkup', 'rvarlkup',
|
||||
# Core tables
|
||||
# Reference tables - import these first
|
||||
'trnstype', 'trnslkup', 'footers', 'filestat', 'employee', 'gruplkup', 'filetype', 'fvarlkup', 'rvarlkup', 'states', 'printers', 'setup',
|
||||
# Core tables - import after reference tables
|
||||
'rolodex', 'phone', 'rolex_v', 'files', 'files_r', 'files_v', 'filenots', 'ledger', 'deposits', 'payments',
|
||||
# Specialized tables
|
||||
# Specialized tables - import last
|
||||
'planinfo', 'qdros', 'pensions', 'pension_marriage', 'pension_death', 'pension_schedule', 'pension_separate', 'pension_results',
|
||||
]
|
||||
ORDER_INDEX: Dict[str, int] = {t: i for i, t in enumerate(IMPORT_ORDER)}
|
||||
@@ -272,6 +272,9 @@ ORDER_INDEX: Dict[str, int] = {t: i for i, t in enumerate(IMPORT_ORDER)}
|
||||
def get_import_type_from_filename(filename: str) -> str:
|
||||
"""
|
||||
Determine import type based on filename pattern for legacy CSV files.
|
||||
|
||||
Supports both legacy CSV naming (e.g., FILES.csv, LEDGER.csv) and
|
||||
model class naming (e.g., LegacyFile.csv, Ledger.csv).
|
||||
|
||||
Args:
|
||||
filename: Name of the uploaded CSV file
|
||||
@@ -294,7 +297,7 @@ def get_import_type_from_filename(filename: str) -> str:
|
||||
return 'filestat'
|
||||
if 'EMPLOYEE' in base:
|
||||
return 'employee'
|
||||
if 'GRUPLKUP' in base or 'GROUPLKUP' in base:
|
||||
if 'GRUPLKUP' in base or 'GROUPLKUP' in base or base == 'GROUPLKUP':
|
||||
return 'gruplkup'
|
||||
if 'FILETYPE' in base:
|
||||
return 'filetype'
|
||||
@@ -302,27 +305,53 @@ def get_import_type_from_filename(filename: str) -> str:
|
||||
return 'fvarlkup'
|
||||
if 'RVARLKUP' in base:
|
||||
return 'rvarlkup'
|
||||
if 'STATES' in base or base == 'STATES':
|
||||
return 'states'
|
||||
if 'PRINTERS' in base or base == 'PRINTERS':
|
||||
return 'printers'
|
||||
if 'SETUP' in base or base == 'SETUP':
|
||||
return 'setup'
|
||||
|
||||
# Core data tables
|
||||
# Core data tables - check most specific patterns first
|
||||
# Check for ROLEX_V and ROLEXV before ROLEX
|
||||
if 'ROLEX_V' in base or 'ROLEXV' in base:
|
||||
return 'rolex_v'
|
||||
if 'ROLODEX' in base or 'ROLEX' in base:
|
||||
return 'rolodex'
|
||||
|
||||
# Check for FILES_R, FILES_V, FILENOTS before generic FILES
|
||||
if 'FILES_R' in base or 'FILESR' in base:
|
||||
return 'files_r'
|
||||
if 'FILES_V' in base or 'FILESV' in base:
|
||||
return 'files_v'
|
||||
if 'FILENOTS' in base or 'FILE_NOTS' in base:
|
||||
if 'FILENOTS' in base or 'FILE_NOTS' in base or base == 'FILENOTS':
|
||||
return 'filenots'
|
||||
if 'FILES' in base or 'FILE' in base:
|
||||
|
||||
# Check for model class name "LEGACYFILE" before generic "FILE"
|
||||
if base == 'LEGACYFILE':
|
||||
return 'files'
|
||||
if 'PHONE' in base:
|
||||
if 'FILES' in base:
|
||||
return 'files'
|
||||
# Only match generic "FILE" if it's the exact base name or starts with it
|
||||
if base == 'FILE' or base.startswith('FILE_'):
|
||||
return 'files'
|
||||
|
||||
# ROLODEX variations
|
||||
if 'ROLODEX' in base or base == 'ROLEX':
|
||||
return 'rolodex'
|
||||
|
||||
# PHONE variations (including model class name LEGACYPHONE)
|
||||
if 'PHONE' in base or base == 'LEGACYPHONE':
|
||||
return 'phone'
|
||||
|
||||
# LEDGER
|
||||
if 'LEDGER' in base:
|
||||
return 'ledger'
|
||||
|
||||
# DEPOSITS
|
||||
if 'DEPOSITS' in base or 'DEPOSIT' in base:
|
||||
return 'deposits'
|
||||
if 'PAYMENTS' in base or 'PAYMENT' in base:
|
||||
|
||||
# PAYMENTS (including model class name LEGACYPAYMENT)
|
||||
if 'PAYMENTS' in base or 'PAYMENT' in base or base == 'LEGACYPAYMENT':
|
||||
return 'payments'
|
||||
|
||||
# Specialized tables
|
||||
@@ -330,17 +359,23 @@ def get_import_type_from_filename(filename: str) -> str:
|
||||
return 'planinfo'
|
||||
if 'QDROS' in base or 'QDRO' in base:
|
||||
return 'qdros'
|
||||
if 'MARRIAGE' in base:
|
||||
|
||||
# Pension sub-tables - check most specific first
|
||||
if 'MARRIAGE' in base or base == 'PENSIONMARRIAGE':
|
||||
return 'pension_marriage'
|
||||
if 'DEATH' in base:
|
||||
if 'DEATH' in base or base == 'PENSIONDEATH':
|
||||
return 'pension_death'
|
||||
if 'SCHEDULE' in base:
|
||||
if 'SCHEDULE' in base or base == 'PENSIONSCHEDULE':
|
||||
return 'pension_schedule'
|
||||
if 'SEPARATE' in base:
|
||||
if 'SEPARATE' in base or base == 'PENSIONSEPARATE':
|
||||
return 'pension_separate'
|
||||
if 'RESULTS' in base:
|
||||
if 'RESULTS' in base or base == 'PENSIONRESULTS':
|
||||
return 'pension_results'
|
||||
if 'PENSIONS' in base or 'PENSION' in base:
|
||||
|
||||
# Generic PENSIONS - check last after specific pension tables
|
||||
if 'PENSIONS' in base or base == 'PENSIONS':
|
||||
return 'pensions'
|
||||
if base == 'PENSION':
|
||||
return 'pensions'
|
||||
|
||||
raise ValueError(f"Unknown file type for filename: {filename}")
|
||||
@@ -1050,6 +1085,9 @@ def process_csv_import(db: Session, import_type: str, file_path: str) -> Dict[st
|
||||
'filetype': import_legacy.import_filetype,
|
||||
'fvarlkup': import_legacy.import_fvarlkup,
|
||||
'rvarlkup': import_legacy.import_rvarlkup,
|
||||
'states': import_legacy.import_states,
|
||||
'printers': import_legacy.import_printers,
|
||||
'setup': import_legacy.import_setup,
|
||||
|
||||
# Core data tables
|
||||
'rolodex': import_legacy.import_rolodex,
|
||||
@@ -2146,7 +2184,7 @@ async def admin_panel(request: Request, db: Session = Depends(get_db)):
|
||||
Footers, FileStat, Employee, GroupLkup, FileType,
|
||||
Qdros, PlanInfo, Pensions, PensionMarriage, PensionDeath,
|
||||
PensionSchedule, PensionSeparate, PensionResults,
|
||||
RolexV, FVarLkup, RVarLkup,
|
||||
RolexV, FVarLkup, RVarLkup, States, Printers, Setup,
|
||||
# Modern tables
|
||||
Client, Phone, Case, Transaction, Payment, Document
|
||||
)
|
||||
@@ -2162,6 +2200,9 @@ async def admin_panel(request: Request, db: Session = Depends(get_db)):
|
||||
'FileType': db.query(FileType).count(),
|
||||
'FVarLkup': db.query(FVarLkup).count(),
|
||||
'RVarLkup': db.query(RVarLkup).count(),
|
||||
'States': db.query(States).count(),
|
||||
'Printers': db.query(Printers).count(),
|
||||
'Setup': db.query(Setup).count(),
|
||||
},
|
||||
'core': {
|
||||
'Rolodex': db.query(Rolodex).count(),
|
||||
|
||||
Reference in New Issue
Block a user