def setting(): # user_name from my_project.current_username import user_name form = PasswordForm() deativate_user_form = DeactivateUserForm() user = User.query.filter_by(email=current_user.email).first() if form.validate_on_submit(): old_password = form.old_password.data new_password = form.new_password.data if user.check_password(password=old_password): print("Password Matches!") user.set_password(new_password) db.session.add(user) db.session.commit() print("Password updated!") return redirect(url_for('setting_view_bp.setting')) else: print("Wrong password") elif deativate_user_form.validate_on_submit(): if user is not None: db.session.delete(user) db.session.commit() print("user deleted") return redirect('/') print("form deactivate btn clicked") return render_template('setting/setting.html', form=form, deativate_user_form=deativate_user_form, profile_image=user_name())
def create_blog(): form = CreateBlog() # Username from my_project.current_username import user_name if form.validate_on_submit(): dish_name = form.dish_name.data dish_receipe = form.dish_reciepe.data count = db.session.query(Blog).filter_by(email=current_user.email).count() blog = Blog(email=current_user.email, dish_name=dish_name, dish_receipe=dish_receipe, count=count) print(blog) db.session.add(blog) db.session.commit() flash("Blog created successfully") return redirect(url_for('blog_bp.view_blogs')) return render_template('blogs/create_blog.html', form=form, profile_image=user_name())
def update_blog(blog_id): # Username from my_project.current_username import user_name blog_to_be_updated = Blog.query.filter_by(blog_id=blog_id).first() print(blog_to_be_updated.dish_name) print(blog_to_be_updated.dish_receipe) form = CreateBlog() if form.validate_on_submit(): if form.dish_name.data: blog_to_be_updated.dish_name = form.dish_name.data if form.dish_reciepe.data: blog_to_be_updated.dish_receipe = form.dish_reciepe.data if form.dish_img.data: print(form.dish_img.data) pic = add_dish_pic(pic_upload=form.dish_img.data, blog_id=blog_id) blog_to_be_updated.recipe_img = pic print("Image uploaded") # blog_to_be_updated.date = datetime.utcnow db.session.add(blog_to_be_updated) db.session.commit() return redirect(url_for('blog_bp.view_blogs')) elif request.method == "GET": form.dish_name.data = blog_to_be_updated.dish_name # form.email.data = current_user.email form.dish_reciepe.data = blog_to_be_updated.dish_receipe return render_template('blogs/update_blog.html', blog=blog_to_be_updated, form=form, profile_image=user_name())
def view_blogs(): # Username from my_project.current_username import user_name blogs_list = Blog.query.order_by(desc(Blog.date)).all() return render_template('blogs/view_blogs.html', blogs_list=blogs_list, profile_image=user_name())
def view_blog(blog_id): # Username from my_project.current_username import user_name blog = Blog.query.filter_by(blog_id=blog_id).first() return render_template('blogs/blog.html', blog=blog, profile_image=user_name())
def account_view(): form = UpdateAccount() # Username from my_project.current_username import user_name user_info = UserInfo.query.filter_by(email=current_user.email).first() blogs_list = Blog.query.order_by(desc(Blog.date)).filter_by(email=current_user.email).all() if form.validate_on_submit(): first_name = form.first_name.data last_name = form.last_name.data email = form.email.data # disabled print(current_user.email) print("On subbmit") print(form.profile_pic.data) if form.profile_pic.data: print(form.profile_pic.data) pic = add_profile_pic(pic_upload=form.profile_pic.data, email=current_user.email) user_info.profile_image = pic print("Image uploaded") user_info.first_name = first_name user_info.last_name = last_name db.session.add(user_info) db.session.commit() return redirect(url_for('blog_bp.view_blogs')) # return redirect(request.url) elif request.method == "GET": form.first_name.data = user_info.first_name form.email.data = current_user.email form.last_name.data = user_info.last_name return render_template('account/update_account.html', form=form, user_info=user_info, blogs_list=blogs_list, profile_image=user_name())