def addImage(concept, searchWord): form = AddImage() if form.validate_on_submit(): user_img = Image.query.filter_by(image=form.image.data).first() if user_img is None: image = Image(image=form.image.data) image.searchWord = searchWord image.concept = concept image.verified = '0' image.deleted = '0' db.session.add(image) rel_searchWord = SearchWord.query.filter_by(searchWord=searchWord).first() rel_searchWord.num_im = int(rel_searchWord.num_im) + 1 rel_concept = Concept.query.filter_by(concept=concept).first() rel_concept.num_im = int(rel_concept.num_im) + 1 db.session.commit() return redirect(url_for('addImage', searchWord=searchWord, concept=concept)) else: if str(user_img.deleted)=='1': user_img.deleted='0' user_img.timestamp=datetime.utcnow() db.session.commit() images = Image.query.filter_by(concept=concept, searchWord=searchWord, deleted='0').order_by(Image.timestamp.desc()) return render_template("images.html", concept=concept, form=form, searchWord=searchWord, images=images)
def addImage_JSON(concept, searchWord, image): new_image = Image(image=image) new_image.searchWord = searchWord new_image.concept = concept new_image.verified = '0' new_image.deleted = '0' db.session.add(new_image) rel_searchWord = SearchWord.query.filter_by(searchWord=searchWord).first() rel_searchWord.num_im = int(rel_searchWord.num_im) + 1 rel_concept = Concept.query.filter_by(concept=concept).first() rel_concept.num_im = int(rel_concept.num_im) + 1