Пример #1
0
def update_user():
    password =  request.forms.get('password').strip()
    conpassword = request.forms.get('conpassword').strip()
    email = request.forms.get('email').strip()
    user_details = logged_in_user()
    token =  request.forms.get('form_token').strip()
    user_session = request.environ.get('beaker.session')
    if token == user_session["token"]:
	del user_session["token"]
	if user_details["id"]:
	    if password is not '' and conpassword is not '' and password == conpassword:
		try:
		    my_return = Users.update_password(user_details["id"] , password)
		    if my_return:
			mymail.send_mail( email=user_details['email'], name=user_details['username'])
			return template("registration",success_message = success_message,  username=user_details["username"] ) 
		    else:
			 template("edit_user", my_top =0, error_message  = error_message, email = user_details["email"], username=user_details["username"])
			 
		except MySQLdb.OperationalError , e:
		    return  template("edit_user", my_top =0, error_message  = error_message, email = user_details["email"], username=user_details["username"])
	    else:
		redirect("/user/edit")
	else:
	    redirect("/user/edit")
Пример #2
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')
Пример #3
0
def create_comment():
    message = request.forms.get('articleComment').strip()
    review_id =  request.forms.get('review_id')
    s = request.environ.get('beaker.session')
    if logged_in_user() is None:
	redirect('/login')
    else:
	try:
	    user_details = logged_in_user()
	    user_id = user_details['id']
	    reviews =  return_reviews()
	    (review, comments) =  Comments.create(user_id, review_id, message).save()
	    #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)
Пример #4
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')
Пример #5
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")
Пример #6
0
def get_edit_user_form():
    try:
	user_details = logged_in_user()
	if user_details:
	    email =  user_details['email']
	    username = user_details['username']
            token = add_token(helper.token)
            return template("edit_user", my_top = 0,  token=token, email=email, username=username)
	else:
	    redirect("/login")
    except MySQLdb.OperationalError ,e:
	redirect("/login")
Пример #7
0
def get_all_Reviews():
    try:
        start_point = 1
	reviews =  return_reviews()
	if reviews :
	    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) #I need to add pagination somewhere, and 
	else:
	    return template("list_reviews", reviews=reviews, start_point=start_point)
    except MySQLdb.OperationalError, e:
	redirect('/index')
Пример #8
0
def edit_review():
    title =  request.forms.get('title').strip()
    entry =  request.forms.get('entry').strip()
    review_id =  int(request.forms.get('review_id').strip())
    branch_id =  int(request.forms.get('option-value'))
    #id =  request.forms.get('id')
    try:
	user_details  = logged_in_user()
	id = user_details["id"]
	url = helper.generate_url(user_details["username"], title)
    except TypeError, e:
	redirect("/index")
Пример #9
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")
Пример #10
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')
Пример #11
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')
Пример #12
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')
Пример #13
0
def vote_down(id):
    try:
	logged_id = logged_in_user()['id']
    except TypeError, e:
	redirect('/reviews/{}'.format(id))
Пример #14
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:
	    reviews =  return_reviews()