refactored model, fixed utf-8 export json
This commit is contained in:
@@ -8,6 +8,7 @@ from tkinter import ttk
|
|||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from connector import JSONConnector
|
from connector import JSONConnector
|
||||||
|
from model import Model
|
||||||
from windows import SettingsWindow, EditRecord, show_error
|
from windows import SettingsWindow, EditRecord, show_error
|
||||||
|
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ class Application:
|
|||||||
self.filter_active = tk.BooleanVar(value=False)
|
self.filter_active = tk.BooleanVar(value=False)
|
||||||
|
|
||||||
# model connector
|
# model connector
|
||||||
self.model = JSONConnector()
|
self.model = Model(JSONConnector())
|
||||||
|
|
||||||
# init paths to json and csv file
|
# init paths to json and csv file
|
||||||
self.json_file_name = "brovski-adress-etiketten-verwaltung.json"
|
self.json_file_name = "brovski-adress-etiketten-verwaltung.json"
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ class Connector(ABC):
|
|||||||
def create_new(self, values: dict) -> int:
|
def create_new(self, values: dict) -> int:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_all_sorted_by(self, field: str, reverse: bool = False) -> list:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class JSONConnector(Connector):
|
class JSONConnector(Connector):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -78,5 +82,5 @@ class JSONConnector(Connector):
|
|||||||
return next_id
|
return next_id
|
||||||
|
|
||||||
def _write_to_file(self, data):
|
def _write_to_file(self, data):
|
||||||
with open(self.json_file, "w") as f:
|
with open(self.json_file, "w", encoding="UTF-8") as f:
|
||||||
json.dump(data, f, indent=4)
|
json.dump(data, f, indent=4, ensure_ascii=False)
|
||||||
|
|||||||
24
src/model.py
Normal file
24
src/model.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from connector import JSONConnector, Connector
|
||||||
|
|
||||||
|
|
||||||
|
class Model:
|
||||||
|
def __init__(self, connector: Connector):
|
||||||
|
self.connector = connector
|
||||||
|
|
||||||
|
def get_all(self):
|
||||||
|
return self.connector.get_all()
|
||||||
|
|
||||||
|
def get_all_sorted_by(self, field: str, reverse: bool = False):
|
||||||
|
return self.connector.get_all_sorted_by(field=field, reverse=reverse)
|
||||||
|
|
||||||
|
def get_by_id(self, record_id: int):
|
||||||
|
return self.connector.get_by_id(record_id)
|
||||||
|
|
||||||
|
def delete_by_id(self, record_id: int):
|
||||||
|
self.connector.delete_by_id(record_id)
|
||||||
|
|
||||||
|
def update_record(self, new_record: dict):
|
||||||
|
self.connector.update_record(new_record)
|
||||||
|
|
||||||
|
def create_new(self, record: dict):
|
||||||
|
self.connector.create_new(record)
|
||||||
Reference in New Issue
Block a user