Ejemplo n.º 1
0
def charms_for_user(username):
    charms = get_charms(username) 
    charms.reverse()
    
    return render_template('charms.html', charms=charms, home_username=request.cookies.get('username'))
Ejemplo n.º 2
0
def profile_data(username):
    start = time.time()
    home_username = request.cookies.get('username')
    myprofile = home_username == username
    print "returning user?", myprofile, username
    print "met", request.cookies
    # TODO test if webcode belongs to session. self profile diff view vs others
    #TODO package user's info into dictionary


    yourself = retrieve_yourself(username)

    if yourself == None:
        msg = "We are experiencing a problem with our servers."
        submsg = ""
        return render_template('error.html', message = msg, sub_message=submsg)


    try:
        user_charms = get_charms(username)
        if not user_charms: # means there was a problem accessing the url to get the charms
            msg = "Sorry, something went wrong on our end."
            submsg = ""
            return render_template('error.html', message=msg, sub_message=submsg)
    except AntiSocialException:
        if home_username == username:
            flash(u"You don't have any charms yet. Go out and meet people!", 'error')
            print "No Charms!"
            msg = "You don't have any charms!"
            submsg = "We need to know something \
                about you before we can recommend anyone. To charm something, \
                take a picture of a project or session QR Code using a QR Reader application. \
                A good QR Reader to download is Google Goggles."
            return render_template('error.html', message=msg, sub_message=submsg)
        else:
            print "has no charms", username
            return render_template('error.html', message = "Also, this user does not have any charms. ")
    except InactiveCharmsException:
        print "inactive charm exception"
        return render_template('error.html', message="Unfortunately, the projects you have charmed are no longer active. Go charm new projects!") 
    except Exception as e:
        print "error1", type(e), e
        flash(u"error", 'error')
        return render_template('error.html', message="We are working on a fix right now.")

    yourself['num_charms']= len(user_charms)
    user_charms.reverse()
    yourself['charms'] = user_charms

    # visiting guest profile
    if not myprofile:
        resp = make_response( render_template("profile.html", yourself=yourself, recommendations=[],
                                sponsor_recs=[], home_username=home_username, my_profile=False))
        resp.set_cookie('username', home_username)
        print "profile load time: ", time.time() - start
        return resp

    recommendations = retrieve_recommendations(username, yourself) 

    sponsor_recs = retrieve_sponsor_recs(username, yourself)

    if username == 'joi':
        yourself['affiliation'] = 'Director'
    resp = make_response( render_template("profile.html", yourself=yourself, recommendations=recommendations,
                sponsor_recs=sponsor_recs, home_username=home_username, my_profile=True))
    resp.set_cookie('username', home_username)
    print "profile load time: ", time.time() - start, "\n\n\n\n\n"
    return resp