示例#1
0
def archived_tasks_view():
    if current_user.is_anonymous:
        goals = []
        tasks = []
        completed = []
    else:
        current_time = datetime.datetime.now()
        goals = Goal.query.filter(Goal.owner_id == current_user.id, ).all()
        tasks = Task.query.filter(Task.owner_id == current_user.id, ).all()
        tasks = [
            task for task in tasks
            if task.finish_time is not None and task.finish_time < current_time
        ]
        completed = CompletedTask.get_completed(
            date=datetime.datetime.today(), )

    tree = {'goals': {}}

    top_level_goals = [(goal.id, goal.name) for goal in goals
                       if goal.parent_goal_id is None]

    for goal in top_level_goals:
        tree['goals'][goal] = make_goal_branch(
            goal,
            goals,
            tasks,
            completed,
        )

    return render_turkey("archived_tasks.html",
                         tree=tree,
                         current_page='archived_tasks')
示例#2
0
文件: task.py 项目: geokala/quizify
def try_to_complete_task(task_id, form, date=None):
    if date is not None:
        completion_date = datetime.datetime.strptime(date, "%Y %b %d")
        just_before_midnight = datetime.datetime.max.time()
        completion_time = datetime.datetime.combine(completion_date, just_before_midnight)
        completed_later = True
    else:
        completion_time = datetime.datetime.now()
        completed_later = False

    completed_task = CompletedTask.create(
        comment=form.task_comment.data,
        associated_task_id=task_id,
        completed_time=completion_time,
        owner_id=current_user.id,
        completed_later=completed_later,
    )

    if completed_task is None:
        # TODO: better output from this
        flash("Task could not be completed!", "danger")
        return redirect(request.referrer)
    else:
        # TODO: improve this message
        flash("Task completed.", "success")
        if completed_later:
            return redirect(url_for("task_history", task_id=task_id))
        else:
            return redirect(url_for("home"))
示例#3
0
文件: home.py 项目: geokala/turkey
def home_view():
    if current_user.is_anonymous:
        goals = []
        tasks = []
        completed = []
        breaks = []
    else:
        current_time = datetime.datetime.now()
        goals = Goal.query.filter(
            Goal.owner_id == current_user.id,
        ).all()
        tasks = Task.query.filter(
            Task.owner_id == current_user.id,
        ).all()
        tasks = [
            task for task in tasks
            if task.finish_time is None
            or task.finish_time >= current_time
            ]
        completed = CompletedTask.get_completed(
            date=datetime.datetime.today(),
        )
        breaks = TaskBreak.get_breaks(
            date=datetime.datetime.today(),
        )

    tree = {'goals': {}}

    top_level_goals = [
        (goal.id, goal.name)
        for goal in goals
        if goal.parent_goal_id is None
    ]

    for goal in top_level_goals:
        tree['goals'][goal] = make_goal_branch(
            goal,
            goals,
            tasks,
            completed,
            breaks,
        )

    return render_turkey("home.html", tree=tree, current_page='active_tasks')
示例#4
0
文件: task.py 项目: geokala/quizify
def try_to_complete_task(task_id, form, date=None):
    if date is not None:
        completion_date = datetime.datetime.strptime(
            date,
            '%Y %b %d',
        )
        just_before_midnight = datetime.datetime.max.time()
        completion_time = datetime.datetime.combine(
            completion_date,
            just_before_midnight,
        )
        completed_later = True
    else:
        completion_time = datetime.datetime.now()
        completed_later = False

    completed_task = CompletedTask.create(
        comment=form.task_comment.data,
        associated_task_id=task_id,
        completed_time=completion_time,
        owner_id=current_user.id,
        completed_later=completed_later,
    )

    if completed_task is None:
        # TODO: better output from this
        flash(
            'Task could not be completed!',
            'danger',
        )
        return redirect(request.referrer)
    else:
        # TODO: improve this message
        flash(
            'Task completed.',
            'success',
        )
        if completed_later:
            return redirect(url_for('task_history', task_id=task_id))
        else:
            return redirect(url_for('home'))
示例#5
0
文件: task.py 项目: geokala/turkey
def try_to_complete_task(task_id, form, date=None):
    if date is not None:
        completion_date = datetime.datetime.strptime(
            date,
            '%Y %b %d',
        )
        just_before_midnight = datetime.datetime.max.time()
        completion_time = datetime.datetime.combine(
            completion_date,
            just_before_midnight,
        )
        completed_later = True
    else:
        completion_time = datetime.datetime.now()
        completed_later = False

    completed_task = CompletedTask.create(
        comment=form.task_comment.data,
        associated_task_id=task_id,
        completed_time=completion_time,
        owner_id=current_user.id,
        completed_later=completed_later,
    )

    if completed_task is None:
        # TODO: better output from this
        flash(
            'Task could not be completed!',
            'danger',
        )
        abort(403)
    else:
        # TODO: improve this message
        flash(
            'Task completed.',
            'success',
        )
        if completed_later:
            return redirect(url_for('task_history', task_id=task_id))
        else:
            return redirect(url_for('home'))