Пример #1
0
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')
Пример #2
0
def  index():
    try:

	token = add_token(helper.token)
	reviews =  Reviews.list_all_reviews()   
        return template("layout",  my_top=0, reviews = reviews, token = token )
    except MySQLdb.OperationalError ,e:
	redirect("/index")
Пример #3
0
def search():
    search  = request.GET.get('asearch').strip()
    try:
	start_point = 1
	reviews = Reviews.search(search, start_point)
	return template("list_reviews", reviews = reviews ,   start_point = start_point) 
    except MySQLdb.OperationalError, e:
	redirect("/index")
Пример #4
0
def get_sector(id):
    sector_reviews = Reviews.get_sector_by_id(int(id))[::-1][:6]
    try:
	start_point = 1
	user_details = logged_in_user()
	my_top = user_details ["username"] if user_details  else 0	
	reviews = return_reviews()
	return  template("sector_activity", sector_reviews=sector_reviews, reviews=reviews, my_top = my_top, start_point = start_point)		
    except MySQLdb.OperationalError, e:
	redirect('/index')
Пример #5
0
def get_review(a, b , c, name):
    created_time =  "{a}-{b}-{c}".format(a ,b , c)
    try:
        review, comments = Reviews.get_by_url(created_time, name.strip())
	if review:
	    return template("review", review = review, comments=comments)
	else:
	    redirect('/index')
    except MySQLdb.OperationalError, e:
	redirect('/index')
Пример #6
0
def create_review_get():
    try:
        user = logged_in_user()
        if not user:
	    add_url('/review/create')
            redirect('/login')
        else:
	    reviews = Reviews.list_all_reviews()
	    return template("create_review", user_id=user["id"], my_top = user["username"], reviews = reviews)
    except MySQLdb.OperationalError , e:
	redirect('/index')
Пример #7
0
def login_form():
    try:
        user_details = logged_in_user()
	start_point = 1
	reviews =  Reviews.list_all_reviews() 
        if not user_details:
	    token = add_token(helper.token)
            return template("alogin", my_top=1, cond=0,token=token)
        else:
	    return template("layout",my_top=user_details["username"], reviews=reviews)
    except MySQLdb.OperationalError ,e:
	redirect("/index")
Пример #8
0
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")
Пример #9
0
def get_sector_review():
    try:
	    
        sector_id =  request.GET.get("sector_id")
        start_point = int(request.GET.get("start"))
	print sector_id, start_point
	sector_reviews = Reviews.get_sector_by_id(int(sector_id))[::-1][start_point:6+start_point]
	print sector_reviews
        user_details = logged_in_user()
        my_top = user_details ["username"] if user_details  else 0	
        reviews = return_reviews()
        return  template("sector_activity", sector_reviews=sector_reviews, reviews=reviews, my_top = my_top, start_point = start_point )		
    except (MySQLdb.OperationalError, ValueError):
	redirect('/index')
Пример #10
0
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')
Пример #11
0
def login_submit():
    email = request.forms.get('email').strip()
    password = request.forms.get('password').strip()
    obj_session = request.environ.get('beaker.session')
    token =  request.forms.get('form_token').strip()
    if token == obj_session["token"]:
	del obj_session["token"]
        try:
	    user =  Users.find_user_by_password_and_email(password, email)
	    if user:
	        user_session(user['id'])
	        s = request.environ.get('beaker.session')
	        if  s.has_key('url'):
	            url = s['url']
	            del s['url']	
	            redirect(url)	
		reviews =  Reviews.list_all_reviews()		    
	        return template("layout",my_top=user["username"], token=0, reviews=reviews)
	    else:
		return template("alogin", my_top=1, cond=1,token=token, error_message=error_message)  # template("failedlogin")
        except MySQLdb.OperationalError ,e:
	     return template("alogin", my_top=1, cond=1, token=token,error_message=error_message) # template("failedlogin")
Пример #12
0
def return_reviews():
    return Reviews.list_all_reviews()[::-1][:6]
Пример #13
0
	    my_top = user["username"] if user is not None else 0
	    return template("list_reviews", reviews = reviews , start_point=start_point, my_top=my_top) #I need to add pagination somewhere, and 
	else:
	    return template("list_reviews", reviews=reviews, start_point=start_point)
    except MySQLdb.OperationalError, e:
	redirect('/index')

@app_others.route('/reviews/pages')
def get_page():
    start_point = request.GET.get("start")
    try:
        start_point = int(start_point)
    except ValueError, e:
	redirect("/index")
    try:
        reviews = Reviews.list_all_reviews()[::-1][start_point:6+start_point]
	user = logged_in_user()
	my_top = user["username"] if user is not None else 0
	return template("list_reviews" , reviews = reviews, start_point=start_point,my_top=my_top)
    except MySQLdb.OperationalError, e:
	redirect('/index')
    
@app_others.get('/review/edit/:id')
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: