fmatituy/selectospromanager
0
1import datetime, json, os2 3class RepositoryState:4 def __init__(self):5 self.field_refs = {} 6 self.config_path = os.path.join(os.path.dirname(__file__), 'sst_form_state.json')7 self.reset()8 self.load_from_disk()9 10 def reset(self):11 self.search_query = ""12 self.excel_template_path = None13 self.excel_template_name = ""14 self.current_draft_id = None15 self.form_data = {16 'fecha': datetime.date.today().strftime('%Y-%m-%d'),17 'hora_inicio': '',18 'hora_fin': '',19 'h_iam': False, 'h_ipm': False, 'h_fam': False, 'h_fpm': False20 } 21 self.current_project_id = None22 self.current_activity_id = None23 self.current_activity_name = None24 self.current_template_id = None25 self.current_solicitud_id = None26 self.current_document_id = None27 self.assigned_crew_ids = None 28 self.editing_area = False29 self.current_mapping_type = "Excavación y Demolición"30 self.busy_updating = False 31 self.lista_empleados = []32 self.stepper_ui = None33 self.existing_permits_for_act = []34 35 def save_to_disk(self):36 try:37 # Solo guardamos form_data para persistir imágenes y campos fijos38 with open(self.config_path, 'w', encoding='utf-8') as f:39 json.dump(self.form_data, f, ensure_ascii=False, indent=2)40 except Exception as e:41 print(f"Error saving state: {e}")42 43 def load_from_disk(self):44 if os.path.exists(self.config_path):45 try:46 with open(self.config_path, 'r', encoding='utf-8') as f:47 saved_data = json.load(f)48 # Actualizamos el form_data sin perder la fecha actual si no hay guardada en el json49 self.form_data.update(saved_data)50 # Pero forzamos que la fecha sea la de hoy si el json es viejo51 self.form_data['fecha'] = datetime.date.today().strftime('%Y-%m-%d')52 except Exception as e:53 print(f"Error loading state: {e}")54 55state = RepositoryState()56 