def django_task_to_task(django_task): dt = django_task task = yacc.Task(dt.description) # here we do an evil trick! # we reparse the task so we can extract tasks to be added to proper tags # TODO: have tags field in the model, so we don't need to reparse here parser = yacc.get_parser( 'task_suffix') # we are testing just part of the parser res = parser.parse(task.text + "\n") task = yacc.Task(res.text.text) task.tags = res.tags task.score = dt.score if dt.state is None: pass elif dt.state == "TO_CLOSED": task.tags.append("#done") elif dt.state == "TO_WORKING": task.tags.append("#work") elif dt.state == "TO_WAITING": # waiting means no tag pass else: raise Exception("Unknown task.state: %s" % dt.state) if dt.owner: task.owner = "@" + dt.owner.username return task
def django_task_to_task(django_task): dt = django_task task = yacc.Task(dt.description) # here we do an evil trick! # we reparse the task so we can extract tasks to be added to proper tags # TODO: have tags field in the model, so we don't need to reparse here parser = yacc.get_parser('task_suffix') # we are testing just part of the parser res = parser.parse(task.text + "\n") task = yacc.Task(res.text.text) task.tags = res.tags task.score = dt.score if dt.state is None: pass elif dt.state == "TO_CLOSED": task.tags.append("#done") elif dt.state == "TO_WORKING": task.tags.append("#work") elif dt.state == "TO_WAITING": # waiting means no tag pass else: raise Exception("Unknown task.state: %s" % dt.state) if dt.owner: task.owner = "@" + dt.owner.username return task
def text_to_django_story(text): parser = yacc.get_parser( 'story') # we are testing just part of the parser text = text.replace("\r\n", "\n") # convert crlf -> lf text = text.strip( "\n" ) + "\n" # make sure there are no multiple new lines after the tasks story = parser.parse(text, tracking=True) if not story: raise Exception("Story parsing wasn't successful") dstory = wm.Story() dstory.title = story.title dstory.story_description = story.description dstory.state = 'BACKLOG' dstory_tags_list = [] for t in story.tags: if "#green" == t: dstory.is_green = True elif "#fire" == t: dstory.is_burning = True elif "#timebox" == t: dstory.time_boxed = True elif "#would" == t: dstory.moscow = "W" elif "#could" == t: dstory.moscow = "C" elif "#should" == t: dstory.moscow = "S" elif "#must" == t: dstory.moscow = "M" else: dstory_tags_list.append(t) dstory.tags = " ".join(dstory_tags_list) dtasks = [] for task in story.tasks: dtask = wm.Task() dtask.score = task.score dtask.description = task.text.text tags = [] for t in task.tags: if t == "#done": dtask.state = "TO_CLOSED" elif t == "#work": dtask.state = "TO_WORKING" else: tags.append(t) if task.owner: # make sure we catch the right errors here try: dtask.owner = wm.User.objects.get(username=task.owner[1:]) except ObjectDoesNotExist: logging.warning( "Could not resolve username: %s, we will add it as regular tag" % task.owner) tags.append(task.owner) if tags: dtask.description += " [" + " ".join(tags) + "]" dtask.story = dstory dtasks.append(dtask) return (dstory, dtasks)
def text_to_django_story(text): parser = yacc.get_parser('story') # we are testing just part of the parser text = text.replace("\r\n", "\n") # convert crlf -> lf text = text.strip("\n") + "\n" # make sure there are no multiple new lines after the tasks story = parser.parse(text, tracking = True) if not story: raise Exception("Story parsing wasn't successful") dstory = wm.Story() dstory.title = story.title dstory.story_description = story.description dstory.state = 'BACKLOG' dstory_tags_list = [] for t in story.tags: if "#green" == t: dstory.is_green = True elif "#fire" == t: dstory.is_burning = True elif "#timebox" == t: dstory.time_boxed = True elif "#would" == t: dstory.moscow = "W" elif "#could" == t: dstory.moscow = "C" elif "#should" == t: dstory.moscow = "S" elif "#must" == t: dstory.moscow = "M" else: dstory_tags_list.append(t) dstory.tags = " ".join(dstory_tags_list) dtasks = [] for task in story.tasks: dtask = wm.Task() dtask.score = task.score dtask.description = task.text.text tags = [] for t in task.tags: if t == "#done": dtask.state = "TO_CLOSED" elif t == "#work": dtask.state = "TO_WORKING" else: tags.append(t) if task.owner: # make sure we catch the right errors here try: dtask.owner = wm.User.objects.get(username = task.owner[1:]) except ObjectDoesNotExist: logging.warning("Could not resolve username: %s, we will add it as regular tag" % task.owner) tags.append(task.owner) if tags: dtask.description += " [" + " ".join(tags) + "]" dtask.story = dstory dtasks.append(dtask) return (dstory, dtasks)