def dislike(fotoid, direct='home'): """ Check if dislike doesnt already exist Registers the dislike in the database Redirects to the correct page """ # check the fotoid if not helpers.geldig(fotoid): return helpers.apology("Fill in a valid photo-id") # insert the dislike userid = session["user_id"] if not helpers.h_like(fotoid, userid, '0'): return helpers.apology("You can't like this photo (anymore)") return redirect(url_for(direct))
def photo(fotoid=False): """ Loads a photo with all data """ # if unvalid fotoid apologize if not fotoid: return helpers.apology("Fill in a photo-id") if not helpers.geldig(fotoid): return helpers.apology("Fill in a valid photo-id") # get all data data = helpers.get_foto(fotoid) # Set data for template username, fotoid, foto, caption, titel, date, likes, userid = helpers.foto_data( data) eigenacc = False # try to look if it is his/her own photo, try statement used for not logged in users try: if session["user_id"] == userid: eigenacc = True except: pass # get all other data profielfoto, naam = helpers.pfname(userid) comments = helpers.get_comments(fotoid) aantalcomments = helpers.lengte_comments(comments) welvolg = helpers.volgcheck(username) return render_template("photo.html", eigenacc=eigenacc, userid=userid, welvolg=welvolg, aantalcomments=aantalcomments, fotoid=fotoid, foto=foto, caption=caption, titel=titel, date=date, likes=likes, profielfoto=profielfoto, naam=naam, comments=comments, accountnaam=username)
def comment(fotoid, direct='home'): """ Validates the photoid Registers the comment in the database Redirects to the correct page """ # if not valid fotoid, apologize if not helpers.geldig(fotoid): return helpers.apology("Fill in a valid photo-id") # get the comment comment = request.form.get("uploadcomment") # only insert comment if the comment is not empty if len(comment) != 0: # instert into database helpers.post_comment(fotoid, comment) return redirect(url_for(direct, fotoid=fotoid))
def pack(fotoid=False): """ Gets a fotoid from the pack Shows all relevant data """ # get a valid fotoid (not theirs or one they have "beoordeeld" yet) if not fotoid: fotoid = helpers.volger_fotoid() if not fotoid: return helpers.apology("No more pictures") if not helpers.geldig(fotoid): return redirect(url_for("pack")) # get all data of a photo data = helpers.get_foto(fotoid) # Set up all data for template username, fotoid, foto, caption, titel, date, likes, userid = helpers.foto_data( data) profielfoto, naam = helpers.pfname(userid) comments = helpers.get_comments(fotoid) aantalcomments = helpers.lengte_comments(comments) welvolg = helpers.volgcheck(username) return render_template("pack.html", userid=userid, welvolg=welvolg, aantalcomments=aantalcomments, likes=likes, foto=foto, caption=caption, fotoid=fotoid, titel=titel, date=date, profielfoto=profielfoto, naam=naam, comments=comments, accountnaam=username)