Fix tag editing

The set conversion wasn't correct -- iterate over the tag names
rather than the dict.

Use the proxy objects rather than creating StoryTag objects directly.
Remove some unecessary db functions.  Add to help text.

Change-Id: I023f3fb7351b3e57f8984adb537b26483f6b7c1f
This commit is contained in:
James E. Blair 2017-11-27 11:20:55 -08:00
parent 09305f8248
commit d6def5b802
3 changed files with 14 additions and 20 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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()