def food(): user = session.get('username') allWordSave = Reviews.objects() numberOfWords = 0 for i in allWordSave: if i.username == user: numberOfWords += 1 list_audio = [] list_word = [] list_image = [] list_pronunciation = [] list_id = [] # get all document from dabase total_food = Food.objects() for i in total_food: audio = i.audio_link word = i.word image = i.image pronunciation = i.pronunciation id = i.id list_audio.append(audio) list_word.append(word) list_image.append(image) list_pronunciation.append(pronunciation) list_id.append(id) return render_template("food.html", list_audio=list_audio, list_word=list_word, list_image=list_image, list_pronunciation=list_pronunciation, list_id=list_id, user=user, numberOfWords=numberOfWords)
def update_food(food_id): f = Food.objects().with_id(food_id) if request.method == "GET": return render_template("update_food_form.html", food=f) elif request.method == "POST": form = request.form t = form["title"] l = form["link"] # Update - Automic Update f.update(set__title=t, set__link=l) return "OK"
def admin(): user = session.get('username') if user is None: return redirect(url_for('login')) else: total_vegetablesAndFruits = Vegetablesfruits.objects() total_animals = Animals.objects() total_food = Food.objects() total_actions = Actions.objects() x = len(total_vegetablesAndFruits) y = len(total_animals) z = len(total_food) if request.method == 'GET': videos = Video.objects() return render_template( "admin.html", total_vegetablesAndFruits=total_vegetablesAndFruits, total_animals=total_animals, total_food=total_food, total_actions=total_actions, x=x, y=y, z=z, videos=videos) elif request.method == 'POST': form = request.form link = form['link'] ydl = YoutubeDL() data = ydl.extract_info(link, download=False) title = data['title'] thumbnail = data['thumbnail'] views = data['view_count'] youtube_id = data['id'] link = link video = Video( title=title, thumbnail=thumbnail, views=views, youtube_id=youtube_id, link=link, ) video.save() return redirect(url_for('admin'))
def food_detail(food_id): f = Food.objects().with_id(food_id) # Invalid Id, Not Found return render_template("food_detail.html", food=f)
def menu(): if "token" in session: food_objects = Food.objects() return render_template("menu.html", food_list=food_objects) else: return "Forbidden"
import mlab from models.food import Food mlab.connect() # 1. Create # B1: Create a food f = Food(title="Banh sai", link="<<link sai>>") # B2: Save it # f.save() # 2. Read # B1: Get cursor f_objects = Food.objects() # Lazy loading # Same as list # B2: Process cursor # f_first = f_objects[0] # Thực sự truyền dữ liệu # print(f_first.title) # print(f_first.link) # print(len(f_objects)) # print(f_objects.count()) # Bảo database đếm # for f in f_objects: # print(f.title) # print(f.link) # print("----------------") # f = f_objects[4] # f.update(set__title= "Banh rat rat ngon", set__link= "Link ngon") # #op__prop: hành động __ cần thay đổi # # chỉ xảy ra trong database
def ngay_le(food_id): food = Food.objects().with_id(food_id) return render_template("ngay_le.html", food=food)
def ngayle(): foods = Food.objects(chu_de="ngayle") return render_template("ngayle.html", foods=foods)
def gia_dinh(food_id): food = Food.objects().with_id(food_id) return render_template("gia_dinh.html", food=food)
def giadinh(): foods = Food.objects(chu_de="family") return render_template("giadinh.html", foods=foods)
def cap_doi(food_id): food = Food.objects().with_id(food_id) return render_template("cap_doi.html", food=food)
def capdoi(): foods = Food.objects(chu_de="couple") return render_template("capdoi.html", foods=foods)
def food_detail(food_id): f = Food.objects().with_id(food_id) # Invalid Id, Not found # if f = None: # print("Not found") return render_template("food_detail.html", food=f)