Skip to content

Commit

Permalink
Merge branch 'dev' into sqlalchemy-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
agateau committed Sep 3, 2024
2 parents c6bf84b + a490e51 commit d913389
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
25 changes: 11 additions & 14 deletions yokadi/core/dbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,17 @@ def getOrCreateProject(projectName, interactive=True, createIfNeeded=True):
@type createIfNeeded: Bool
@return: Project instance or None if user cancel creation or createIfNeeded is False"""
session = db.getSession()
result = session.query(Project).filter_by(name=projectName).all()
if len(result):
return result[0]

if not createIfNeeded:
return None

if interactive and not tui.confirm("Project '%s' does not exist, create it" % projectName):
return None

project = Project(name=projectName)
session.add(project)
print("Added project '%s'" % projectName)
return project
try:
return session.query(Project).filter_by(name=projectName).one()
except (NoResultFound, MultipleResultsFound):
if not createIfNeeded:
return None
if interactive and not tui.confirm("Project '%s' does not exist, create it" % projectName):
return None
project = Project(name=projectName)
session.add(project)
print("Added project '%s'" % projectName)
return project


def createMissingKeywords(lst, interactive=True):
Expand Down
4 changes: 3 additions & 1 deletion yokadi/tests/icaltestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ def testTaskDoneMapping(self):
t1 = dbutils.addTask("x", "t1", {})
v1 = yical.createVTodoFromTask(t1)

v1["completed"] = datetime.now()
completed = datetime.now()
v1.add("COMPLETED", completed)
yical.updateTaskFromVTodo(t1, v1)
self.assertEqual(t1.status, "done")
self.assertEqual(t1.doneDate, completed)

def testGenerateCal(self):
# Add an inactive project
Expand Down

0 comments on commit d913389

Please sign in to comment.