diff --git a/boartty/db.py b/boartty/db.py index e292004..5244437 100644 --- a/boartty/db.py +++ b/boartty/db.py @@ -728,13 +728,6 @@ class DatabaseSession(object): except sqlalchemy.orm.exc.NoResultFound: return None - def getStoryTag(self, story_key, tag_key): - try: - return self.session().query(StoryTag).filter_by( - story_key=story_key, tag_key=tag_key).one() - except sqlalchemy.orm.exc.NoResultFound: - return None - def getTask(self, key): try: return self.session().query(Task).filter_by(key=key).one() @@ -904,12 +897,6 @@ class DatabaseSession(object): self.session().flush() return o - def createStoryTag(self, *args, **kw): - o = StoryTag(*args, **kw) - self.session().add(o) - self.session().flush() - return o - def createSystem(self, *args, **kw): o = System(*args, **kw) self.session().add(o) diff --git a/boartty/sync.py b/boartty/sync.py index 177ec7d..e6bc8c5 100644 --- a/boartty/sync.py +++ b/boartty/sync.py @@ -1038,16 +1038,21 @@ class UpdateStoryTask(Task): result = sync.put('v1/stories/%s' % (story.id,), data) local_tags = set(tags_data) - remote_tags = set(sync.get('v1/stories/%s/tags' % (story.id,))) + remote_tags = sync.get('v1/stories/%s/tags' % (story.id,)) + remote_tags = set([t['name'] for t in remote_tags]) added = list(local_tags - remote_tags) removed = list(remote_tags - local_tags) if removed: + self.log.info("Remove tags %s from %s", + removed, story.id) sync.delete('v1/tags/%s' % (story.id,), - removed) + removed) if added: + self.log.info("Add tags %s to %s", + added, story.id) result = sync.put('v1/tags/%s' % (story.id,), - added) - sync.submitTask(SyncStoryTask(story.id, result, + added) + sync.submitTask(SyncStoryTask(story.id, priority=self.priority)) class UpdateTaskTask(Task): diff --git a/boartty/view/story.py b/boartty/view/story.py index 51fd108..0aec955 100644 --- a/boartty/view/story.py +++ b/boartty/view/story.py @@ -480,6 +480,8 @@ class StoryView(urwid.WidgetWrap, mywid.Searchable): "Refresh this story"), (keymap.EDIT_TITLE, "Edit the title of this story"), + (keymap.EDIT_TAGS, + "Edit this story's tags"), (keymap.INTERACTIVE_SEARCH, "Interactive search"), ] @@ -865,13 +867,13 @@ class StoryView(urwid.WidgetWrap, mywid.Searchable): with self.app.db.getSession() as session: story = session.getStory(self.story_key) new_tags = dialog.entry.edit_text.split(' ') + tags = [] for tag_name in new_tags: tag = session.getTag(tag_name) if tag is None: tag = session.createTag(tag_name) - story_tag = session.getStoryTag(story.key, tag_name) - if story_tag is None: - session.createStoryTag(story, tag) + tags.append(tag) + story.tags = tags self.app.sync.submitTask( sync.UpdateStoryTask(story.key, sync.HIGH_PRIORITY)) self.app.backScreen()