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 = request.cookies.get('user_ip') user_ip = session.get('user_ip') username = current_user.id todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() #return "Hello World Platzi, tu IP es {}".format(user_ip) context = { 'user_ip': user_ip, 'todos': get_todos(username=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form } if todo_form.validate_on_submit(): put_todos(user_id=username, description=todo_form.description.data, done=0) flash('Tu tarea se creo con exito!') return redirect(url_for('hello')) return render_template('hello.html', **context) # Los ** es para expandir las variables
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(): user_ip = session.get('user_ip') username = current_user.id todo_form = TodoForm() delete_todo = DeleteTodoForm() update_todo = UpdateTodoForm() context = { 'user_ip': user_ip, 'todos': get_todos(username=username), 'username': username, 'todo_form': todo_form, 'delete_todo': delete_todo, 'update_todo': update_todo } if todo_form.validate_on_submit(): description = todo_form.description.data add_todo(username, description) flash('La tarea se creo correctamente') return redirect(url_for('hello')) return render_template('hello.html', **context)
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(): #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') #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') username = current_user.id todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() ctx = { '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(): description = todo_form.description.data create_todo(username, description) flash('Tarea Creada con éxito') return redirect(url_for('hello')) return render_template('hello.html', **ctx)
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 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(): username = current_user.id todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { '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('Tu tarea se creo con éxito!') return redirect(url_for('hello')) 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_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { 'user_ip': user_ip, 'to_dos': 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') 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() context = { "user_ip": user_ip, "todos": get_todos(user_id=username), 'username': username, 'todo_form': todo_form, 'delete_form': delete_form } if todo_form.validate_on_submit(): put_todo(user_id=username, description=todo_form.description.data) flash('La tarea se creo con exito') return redirect(url_for('hello')) return render_template("hello.html", **context)
def index(): username = current_user.id todos = get_todos(user_id=username) todo_form = TodoForm() delete_form = DeleteTodoForm() update_form = UpdateTodoForm() context = { 'username': username, 'todos': todos, 'todo_form': todo_form, 'delete_form': delete_form, 'update_form': update_form } if todo_form.validate_on_submit(): put_todo(username, todo_form.description.data) flash('Tu tarea fue creada') return redirect(url_for('index')) return render_template('index.html', **context)
def hello(): #user_ip = request.cookies.get('user_ip') 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_todos(user_id=username, description=todo_form.description.data) flash('Task created') return redirect(url_for('hello')) return render_template('hello.html', **context)
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)
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('Added task') return redirect(url_for('hello')) # NOTE: ** expand dictionary 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), # levanto los todos de firestore '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 OK') return redirect(url_for('hello')) return render_template('hello.html', **context)