def todo_list(): try: body = request.get_json() username = body["username"] todo_list = get_todos(user_id=username) todo_list = get_todos(user_id=username) all_todo_dict = {"username": username} todo_array = [] for todo in todo_list: todo_elements = todo.to_dict() todo_elements["id"] = todo.id todo_array.append(todo_elements) all_todo_dict["todos"] = todo_array return make_response(error=False, message="To Do list get", status=200, data=all_todo_dict) except (KeyError, TypeError): # If invalid body schema message = 'No Complete data' return make_response(error=True, message=message, status=400) except Exception: # Return a 500 error if something went wrong return make_response(error=True, message='Server error', status=500)
def hello(): user_ip = session.get('user_ip') username = current_user.id # Obtenermos username todo_form = TodoForm() # instancia de TodoForm delete_form = DeleteTodoForm() # instancia de DeleteTodoForm update_form = UpdateTodoForm() # instancia de UpdateTodoForm context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form, } if todo_form.validate_on_submit(): # Crear la tarea en db put_todo(user_id=username, description=todo_form.description.data) flash('Tu tarea se ha creado con éxito!') return redirect(url_for('hello')) return render_template('hello.html', **context)
def hello(): user_ip = session.get('user_ip') username = current_user.id todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form } if todo_form.validate_on_submit(): todo_put(user_id=username, description=todo_form.description.data) flash('Tu tarea se creo con éxito') return redirect(url_for('hello')) return render_template('hello.html', **context) #Los ** expanden el diccionario.
def hello(user_ip=0, username='******'): user_ip = session.get('user_ip') username = current_user.id todo_form = todoForm() delete_form = DeleteForm() update_form = UpdateForm() context = { 'user_ip': user_ip, 'lista': get_todos(username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form } if todo_form.validate_on_submit(): description = todo_form.description.data put_todo(description=description, user_name=username) flash('Tarea creada con exito') redirect(url_for('hello')) # users = get_users() # # for user in users: # print(user.id) # print(user.to_dict().get('password')) return render_template('hello.html', **context)
def hello(): # user_ip = request.cookies.get("user_ip") user_ip = session.get("user_ip") email = current_user.id username = current_user.username todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { "user_ip": user_ip, "todos": get_todos(user_id=email), "username": username, "todo_form": todo_form, "delete_form": delete_form, "update_form": update_form, } if todo_form.validate_on_submit(): put_todo(user_id=email, description=todo_form.description.data) flash("Tu tarea se creo con éxito!") return redirect(url_for("hello")) return render_template("hello.html", **context)
def hello(): #obtenemos la ip del usuario #obtener la ip desde las cookie y no desde el response user_ip = session.get('user_ip') #para poder desplegar el username, lo obtendremos y lo agregaremos al contexto username = current_user.id todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form, } if todo_form.validate_on_submit(): put_todo(user_id=username, descripcion=todo_form.descripcion.data) flash('Tu tarea se creo con éxito') return redirect(url_for('hello')) #validate_on_submit: recibe los datos de la forma y los valida #la ruta detecta cuando se envia un POST y valida la forma (form) #partimos la funcion en 2 #si se hace un POST validamos la info, si hace un GET envia un contexto return render_template('hello.html', **context)
def hello(): user_ip = session.get('user_ip') # login_form = LoginForm() username = current_user.id todo_form = TodoForm() delete_todo_form = DeleteTodoFrom() update_todo_form = UpdateTodoFrom() ctx = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_todo_form': delete_todo_form, 'update_todo_form': update_todo_form } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash('Tu tarea se creo con éxito!') return redirect(url_for('hello')) return render_template('hello.html', **ctx)
def hello(): user_ip = session.get( 'user_ip') #optener dato de la ip oculta por seguridad en sessions username = current_user.id #Todo form todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash('Tarea agregada') return redirect(url_for('hello')) return render_template('hello.html', **context) #renderear un template
def hello(): user_ip = session.get( 'user_ip') # The user's IP is obtained from the cookie username = current_user.id todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form, } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash('Your task was created!') return redirect(url_for('hello')) # The context varible is expanded for pass every key:value as single variables return render_template('hello.html', **context)
def hello(): """In hello we display the ip""" user_ip = session.get('user_ip') username = current_user.id context = { 'user_ip': user_ip, 'todos': get_todos(username), 'username': username, } return render_template('hello.html', **context)
def hello(): context = { 'delete_form': DeleteTodoForm(), 'edit_form': EditTodoForm(), 'todos': get_todos(user_id=current_user.id), 'username': current_user.id, 'user_ip': session.get('user_ip') } return render_template('hello.html', **context)
def hello(): user_ip = session.get('user_ip') username = current_user.id context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username } return render_template('hello.html', **context)
def hello(): user_ip = session.get('user_ip') username = session.get('username') todos = [todo.to_dict()['description'] for todo in get_todos(username)] context = {'user_ip': user_ip, 'todos': todos, 'username': username} users = get_users() for user in users: #users is a snapshot print(user.id) print(user.to_dict()) return render_template('hello.html', **context)
def hello(): user_ip = session.get('user_ip') login_form = LoginForm() username = session.get('username') context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username } return render_template('hello.html', **context)
def hello(): user_ip = session.get('user_ip') username = current_user.id todo_form = TodoForm() context = { 'user_ip': user_ip, 'todos': get_todos(username), 'username': username, 'todo_form': todo_form, } if todo_form.validate_on_submit(): put_todo(username, todo_form.description.data) flash('Task created') return redirect(url_for('hello')) return render_template('hello.html', **context)
def login(): try: body = request.get_json() username = body["username"] password = body["password"] user_doc = get_user(username) if user_doc.to_dict() is not None: password_from_db = user_doc.to_dict()["password"] if check_password_hash(password_from_db, password): session['username'] = username todo_list = get_todos(user_id=username) all_todo_dict = {"username": username} todo_array = [] for todo in todo_list: todo_elements = todo.to_dict() todo_elements["id"] = todo.id todo_array.append(todo_elements) all_todo_dict["todos"] = todo_array return make_response(error=False, message="Successful Login", status=201, data=all_todo_dict) else: return make_response(error=True, message="Password is Wrong", status=400) else: return make_response(error=True, message="User does not exits", status=400) except (KeyError, TypeError): # If invalid body schema message = 'username and password are needed' return make_response(error=True, message=message, status=400) except Exception: # Return a 500 error if something went wrong return make_response(error=True, message='Server serror', status=500)
def hello_world(): user_ip = session.get('user_ip') username = session.get('username') context = { 'user_ip': user_ip, 'todo':get_todos(user_id=username), 'username': username } users = get_users() for user in users: print(user.id) print(user.to_dict()['password']) return render_template('hello-world.html', **context)
def hello(): username = current_user.id email = current_user.email todo_form = TodoForm() context = { 'todos': get_todos(username), 'username': username, 'email': email, 'todo_form': todo_form, } if request.method == 'POST': todo_put(user_id=username, description=todo_form.description.data) flash('Task created', 'success') return redirect(url_for('hello')) return render_template('hello.html', **context)
def hello(): username = current_user.id todo_form = form.TodoForm() contex = { 'user_ip': session.get('user_ip'), 'todos': db.get_todos(username), 'username': username, 'todo_form': todo_form } if todo_form.validate_on_submit(): description = todo_form.description.data db.todo_put(username, description) flash('Tarea agregada con exito') return render_template('hello.html', **contex)
def hello(): todos = ['TODO 1', 'TODO 2', 'TODO 3'] user_ip = session.get('user_ip') username = current_user.id context = { "user_ip": user_ip, "todos": get_todos(user_id=username), "username": username } users = get_users() for user in users: print(user.id) print(user.to_dict()['password']) return render_template('hello.html', **context)
def home(): username = current_user.id todos = get_todos(username) todo_form = TodoForm() delete_todo_form = DeleteTodoForm() update_todo_form = UpdateTodoForm() context = { "username": username, "todos": todos, "todo_form": todo_form, "delete_todo_form": delete_todo_form, "update_todo_form": update_todo_form } if todo_form.validate_on_submit(): put_todos(user_id=username, description=todo_form.description.data) flash("TODO registrada con exito") return redirect(url_for("app.home")) return render_template("app/home.html", **context)
def hello(): user_ip = session.get('user_ip') username = current_user.id todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateForm() context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, "todo_form": todo_form, "delete_form": delete_form, "update_form": update_form } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash("La tarea fue creada exitosamente") return redirect(url_for("hello")) return render_template("hello.html", **context)
def hello(): user_ip = session.get('user_ip') print(user_ip) quit() username = current_user.id todo_form = TodoForm() context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash('tu tarea se creo con exito') return redirect(url_for('hello')) return render_template('hello.html', **context)
def hello(): #Get the Cookie from the browser user_ip = session.get('user_ip') username = current_user.id todo_form = TodoForm() #Save all the parameters parameter = { 'user_ip':user_ip, 'todos':get_todos(username), 'username': username, 'todo_form': todo_form } if todo_form.validate_on_submit(): todo_put(username, todo_form.description.data) flash('Task created sucesfully!') return redirect(url_for('hello')) return render_template('hello.html', **parameter)
def hello(): user_ip = session.get('user_ip') username = current_user.id todo_form = TodoForm() delete_form = deleteTodoForm() updateform = updateForm() ''' Creo instancia del form ''' ctx = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'updateform': updateform } if todo_form.validate_on_submit(): put_todo(username, todo_form.description.data) flash("La tarea se agregó con exito") return redirect(url_for('hello')) return render_template('hello.html', **ctx)
def hello(): user_ip = session.get('user_ip') username = current_user.id todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form, } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash(' Tarea creada con exito') return redirect(url_for('hello')) return render_template('hello.html', **context)
def board(): ip_user = session.get('ip_user') username = current_user.id todo_form = TodoForm() update_form = UpdateForm() delete_form = DeleteForm() params = { "ip_user": ip_user, 'username': username, "todos": get_todos(username), 'todo_form': todo_form, 'update': update_form, 'delete': delete_form, } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash("Agregado nuevo recordatorio.") return redirect(url_for("board")) return render_template('board.html', **params)
def welcome(): ip_user = session.get('ip_user') username = current_user.id todo_form = TodoForm() update_form = UpdateForm() delete_form = DeleteForm() params = { "ip_user": ip_user, 'username': username, "todos": get_todos(username), 'todo_form': todo_form, 'update': update_form, 'delete': delete_form, } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash("Todo Added.") return redirect(url_for("welcome")) return render_template('welcome.html', **params)
def hello(): #obtenemos la ip del usuario desde la cookie user_ip = session.get('user_ip') username = current_user.id #ahora viene desde el login_form todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() # creamos un contexto para las variables del template context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash('Your task was created successfully') return redirect(url_for('hello')) return render_template('hello.html', **context)
def hello(): user_ip = session.get('user_ip') username = current_user.id todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { 'user_ip': user_ip, 'todos': get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash('Task created successfully') return redirect(url_for('hello')) # two ** before a dictionary expend it automatically return render_template('hello.html', **context)