def review_edit_page(id): id = int(id) try: user = logged_in_user() if not user: add_url( "/review/edit/{}".format(id)) redirect("/login") else: reviews = return_reviews() (review, _) = Reviews.get_by_id( id) return template("review_edit", review = review, reviews=reviews, my_top = user["username"]) except MySQLdb.OperationalError, e: redirect("/index")
def get_review_id(id): id = int(id) try: review, comments = Reviews.get_by_id( id) if review: user = logged_in_user() my_top = user["username"] if user is not None else 0 reviews = Reviews.list_all_reviews() return template("review", review = review, comments=comments, reviews= reviews, my_top=my_top) else: redirect('/index') except MySQLdb.OperationalError, e: redirect('/index')
def create_review_post(): title = request.forms.get('title').strip() branch_id = request.forms.get('option-value') message = request.forms.get('entry').strip() branch_id = branch_id try: user_details = logged_in_user() id = user_details["id"] url = helper.generate_url(user_details["username"], title) review_id = Reviews(id, branch_id, title, message, url).save() reviews = return_reviews() if review_id: review, comments = Reviews.get_by_id(int(review_id)) return template("review", review = review, reviews =reviews, comments = comments, my_top = user_details["username"]) else: redirect('/index') except MySQLdb.OperationalError , e: redirect('/index')
#review, comments = Reviews.get_by_id( review_id) if comments: return template("review" , review = review, comments= comments, my_top = user_details["username"], reviews = reviews) else: return template("review_error", message = "Failed to create your model.Comments", review = review, comments=comments) except MySQLdb.OperationalError , e: return template("review_error", message = "Failed to create your model.Comments", review = review, comments=comments) @app_others.get('/votes/up/:id') def vote_up(id): try: logged_id = logged_in_user()['id'] except TypeError, e: redirect('/reviews/{}'.format(id)) try: review, comments = Reviews.get_by_id( id) if review['user_id'] == logged_id: redirect('/reviews/{}'.format(id)) elif Votes.get_by_review_id_and_user_id(logged_id, id): redirect('/reviews/{}'.format(id)) else: voted = Votes.insert(review['user_id'], logged_id, id, 5) redirect('/reviews/{}'.format(id)) except MySQLdb.OperationalError , e: redirect('/reviews/{}'.format(id)) @app_others.get('/votes/down/:id') def vote_down(id): try: logged_id = logged_in_user()['id'] except TypeError, e: