def todos(): """ Todos GET method used to fetch list of items todo :return: todos, msg """ try: global added global deleted global mark_as_complete messageList = [] if not session.get('logged_in'): return redirect('/login') todos = db_service.getalltodo() messageList.append(added) messageList.append(deleted) messageList.append(mark_as_complete) added = False deleted = False mark_as_complete = False return render_template('todos.html', todos=todos, msg=messageList) except Exception as e: logger.error(e) return redirect('/error')
def logout(): """ Log out method is used to implement log out functionality :return: void """ try: session.pop('logged_in', None) session.pop('user', None) return redirect('/') except Exception as e: logger.error(e) return redirect('/error')
def todo(id): """ TODO GET method is used to fetch details of a selected item :param id: int :return: void """ try: todo = db_service.get_todo_by_id(id) todo_dict = db_service.convert_todo_dict(todo) return render_template('todo.html', todo=todo_dict) except Exception as e: logger.error(e) return redirect('/error')
def todojson(id): """ Todo json GET method is used to fetch details of a selected item in json format :param id: int :return: todo """ try: todos = db_service.get_todo_by_id(id) todos_dict = db_service.convert_todo_dict(todos) todos_json = json.dumps(todos_dict) return render_template('json.html', todo=todos_json) except Exception as e: logger.error(e) return redirect('/error')
def todochk_POST(): """ Todochk method used to mark an item in the list to complete :return: void """ try: global mark_as_complete if not session.get('logged_in'): return redirect('/login') id = request.form['id'] is_checked = str_to_bool(request.form['isChecked']) db_service.updatetodoitem(id, is_checked) mark_as_complete = True except Exception as e: mark_as_complete = False logger.error(e) return redirect('/todo')
def todo_delete(id): """ Todo_delete POST used to delete an existing item from todolist :param id: int :return: void """ try: global deleted if not session.get('logged_in'): return redirect('/login') db_service.deletetodoitem(id) deleted = True return redirect('/todo') except Exception as e: deleted = False logger.error(e) return redirect('/error')
def login_POST(): """ Login POST method is used to post and validate user :return: void """ try: username = request.form.get('username') password = request.form.get('password') getUser = db_service.get_username(username, password) if getUser: session['user'] = getUser.id session['logged_in'] = True return redirect('/todo') except Exception as e: logger.error(e) return redirect('/error') return redirect('/login')
def todos_POST(): """ Todos POST used to add new item to todolist :return: void """ try: global added if not session.get('logged_in'): return redirect('/login') user_id = session['user'] description = request.form.get('description', '') is_completed = False db_service.addtodoitem(user_id, description, is_completed) added = True return redirect('/todo') except Exception as e: added = False logger.error(e) return redirect('/error')