Skip to content

Commit

Permalink
v2024.08.15
Browse files Browse the repository at this point in the history
Signed-off-by: William José Moreno Reyes <williamjmorenor@gmail.com>
  • Loading branch information
williamjmorenor committed Aug 15, 2024
1 parent 4e6007b commit 8d25b2a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
71 changes: 40 additions & 31 deletions cacao_accounting_desktop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ def get_secret_key():
return f.readline()
else:
from uuid import uuid4
from ulid import ULID

UUID = uuid4()
SECURE_KEY = str(UUID)
ULID = ULID()
SECURE_KEY = str(ULID).join(":", str(UUID))
with open(SECURE_KEY_FILE, "x") as f:
f.write(SECURE_KEY)
return SECURE_KEY
Expand Down Expand Up @@ -160,48 +162,55 @@ def create_db(self):
self.DATABASE_FILE = Path(os.path.join(APP_DATA_DIR, self.dbname.get()))
self.DATABASE_URI = "sqlite:///" + str(self.DATABASE_FILE)

from cacao_accounting.logs import log

log.warning(self.DATABASE_FILE)
log.warning(self.DATABASE_URI)

self.app = create_app(
{
"SECRET_KEY": get_secret_key(),
"SQLALCHEMY_DATABASE_URI": self.DATABASE_URI,
}
)

self.new_user = self.nuser.get()
self.new_passwd = self.npswd.get()
self.new_passwd2 = self.npswd2.get()
self.checkpw = self.new_passwd == self.new_passwd2

if self.checkpw is not True:
if not os.path.exists(self.DATABASE_FILE):
open(self.DATABASE_FILE, "w").close()
self.NEW_DB_FILE = True
else:
self.message = CTkMessagebox(
title="Error",
icon="cancel",
message="Las contraseñas no coinciden.",
message="Ya existe una base de datos con ese nombre.",
)
self.NEW_DB_FILE = False

else:
if self.NEW_DB_FILE:
self.app = create_app(
{
"SECRET_KEY": get_secret_key(),
"SQLALCHEMY_DATABASE_URI": self.DATABASE_URI,
}
)

try:
from cacao_accounting.database.helpers import inicia_base_de_datos
self.new_user = self.nuser.get()
self.new_passwd = self.npswd.get()
self.new_passwd2 = self.npswd2.get()
self.checkpw = self.new_passwd == self.new_passwd2

inicia_base_de_datos(app=self.app, user=self.new_user, passwd=self.new_passwd, with_examples=False)
self.message = CTkMessagebox(
title="Confirmación",
icon="check",
message="Base de datos creada correctamente.",
)
except:
if self.checkpw is not True:
self.message = CTkMessagebox(
title="Error",
icon="cancel",
message="Hubo un error al crear la base de datos.",
message="Las contraseñas no coinciden.",
)

else:

try:
from cacao_accounting.database.helpers import inicia_base_de_datos

inicia_base_de_datos(app=self.app, user=self.new_user, passwd=self.new_passwd, with_examples=False)
self.message = CTkMessagebox(
title="Confirmación",
icon="check",
message="Base de datos creada correctamente.",
)
except:
self.message = CTkMessagebox(
title="Error",
icon="cancel",
message="Hubo un error al crear la base de datos.",
)

self.withdraw()


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "cacao-accounting-desktop"
description = "Cacao Accounting Desktop App."
readme = "README.md"
requires-python = ">=3.8"
version="2024.08.11"
version="2024.08.15"
authors = [
{name = "BMO Soluciones", email = "development@bmogroup.solutions"},
]
Expand Down

0 comments on commit 8d25b2a

Please sign in to comment.