Changeset f8e1cf8 in flexograder


Ignore:
Timestamp:
11/10/25 15:10:39 (5 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
fake-data, main, master
Children:
7cc3672
Parents:
bc820cf
Message:

force utf-8 encoding for sessions

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • builder/exam_manager.py

    rbc820cf rf8e1cf8  
     1import json
     2from pathlib import Path
    13from builder.exam import Exam
    24from flexoentity import EntityState, EntityType, Domain
     
    2224        self.active_exam_id = exam.flexo_id
    2325        return exam
    24    
     26
    2527    @property
    2628    def exams(self):
    2729        return self._exams
    28    
     30
    2931    def add_exam(self, exam):
    3032        """Add an externally loaded Exam (e.g., from JSON)."""
    3133        self._exams[exam.flexo_id] = exam
    3234        self.active_exam_id = exam.flexo_id
    33        
     35
    3436    def list_exams(self):
    3537        return list(self.exams.keys())
    36    
     38
    3739    def list_titles(self):
    3840        """Return titles for GUI dropdowns."""
    3941        return [exam.title for exam in self._exams.values()]
    40    
     42
    4143    def get_active(self):
    4244        return self.exams.get(self.active_exam_id)
    43    
     45
    4446    def get_active_id(self) -> str | None:
    4547        return self.active_exam_id
     
    5456        for exam in self._exams.values():
    5557            if exam.title == title:
    56                 self.active_exam_id = exam.flexo_id.id
     58                self.active_exam_id = exam.flexo_id
    5759                return
    5860        raise ValueError(f"No exam with title '{title}' found")
     
    7173    def save_all(self, directory: str):
    7274        """Save all exams to JSON files in a given directory."""
    73         from pathlib import Path
    7475
    7576        directory = Path(directory)
    7677        directory.mkdir(parents=True, exist_ok=True)
    7778        for exam in self._exams.values():
    78             filename = directory / f"{exam.title}_{exam.flexo_id.id}.json"
     79            filename = directory / f"{exam.title}_{exam.flexo_id}.json"
    7980            exam.to_json_file(filename)
    8081
    8182    def load_all(self, directory: str):
    8283        """Load all exams from JSON files in a given directory."""
    83         from pathlib import Path
    84         import json
    8584
    8685        directory = Path(directory)
  • gui/session_manager.py

    rbc820cf rf8e1cf8  
    4444                "timestamp": timestamp,
    4545            }
    46             self.session_file.write_text(json.dumps(data, indent=2))
     46            self.session_file.write_text(json.dumps(data, encoding="utf-8", indent=2))
    4747            print(f"[Session] Saved at {timestamp}")
    4848        except Exception as e:
     
    5858        try:
    5959            print(self.session_file)
    60             data = json.loads(self.session_file.read_text())
     60            data = json.loads(self.session_file.read_text(encoding="utf-8"))
    6161
    6262            # 1. Restore window
Note: See TracChangeset for help on using the changeset viewer.