Increased flexibility and folder obscuring.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
## 202407.04
|
## 202407.04
|
||||||
|
|
||||||
- Added support for postgresql databases (auto backup not functional).
|
- Added support for postgresql databases (auto backup not functional).
|
||||||
|
- Improved portability and folder obscuring.
|
||||||
|
|
||||||
## 202407.02
|
## 202407.02
|
||||||
|
|
||||||
|
|||||||
6
src/config.yml
Normal file
6
src/config.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
directory_path: null
|
||||||
|
database_path: null
|
||||||
|
database_schema: sqlite
|
||||||
|
database_user: null
|
||||||
|
database_password: null
|
||||||
|
database_name: null
|
||||||
@@ -472,7 +472,10 @@ class BasicSubmission(BaseClass):
|
|||||||
except:
|
except:
|
||||||
logger.warning(f"Couldn't drop '{item}' column from submissionsheet df.")
|
logger.warning(f"Couldn't drop '{item}' column from submissionsheet df.")
|
||||||
if chronologic:
|
if chronologic:
|
||||||
|
try:
|
||||||
df.sort_values(by="id", axis=0, inplace=True, ascending=False)
|
df.sort_values(by="id", axis=0, inplace=True, ascending=False)
|
||||||
|
except KeyError:
|
||||||
|
logger.error("No column named 'id'")
|
||||||
# NOTE: Human friendly column labels
|
# NOTE: Human friendly column labels
|
||||||
df.columns = [item.replace("_", " ").title() for item in df.columns]
|
df.columns = [item.replace("_", " ").title() for item in df.columns]
|
||||||
return df
|
return df
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from PyQt6.QtWidgets import QMainWindow, QFileDialog
|
|||||||
logger = logging.getLogger(f"submissions.{__name__}")
|
logger = logging.getLogger(f"submissions.{__name__}")
|
||||||
|
|
||||||
|
|
||||||
def select_open_file(obj:QMainWindow, file_extension:str) -> Path:
|
def select_open_file(obj: QMainWindow, file_extension: str | None = None) -> Path:
|
||||||
"""
|
"""
|
||||||
File dialog to select a file to read from
|
File dialog to select a file to read from
|
||||||
|
|
||||||
@@ -26,12 +26,16 @@ def select_open_file(obj:QMainWindow, file_extension:str) -> Path:
|
|||||||
home_dir = Path.home().resolve().__str__()
|
home_dir = Path.home().resolve().__str__()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
home_dir = obj.app.last_dir.resolve().__str__()
|
home_dir = obj.app.last_dir.resolve().__str__()
|
||||||
fname = Path(QFileDialog.getOpenFileName(obj, 'Open file', home_dir, filter = f"{file_extension}(*.{file_extension})")[0])
|
if file_extension is None:
|
||||||
|
fname = Path(QFileDialog.getExistingDirectory(obj, "Open Folder", home_dir))
|
||||||
|
else:
|
||||||
|
fname = Path(
|
||||||
|
QFileDialog.getOpenFileName(obj, 'Open file', home_dir, filter=f"{file_extension}(*.{file_extension})")[0])
|
||||||
obj.last_dir = fname.parent
|
obj.last_dir = fname.parent
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
|
|
||||||
def select_save_file(obj:QMainWindow, default_name:str, extension:str) -> Path:
|
def select_save_file(obj: QMainWindow, default_name: str, extension: str) -> Path:
|
||||||
"""
|
"""
|
||||||
File dialog to select a file to write to
|
File dialog to select a file to write to
|
||||||
|
|
||||||
@@ -49,6 +53,6 @@ def select_save_file(obj:QMainWindow, default_name:str, extension:str) -> Path:
|
|||||||
home_dir = Path.home().joinpath(default_name).resolve().__str__()
|
home_dir = Path.home().joinpath(default_name).resolve().__str__()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
home_dir = obj.app.last_dir.joinpath(default_name).resolve().__str__()
|
home_dir = obj.app.last_dir.joinpath(default_name).resolve().__str__()
|
||||||
fname = Path(QFileDialog.getSaveFileName(obj, "Save File", home_dir, filter = f"{extension}(*.{extension})")[0])
|
fname = Path(QFileDialog.getSaveFileName(obj, "Save File", home_dir, filter=f"{extension}(*.{extension})")[0])
|
||||||
obj.last_dir = fname.parent
|
obj.last_dir = fname.parent
|
||||||
return fname
|
return fname
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ from openpyxl.worksheet.worksheet import Worksheet
|
|||||||
from PyQt6.QtPrintSupport import QPrinter
|
from PyQt6.QtPrintSupport import QPrinter
|
||||||
from __init__ import project_path
|
from __init__ import project_path
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
from tkinter import Tk # from tkinter import Tk for Python 3.x
|
||||||
|
from tkinter.filedialog import askdirectory
|
||||||
|
|
||||||
logger = logging.getLogger(f"submissions.{__name__}")
|
logger = logging.getLogger(f"submissions.{__name__}")
|
||||||
|
|
||||||
@@ -261,14 +263,14 @@ class Settings(BaseSettings, extra="allow"):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def ensure_directory_exists(cls, value):
|
def ensure_directory_exists(cls, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
print("No value for dir path")
|
# print("No value for dir path")
|
||||||
if check_if_app():
|
if check_if_app():
|
||||||
alembic_path = Path(sys._MEIPASS).joinpath("files", "alembic.ini")
|
alembic_path = Path(sys._MEIPASS).joinpath("files", "alembic.ini")
|
||||||
else:
|
else:
|
||||||
alembic_path = project_path.joinpath("alembic.ini")
|
alembic_path = project_path.joinpath("alembic.ini")
|
||||||
print(f"Getting alembic path: {alembic_path}")
|
# print(f"Getting alembic path: {alembic_path}")
|
||||||
value = cls.get_alembic_db_path(alembic_path=alembic_path)
|
value = cls.get_alembic_db_path(alembic_path=alembic_path).parent
|
||||||
print(f"Using {value}")
|
# print(f"Using {value}")
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
value = Path(value)
|
value = Path(value)
|
||||||
try:
|
try:
|
||||||
@@ -276,11 +278,12 @@ class Settings(BaseSettings, extra="allow"):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
check = False
|
check = False
|
||||||
if not check:
|
if not check:
|
||||||
print(f"No directory found, using Documents/submissions")
|
# print(f"No directory found, using Documents/submissions")
|
||||||
value = Path.home().joinpath("Documents", "submissions")
|
# value = Path.home().joinpath("Documents", "submissions")
|
||||||
value.mkdir()
|
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
|
||||||
# metadata.directory_path = value
|
value = Path(askdirectory(title="Select directory for DB storage")) # show an "Open" dialog box and return the path to the selected file
|
||||||
print(f"Final return of directory_path: {value}")
|
value.mkdir(exist_ok=True)
|
||||||
|
# print(f"Final return of directory_path: {value}")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@field_validator('database_path', mode="before")
|
@field_validator('database_path', mode="before")
|
||||||
@@ -357,6 +360,18 @@ class Settings(BaseSettings, extra="allow"):
|
|||||||
if value is None:
|
if value is None:
|
||||||
return package
|
return package
|
||||||
|
|
||||||
|
@field_validator('database_name', mode='before')
|
||||||
|
@classmethod
|
||||||
|
def get_database_name(cls, value, values):
|
||||||
|
if value is None:
|
||||||
|
if check_if_app():
|
||||||
|
alembic_path = Path(sys._MEIPASS).joinpath("files", "alembic.ini")
|
||||||
|
else:
|
||||||
|
alembic_path = project_path.joinpath("alembic.ini")
|
||||||
|
# print(f"Getting alembic path: {alembic_path}")
|
||||||
|
value = cls.get_alembic_db_path(alembic_path=alembic_path).stem
|
||||||
|
return value
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@@ -389,13 +404,13 @@ class Settings(BaseSettings, extra="allow"):
|
|||||||
c = ConfigParser()
|
c = ConfigParser()
|
||||||
c.read(alembic_path)
|
c.read(alembic_path)
|
||||||
path = c['alembic']['sqlalchemy.url'].replace("sqlite:///", "")
|
path = c['alembic']['sqlalchemy.url'].replace("sqlite:///", "")
|
||||||
return Path(path).parent
|
return Path(path)
|
||||||
|
|
||||||
def save(self, settings_path:Path):
|
def save(self, settings_path:Path):
|
||||||
if not settings_path.exists():
|
if not settings_path.exists():
|
||||||
dicto = {}
|
dicto = {}
|
||||||
for k,v in self.__dict__.items():
|
for k,v in self.__dict__.items():
|
||||||
if k in ['package', 'database_session']:
|
if k in ['package', 'database_session', 'submission_types']:
|
||||||
continue
|
continue
|
||||||
match v:
|
match v:
|
||||||
case Path():
|
case Path():
|
||||||
|
|||||||
Reference in New Issue
Block a user