Skip to content

Commit

Permalink
Normalize how objects are added to session in dbs13n
Browse files Browse the repository at this point in the history
  • Loading branch information
agateau committed Oct 29, 2016
1 parent d1fc536 commit 67fd462
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
14 changes: 7 additions & 7 deletions yokadi/core/dbs13n.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ def _dictFromRow(row, skippedKeys=None):
return dct


def _updateRowFromDict(row, dct, skippedKeys=None):
def _updateRowFromDict(session, row, dct, skippedKeys=None):
if skippedKeys is None:
skippedKeys = set()
for key, value in dct.items():
if key in skippedKeys:
continue
setattr(row, key, value)
session.add(row)


def _convertStringsToDates(dct, keys):
Expand All @@ -47,8 +48,8 @@ def dictFromProject(project):
return _dictFromRow(project, skippedKeys={"tasks"})


def updateProjectFromDict(project, dct):
_updateRowFromDict(project, dct)
def updateProjectFromDict(session, project, dct):
_updateRowFromDict(session, project, dct)


def dictFromTask(task):
Expand All @@ -65,8 +66,7 @@ def updateTaskFromDict(session, task, dct):
dct["project"] = project

_convertStringsToDates(dct, TASK_DATE_FIELDS)
_updateRowFromDict(task, dct, skippedKeys={"recurrence", "keywords"})
session.add(task)
_updateRowFromDict(session, task, dct, skippedKeys={"recurrence", "keywords"})
keywords = dct["keywords"]
dbutils.createMissingKeywords(keywords.keys(), interactive=False)
task.setKeywordDict(keywords)
Expand All @@ -79,5 +79,5 @@ def dictFromAlias(alias):
return _dictFromRow(alias)


def updateAliasFromDict(alias, dct):
_updateRowFromDict(alias, dct)
def updateAliasFromDict(session, alias, dct):
_updateRowFromDict(session, alias, dct)
6 changes: 2 additions & 4 deletions yokadi/sync/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def _update(self, session, project, dct):
self._schedulePostUpdateChange(project, dict(name=dct["name"]))
dct["name"] = dct["uuid"]

dbs13n.updateProjectFromDict(project, dct)
session.add(project)
dbs13n.updateProjectFromDict(session, project, dct)


class TaskChangeHandler(ChangeHandler):
Expand All @@ -127,8 +126,7 @@ def _update(self, session, alias, dct):
self._schedulePostUpdateChange(alias, dict(name=dct["name"]))
dct["name"] = dct["uuid"]

dbs13n.updateAliasFromDict(alias, dct)
session.add(alias)
dbs13n.updateAliasFromDict(session, alias, dct)


def autoResolveConflicts(objects):
Expand Down

0 comments on commit 67fd462

Please sign in to comment.