Example #1
0
def present_main():
	# check for a cookie, if present, then extract value
	username = login_check()
	if (username == None):
		print "main: can't identify user...redirecting to signup"
		bottle.redirect("/login")
	
	connection = pymongo.Connection(connection_string, safe=True)
	me = user.get_user(connection, username)
	friends = me['friends']
	friends_requests = me['friends_requests']
	challenges_ids = me['challenges']
	challenges = []
	for challenge_id in challenges_ids:
		challenges.append(achievement.find_achievement_by_id(connection, challenge_id))
	
	achievements_ids = me['achievements']
	achievements = []
	for achievement_id in achievements_ids:
		challenges.append(achievement.find_achievement_by_id(connection, achievement_id))
		
	return bottle.template("main", 
						{'username':username, 
						  'friends':friends,
						  'friends_requests':friends_requests,
						  'challenges':challenges,
						  'achievements':achievements,
						})
Example #2
0
def present_main():
    # check for a cookie, if present, then extract value
    username = login_check()
    if (username == None):
        print "main: can't identify user...redirecting to signup"
        bottle.redirect("/login")

    connection = pymongo.Connection(connection_string, safe=True)
    me = user.get_user(connection, username)
    friends = me['friends']
    friends_requests = me['friends_requests']
    challenges_ids = me['challenges']
    challenges = []
    for challenge_id in challenges_ids:
        challenges.append(
            achievement.find_achievement_by_id(connection, challenge_id))

    achievements_ids = me['achievements']
    achievements = []
    for achievement_id in achievements_ids:
        challenges.append(
            achievement.find_achievement_by_id(connection, achievement_id))

    return bottle.template(
        "main", {
            'username': username,
            'friends': friends,
            'friends_requests': friends_requests,
            'challenges': challenges,
            'achievements': achievements,
        })
Example #3
0
def main():
    # check for a cookie, if present, then extract value
    username = login_check()
    if username is None:
        print "main: can't identify user...redirecting to signup"
        redirect("/login")

    connection = pymongo.Connection(connection_string, safe=True)
    me = user.get_user(connection, username)
    friends = me['friends']
    friends_requests = me['friends_requests']
    challenges_ids = me['challenges']
    challenges = []
    for challenge_id in challenges_ids:
        challenges.append(
            achievement.find_achievement_by_id(connection, challenge_id))

    challenges_requests_ids = me['challenges_requests_from_friends']
    challenges_requests = []
    for challenge_id in challenges_requests_ids:
        challenge = {
            "achievement":
            achievement.find_achievement_by_id(connection,
                                               challenge_id['achievement']),
            "from":
            challenge_id['from']
        }
        challenges_requests.append(challenge)

    achievements_ids = me['achievements']
    achievements = []
    for achievement_id in achievements_ids:
        achievements.append(
            achievement.find_achievement_by_id(connection, achievement_id))

    achievements_requests_ids = me['achievements_requests_from_friends']
    achievements_requests = []
    for achievement_id in achievements_requests_ids:
        achievement_id = {
            "achievement":
            achievement.find_achievement_by_id(connection,
                                               achievement_id['achievement']),
            "from":
            achievement_id['from']
        }
        achievements_requests.append(achievement_id)

    return template(
        "main", {
            'username': username,
            'friends': friends,
            'friends_requests': friends_requests,
            'challenges': challenges,
            'challenges_requests_from_friends': challenges_requests,
            'achievements': achievements,
            'achievements_requests_from_friends': achievements_requests
        })
