def edit_task_start(task_id): task = repo.get_task_by_id(task_id) delta = timedelta(minutes=session['utc_offset']) # POST modified the start of task chunk if request.method == 'POST': return_url = request.form.get('return_url') start_time = request.form.get('start_time') if start_time: start_time = datetime.strptime(start_time, '%Y/%m/%d %H:%M:%S') if start_time: start_time += delta task.start_time = start_time repo.db.session.commit() if return_url: return redirect(return_url) return redirect(url_for('dashboard.index')) # GET opens task chunk edit (with only start modifier) return_url = request.args.get('return_url') start_time = datetime.strftime( task.start_time - delta, '%Y/%m/%d %H:%M:%S') return render_template('dashboard/edit_task_chunk.html', task=task, return_url=return_url, start_time=start_time, only_start=True)
def task(id): task = repo.get_task_by_id(id) tasks = repo.get_tasks_of_user(g.user.id) subtasks = get_subtasks(task.id, tasks) calc_stats(subtasks, task) return render_template('statistics/tasks.html', tasks=subtasks, section=task.name)
def edit_task_chunk(task_id, tc_id): task = repo.get_task_by_id(task_id) delta = timedelta(minutes=session['utc_offset']) if request.method == 'POST': return_url = request.form.get('return_url') start_time = request.form.get('start_time') end_time = request.form.get('end_time') if start_time: start_time = datetime.strptime(start_time, '%Y/%m/%d %H:%M:%S') if end_time: end_time = datetime.strptime(end_time, '%Y/%m/%d %H:%M:%S') if start_time and end_time and end_time > start_time: start_time += delta end_time += delta if tc_id: task_chunk = repo.get_task_chunk_by_id(tc_id) # Modify task/project times new_duration = end_time - start_time delta = new_duration - task_chunk.duration task_chunk.start = start_time task_chunk.end = end_time task_chunk.duration = new_duration task._add_duration(delta) repo.db.session.commit() else: duration = end_time - start_time task._add_duration(duration) repo.create_task_chunk( g.user.id, task.id, start_time, end_time) repo.db.session.commit() if return_url: return redirect(return_url) return redirect(url_for('dashboard.index')) return_url = request.args.get('return_url') start_time = '' end_time = '' if tc_id: task_chunk = repo.get_task_chunk_by_id(tc_id) start_time = datetime.strftime( task_chunk.start - delta, '%Y/%m/%d %H:%M:%S') end_time = datetime.strftime( task_chunk.end - delta, '%Y/%m/%d %H:%M:%S') return render_template('dashboard/edit_task_chunk.html', tc_id=tc_id, task=task, return_url=return_url, start_time=start_time, end_time=end_time)
def start(task_id): return_url = request.form.get('return_url') if request.method == 'POST': if task_id: task = repo.get_task_by_id(task_id) if task: task.start() repo.db.session.commit() if return_url: return redirect(return_url) return redirect(url_for('dashboard.index', task_id=task_id))
def delete_task_chunk(tc_id): task_chunk = repo.get_task_chunk_by_id(tc_id) return_url = request.form.get('return_url') if request.method == 'POST': task = repo.get_task_by_id(task_chunk.task_id) duration = task_chunk.start - task_chunk.end task._add_duration(duration) repo.delete_task_chunk(tc_id) if return_url: return redirect(return_url) return redirect(url_for('dashboard.index', task_id=task_chunk.task_id))
def index(task_id): delta = timedelta(minutes=session['utc_offset']) task = None if task_id: task = repo.get_task_by_id(task_id) user = repo.get_user_by_id(g.user.id) tasks = repo.get_tasks_of_user(g.user.id) set_task_full_paths(tasks) if user.order_date is True: # Sort by last chunk end time, unstarted will have the same value set_task_last_chunks(tasks, repo) tasks.sort(key=lambda task: task.last_chunk_time, reverse=True) else: tasks.sort(key=lambda task: task.full_path) for t in tasks: if t.start_time: t.start_time_elapsed = str( datetime.utcnow() - t.start_time).split('.')[0] start_date = request.args.get('start_date') end_date = request.args.get('end_date') if start_date is None: start_date = datetime.utcnow().date() else: start_date = datetime.strptime(start_date, '%Y-%m-%d').date() if end_date is None: end_date = datetime.utcnow().date() else: end_date = datetime.strptime(end_date, '%Y-%m-%d').date() # Fill out the displayed days task_chunks = task_chunks_between_dates( g.user.id, start_date, end_date, delta) for tc in task_chunks: tc['chunks'].sort(key=lambda x: x.start, reverse=True) return render_template('dashboard/index.html', tasks=tasks, task=task, task_chunks=task_chunks, start_date=start_date, end_date=end_date, order_date=user.order_date)
def stop(task_id): return_url = request.form.get('return_url') if request.method == 'POST': if task_id: task = repo.get_task_by_id(task_id) if task: if task.started: start = task.start_time end = datetime.utcnow() repo.create_task_chunk( g.user.id, task.id, start, end) task.stop() repo.db.session.commit() if return_url: return redirect(return_url) return redirect(url_for('dashboard.index', task_id=task_id))
def edit(project_id, task_id): task = repo.get_task_by_id(task_id) if task: if request.method == 'POST': name = request.form['name'] error = None if not name: error = 'Name is required.' if error: flash(error) else: task.name = name repo.db.session.commit() else: return render_template( 'tasks/edit.html', task=task, project_id=project_id) return redirect(url_for('tasks.index', project_id=project_id))
def subtask(project_id, parent_id): parent = None if parent_id is not None: parent = repo.get_task_by_id(parent_id) if parent is None: return redirect( url_for('tasks.index', project_id=project_id)) if request.method == 'POST': name = request.form['name'] error = None if not name: error = 'Name is required.' if error: flash(error) else: repo.create_task(name, parent.project, parent) return redirect( url_for('tasks.index', project_id=project_id)) else: return render_template('tasks/subtask.html', project_id=project_id, task=parent)