Skip to content

Commit

Permalink
برمجة مسار الملف لتتبع السجلات المستوردة في نموذج قواعد البيانات
Browse files Browse the repository at this point in the history
  • Loading branch information
vzool committed Nov 5, 2024
1 parent f0fcfda commit d738ce6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .idea/dbnavigator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 33 additions & 12 deletions zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ def hide(self, account_id: int, status: bool = None) -> bool:
Example:
>>> tracker = ZakatTracker()
>>> ref = tracker.db.track(51, 'desc', 1) # 'account1'
>>> tracker.db.hide(1) # Set the hide status of 'account1' to True
>>> tracker.db.hide(1) # Get the hide status of 'account1', which is False by default
False
>>> tracker.db.hide(1, True) # Set the hide status of 'account1' to True
True
>>> tracker.db.hide(1) # Get the hide status of 'account1' by default
>>> tracker.db.hide(1) # Get the hide status of 'account1'
True
>>> tracker.db.hide(1, False)
False
Expand Down Expand Up @@ -621,6 +621,15 @@ def zakat(self, report: tuple, parts: Dict[str, Dict | bool | Any] = None, debug
bool: True if the zakat calculation is successful, False otherwise.
"""

@abstractmethod
def file_exists(self) -> bool:
"""
Determines whether the file associated with this object exists.
Returns:
bool: True if the file exists, False otherwise.
"""

@abstractmethod
def import_csv_cache_path(self):
"""
Expand Down Expand Up @@ -768,14 +777,14 @@ def snapshot(self) -> bool:
False if the snapshot creation fails.
"""

@staticmethod
@abstractmethod
def ext() -> str:
def ext(self) -> str | None:
"""
Returns the file extension used by the ZakatTracker class.
Returns the file extension of the current object.
Returns:
str: The file extension used by the ZakatTracker class, which is 'camel' or 'sqlite'.
str | None: The file extension as a string like ('camel', 'sqlite', ..., etc.),
or None if the extension is not available.
"""

@abstractmethod
Expand Down Expand Up @@ -1403,15 +1412,17 @@ def path(self, path: str = None) -> str:
self._base_path = base_path
return str(self._vault_path)

def file_exists(self) -> bool:
return True

def reset(self) -> None:
self._vault = {
'account': {},
'exchange': {},
'report': {},
}

@staticmethod
def ext() -> str:
def ext(self) -> str | None:
return 'camel'

def base_path(self, *args) -> str:
Expand Down Expand Up @@ -2305,12 +2316,14 @@ def __init__(self, **db_params):
self._config_path = None
self._db_path = None
self.debug = False
self._file_exists = False
self.raw_sql = True

if str.lower(db_params['provider']) == 'sqlite' and 'filename' in db_params:
db_params['filename'] = str(self.path(db_params['filename']))
self._db_path = db_params['filename']
self._config_path = str(self._base_path / 'config.db')
self._file_exists = True
else:
self._config_path = str(self.path('config.db'))
self.config = ConfigManager(db_file=self._config_path)
Expand All @@ -2336,6 +2349,9 @@ def path(self, path: str = None) -> str:
self._base_path = base_path
return str(self._vault_path)

def file_exists(self) -> bool:
return self._file_exists

@pony.db_session
def sub(self, unscaled_value: float | int | Decimal, desc: str = '', account: int = 1, created: int = None,
debug: bool = False) \
Expand Down Expand Up @@ -2826,7 +2842,13 @@ def zakat(self, report: tuple, parts: Dict[str, Dict | bool | Any] = None, debug
pass

def import_csv_cache_path(self):
pass
path = str(self.path())
ext = self.ext()
ext_len = len(ext)
if path.endswith(f'.{ext}'):
path = path[:-ext_len - 1]
_, filename = os.path.split(f'{path}.import_csv.{ext}.camel')
return f'{self._base_path}/{filename}'

def daily_logs(self, weekday: WeekDay = WeekDay.Friday, debug: bool = False):
return {
Expand Down Expand Up @@ -2898,9 +2920,8 @@ def vault(self, section: Vault = Vault.ALL) -> dict:
def snapshot(self) -> bool:
pass

@staticmethod
def ext() -> str:
return 'sqlite'
def ext(self) -> str | None:
return 'sqlite' if self._file_exists else None

@pony.db_session
def log(self, value: float, desc: str = '', account_id: int = 1, created: int = None, ref: int = None,
Expand Down

0 comments on commit d738ce6

Please sign in to comment.