Example #4
0
def main():
    # check for a cookie, if present, then extract value
    username = login_check()
    if username is None:
        print "main: can't identify user...redirecting to signup"
        redirect("/login")

    connection = pymongo.Connection(connection_string, safe=True)
    me = user.get_user(connection, username)
    friends = me['friends']
    friends_requests = me['friends_requests']
    challenges_ids = me['challenges']
    challenges = []
    for challenge_id in challenges_ids:
        challenges.append(achievement.find_achievement_by_id(connection, challenge_id))

    challenges_requests_ids = me['challenges_requests_from_friends']
    challenges_requests = []
    for challenge_id in challenges_requests_ids:
        challenge = {"achievement": achievement.find_achievement_by_id(connection, challenge_id['achievement']),
                     "from": challenge_id['from']}
        challenges_requests.append(challenge)

    achievements_ids = me['achievements']
    achievements = []
    for achievement_id in achievements_ids:
        achievements.append(achievement.find_achievement_by_id(connection, achievement_id))

    achievements_requests_ids = me['achievements_requests_from_friends']
    achievements_requests = []
    for achievement_id in achievements_requests_ids:
        achievement_id = {"achievement": achievement.find_achievement_by_id(connection, achievement_id['achievement']),
                          "from": achievement_id['from']}
        achievements_requests.append(achievement_id)

    return template("main",
        {'username': username,
         'friends': friends,
         'friends_requests': friends_requests,
         'challenges': challenges,
         'challenges_requests_from_friends': challenges_requests,
         'achievements': achievements,
         'achievements_requests_from_friends': achievements_requests
        })
Example #5
0
def main():
    # check for a cookie, if present, then extract value
    username = login_check()
    if username is None:
        print "main: can't identify user...redirecting to signup"
        redirect("/login")

    connection = pymongo.Connection(connection_string, safe=True)
    friend_name = None
    try:
        friend_name = request.query['friend']
    except KeyError:
        redirect("/main")

    friend = user.get_user(connection, friend_name)
    friends = friend['friends']
    challenges_ids = friend['challenges']
    challenges = []
    for challenge_id in challenges_ids:
        challenges.append(
            achievement.find_achievement_by_id(connection, challenge_id))

    achievements_ids = friend['achievements']
    achievements = []
    for achievement_id in achievements_ids:
        challenges.append(
            achievement.find_achievement_by_id(connection, achievement_id))

    me = user.get_user(connection, username)

    return template(
        "friend", {
            'username': username,
            'friend': friend_name,
            'isFriend': friend_name in me['friends'],
            'friends': friends,
            'challenges': challenges,
            'achievements': achievements,
        })
Example #6
0
def achievement_unlocked_badge():
    # check for a cookie, if present, then extract value
    username = login_check()
    if username is None:
        print "main: can't identify user...redirecting to signup"
        redirect("/signup")
    connection = pymongo.Connection(connection_string, safe=True)

    try:
        achievement_id = bson.objectid.ObjectId(request.query['achievement'])
        achievement_value = achievement.find_achievement_by_id(connection, achievement_id)
        return template("achievement_unlocked_badge",
            dict(username=username, achievement=achievement_value))
    except TypeError, bson.errors.InvalidId:
        redirect("/main")
Example #7
0
def main():
    # check for a cookie, if present, then extract value
    username = login_check()
    if username is None:
        print "main: can't identify user...redirecting to signup"
        redirect("/login")

    connection = pymongo.Connection(connection_string, safe=True)
    friend_name = None
    try:
        friend_name = request.query['friend']
    except KeyError:
        redirect("/main")

    friend = user.get_user(connection, friend_name)
    friends = friend['friends']
    challenges_ids = friend['challenges']
    challenges = []
    for challenge_id in challenges_ids:
        challenges.append(achievement.find_achievement_by_id(connection, challenge_id))

    achievements_ids = friend['achievements']
    achievements = []
    for achievement_id in achievements_ids:
        challenges.append(achievement.find_achievement_by_id(connection, achievement_id))

    me = user.get_user(connection, username)

    return template("friend",
        {'username': username,
         'friend': friend_name,
         'isFriend': friend_name in me['friends'],
         'friends': friends,
         'challenges': challenges,
         'achievements': achievements,
        })
Example #8
0
def achievement_unlocked_badge():
    # check for a cookie, if present, then extract value
    username = login_check()
    if username is None:
        print "main: can't identify user...redirecting to signup"
        redirect("/signup")
    connection = pymongo.Connection(connection_string, safe=True)

    try:
        achievement_id = bson.objectid.ObjectId(request.query['achievement'])
        achievement_value = achievement.find_achievement_by_id(
            connection, achievement_id)
        return template("achievement_unlocked_badge",
                        dict(username=username, achievement=achievement_value))
    except TypeError, bson.errors.InvalidId:
        redirect("/main")