def get_task(task_id): #task = [task for task in tasks if task["id"] == task_id] db.db.connect() try: task = db.get_task(task_id) except: abort(404) db.db.close() return jsonify({"task": make_public(task)})
def task(): if not session.get('logged_in', False): return redirect('/') team_id = session['team_id'] if request.method == 'GET': stage = get_task(team_id).stage if stage > 1000: user = get_user(team_id) return user.flag else: answer, task_body = generate() update_answer(team_id, answer) return render_template('task.html', stage=stage, task=task_body) else: task = get_task(team_id) answer = str(request.form['answer']) if answer == task.answer: update_stage(team_id, task.stage + 1) return redirect('/task')
def update(id): if request.method == 'POST': new_task = request.form.get('content') if not new_task: return render_template('apology.html', msg='No task provided!'), 404 database.update_task(id, new_task) return redirect('/') else: task = database.get_task(task_id=id) return render_template('update.html', task=task)
def update_task(task_id): task = database.get_task(CONNECTION, task_id) print(task) if len(task) == 0: abort(404) if not request.json: abort(400) if 'title' in request.json and not isinstance(request.json['title'], str): abort(400) if 'description' in request.json and \ not isinstance(request.json['description'], str): abort(400) if 'done' in request.json and type(request.json['done']) is not bool: abort(400) task[0]['title'] = request.json.get('title', task[0]['title']) task[0]['description'] = request.json.get('description', task[0]['description']) task[0]['status'] = request.json.get('status', task[0]['status']) database.update_task(CONNECTION, task[0]) return jsonify({'task': make_public_task(task[0])})
def complete(request, list_id, series_id, task_id): task = database.get_task(list_id, series_id, task_id) task.complete() return redirect('home')
def postpone(request, list_id, series_id, task_id): task = database.get_task(list_id, series_id, task_id) task.postpone() return redirect('home')
def edit(request, list_id, series_id, task_id): task = database.get_task(list_id, series_id, task_id) return render_to_response('edit.html', {'task': task}, RequestContext(request))
def edit_item(no): cur_data = database.get_task(no) return template('edit_task', old=cur_data, no=no)
def get_task(task_id): task = database.get_task(CONNECTION, task_id) if len(task) == 0: abort(404) return jsonify({'task': make_public_task(task[0])})
def delete_task(task_id): task = database.get_task(CONNECTION, task_id) if len(task) == 0: abort(404) database.delete_task(CONNECTION, task_id) return jsonify({'result': True})