示例#1
0
def create_task(project_key):
    form = TaskForm(request.form)
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    current_user_id = get_user(request, project_key)
    if current_user_id is None:
        return redirect(url_for('who_are_you', project_key=project_key))
    choices = [(p.id, p.name) for p in project.people]
    form.assigned_to.choices = choices
    if request.method == 'POST' and form.validate():
        title = form.title.data
        description = form.description.data
        priority = form.priority.data
        assigned_to = form.assigned_to.data
        Task.new(project.key, title, priority, current_user_id, assigned_to,
                 description)
        flash("Your task was created")
        project.touch()
        return redirect('/project/' + project_key)
    else:
        assigned_to = current_user_id
        form.assigned_to.default = current_user_id
        form.process()
    return render_template('edit_task.html',
                           form=form,
                           project=project,
                           assigned_to=assigned_to)
示例#2
0
def delete_task(project_key, task_key):
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    task = Task.get_task(project, task_key)
    flash('Task deleted: ' + task.title)
    task.delete()
    return redirect(url_for('view_project', project_key=project_key))
示例#3
0
def delete_comment(project_key, task_key):
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    task = Task.get_task(project, task_key)
    deletion_id = int(request.form['delete_comment'])
    task.delete_comment(deletion_id)
    flash('Comment was deleted')
    return redirect(
        url_for('view_task', project_key=project_key, task_key=task_key))
示例#4
0
def toggle_task_status(project_key, task_key):
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    task = Task.get_task(project, task_key)
    if task.status == 0:
        flash('Completed: ' + task.title)
        task.set_status(1)
    else:
        flash('Task not complete: ' + task.title)
        task.set_status(0)
    return redirect(url_for('view_project', project_key=project_key))
示例#5
0
def view_task(project_key, task_key):
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    task = Task.get_task(project, task_key)
    current_user_id = get_user(request, project_key)
    form = CommentForm(request.form)
    if request.method == 'POST' and form.validate():
        flash("Your comment was added")
        task.add_comment(form.comment.data, current_user_id)
        return redirect(
            url_for('view_task', project_key=project_key, task_key=task_key))
    return render_template('task.html', task=task, project=project, form=form)
示例#6
0
def who_are_you(project_key):
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    form = WhoAreYouForm(request.form)
    # Populate radio buttons
    categories = [(p.id, p.name) for p in project.people]
    form.people.choices = categories
    if request.method == 'POST' and form.validate():
        person_id = request.form['people']
        person_name = project.people[int(person_id)].name
        flash('Welcome ' + person_name + '! Please bookmark this page')
        response = make_response(redirect('/project/' + project_key))
        store_user(request, response, project_key, person_id)
        return response
    else:
        return render_template('who_are_you.html', project=project, form=form)
示例#7
0
def get_previous_projects(request):
    """Return a list of previous project keys from cookies in the request"""
    projects = []
    project_list = {}
    json_str = request.cookies.get('projects')
    if json_str is not None:
        try:
            project_list = json.loads(json_str)
        except (ValueError, KeyError, TypeError):
            print "JSON format error"
            logging.exception("Cookie json could not be decoded")
            return
    project_keys = [k for k in project_list.keys()]
    for key in project_keys:
        project = Project.get_project(key)
        if project is not None:
            projects.append(project)
    return projects
示例#8
0
def view_project(project_key):
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    current_user_id = get_user(request, project_key)
    if current_user_id is None:
        return redirect(url_for('who_are_you', project_key=project_key))
    if request.method == 'POST':
        person_id = request.form['user_id']
        response = make_response(redirect('/project/' + project_key))
        store_user(request, response, project_key, person_id)
        return response
    # Create list of people without current user for user selection
    other_people = [p for p in project.people if p.id is not current_user_id]
    # Fetch tasks
    tasks = project.get_tasks()
    return render_template('project.html',
                           current_user_id=current_user_id,
                           other_people=other_people,
                           project=project,
                           tasks=tasks)
示例#9
0
def edit_task(project_key, task_key):
    form = TaskForm(request.form)
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    task = Task.get_task(project, task_key)
    choices = [(p.id, p.name) for p in project.people]
    form.assigned_to.choices = choices
    if request.method == 'POST' and form.validate():
        flash("Task was updated")
        task.update(form.title.data, int(form.priority.data),
                    form.description.data, form.assigned_to.data)
        return redirect(
            url_for('view_task', project_key=project_key, task_key=task_key))
    form.title.data = task.title
    form.priority.data = str(task.priority)
    form.description.data = task.description
    form.assigned_to.data = task.assigned_to
    return render_template('edit_task.html',
                           task=task,
                           project=project,
                           form=form)
示例#10
0
def edit_project(project_key):
    project = Project.get_project(project_key)
    if project is None:
        abort(404)
    return render_template('edit_project.html', project=project)