示例#1
0
def rate(user_email):
        form =forms.submitRating()
        person_being_rated=db.session.query(Client).filter(Client.email==user_email).one()

        rating = form.rating.data
        print form.validate_on_submit()
        flag=False
        rating_himself=False
        if request.method == 'POST' and form.validate_on_submit():
            flag=True
            id_of_rater=current_user.id
            id_person_being_rated=person_being_rated.id
            #db.session.query(Rating).filter_by(reviewer_id=1,reviewed_id=1).one()
            if id_of_rater==id_person_being_rated:
                rating_himself=True
                flash(("flash_error", "Are you rating yourself?"))
            try:
                if(not rating_himself):
                    rate=Rating(id_of_rater,id_person_being_rated,rating)
                    db.session.add(rate)
                    db.session.commit()
            except Exception as e:

                flash(("flash_error", "Didn't you rate before?"))
                print str(e)
                return redirect(url_for('AUBOOST.profile',user_email=user_email))
        if flag and not rating_himself:
            flash(("flash_notification", "Successfully added rating."))
        else:
            flash(("flash_error", "Error Setting rating. you probably already rated"))

        return redirect(url_for('AUBOOST.profile',user_email=user_email))
示例#2
0
def profile(user_email):


    form_rating=forms.submitRating()
    form_review=forms.submitReview()
    user=db.session.query(Client).filter(Client.email==user_email).one()

    owner=False
    if user==current_user:
        owner=True

    return render_template('AUBOOST/profile.html',user=user,email=user_email,loggedIn=True,profile_page=True,owner=owner
                           ,form_rating=form_rating,form_review=form_review,courses=user.getCourses())