def get_completed_tasks_display(task_id): week = get_completed_tasks_history(task_id) # Calculate widths to make 100% of progress bar for display width_remaining = 100 for day in week: day['width'] = 100 // len(week) width_remaining = width_remaining - day['width'] if len(week) > 0: next_day_width_balance = 0 while width_remaining > 0: week[next_day_width_balance]['width'] += 1 width_remaining -= 1 next_day_width_balance = (next_day_width_balance + 1) % len(week) return week
def task_history_view(task_id): try: task = Task.query.filter( Task.id == task_id, Task.owner_id == current_user.id, ).one() except NoResultFound: # This is not an existing task this user owns flash( 'Could not find task {id}.'.format(id=task_id), 'danger', ) return redirect(url_for('home')) current_day = datetime.date.today() midnight = datetime.datetime.min.time() current_day = datetime.datetime.combine(current_day, midnight) creation_day = datetime.datetime.combine(task.creation_time, midnight) creation_history_delta = (current_day - creation_day).days task_history = get_completed_tasks_history( task_id=task_id, days=creation_history_delta, ) task_name = task.name for task in task_history: task['date_quoted'] = parse.quote_plus(task['date']) days_ago = [] while current_day >= creation_day: days_ago.append(current_day) current_day = current_day - datetime.timedelta(days=1) return render_turkey( 'task_history.html', history=task_history, task_name=task_name, )