Example #1
0
def _get_world_rank():
    dbsession = DBSession()
    world_top = dbsession.query(Friend).order_by(desc(Friend.score)).\
            limit(100).all()
    world_top_users = dbsession.query(User).order_by(desc(User.score)).\
            limit(100).all()
    world_top.extend(world_top_users)
    return sorted(world_top, key=lambda k:k.score, reverse=True)
Example #2
0
def _get_world_rank():
    dbsession = DBSession()
    world_top = dbsession.query(Friend).order_by(desc(Friend.score)).\
            limit(100).all()
    world_top_users = dbsession.query(User).order_by(desc(User.score)).\
            limit(100).all()
    world_top.extend(world_top_users)
    return sorted(world_top, key=lambda k: k.score, reverse=True)
Example #3
0
def _get_all_national_schools():
    dbsession = DBSession()
    schools = dbsession.query(NationalSchools.rank, NationalSchools.name,
                    NationalSchools.short_name).all()
    names = [s.name for s in schools]
    short_names = [s.short_name for s in schools]
    return dict(names=names, short_names=short_names)
Example #4
0
def _get_all_world_schools():
    dbsession = DBSession()
    schools = dbsession.query(WorldSchools.rank, WorldSchools.name,
                    WorldSchools.short_name).all()
    names = [s.name for s in schools]
    short_names = [s.short_name for s in schools]
    return dict(names=names, short_names=short_names)
Example #5
0
def _get_all_national_schools():
    dbsession = DBSession()
    schools = dbsession.query(NationalSchools.rank, NationalSchools.name,
                              NationalSchools.short_name).all()
    names = [s.name for s in schools]
    short_names = [s.short_name for s in schools]
    return dict(names=names, short_names=short_names)
Example #6
0
def _get_all_world_schools():
    dbsession = DBSession()
    schools = dbsession.query(WorldSchools.rank, WorldSchools.name,
                              WorldSchools.short_name).all()
    names = [s.name for s in schools]
    short_names = [s.short_name for s in schools]
    return dict(names=names, short_names=short_names)
Example #7
0
def dashboard(request):
    dbsession = DBSession()
    settings = request.registry.settings
    cookie = facebook.get_user_from_cookie(request.cookies,
                                           settings['facebook.app.id'],
                                           settings['facebook.app.secret'])
    if cookie:
        graph = _get_graph(cookie['access_token'])
        profile = graph.get_object('me')
        fb_id = profile['id']
        user = dbsession.query(User).filter(User.fb_id == fb_id).first()
        if not user:
            user = User(
                fb_id, cookie['access_token'], profile['updated_time'],
                profile['name'], 'gender' in profile and profile['gender']
                or None, 'location' in profile and profile['location']['name']
                or None, _get_lifescore(profile))
            dbsession.add(user)
            dbsession.commit()
            return dict(profile=profile,
                        score=user.score,
                        friends_id=_get_friends_id(graph).encode(
                            'ascii', 'ignore'),
                        world_rank=_get_world_rank()[0:20])
        elif user.fb_access_token != cookie['access_token']:
            user.fb_access_token = cookie['access_token']
            if user.fb_updated_time != profile['update_time']:
                user.score = _get_lifescore(profile)
            dbsession.merge(user)
            dbsession.commit()

        try:
            debug = request.GET['debug']
            return dict(profile=profile,
                        score=user.score,
                        friends_id=_get_friends_id(graph).encode(
                            'ascii', 'ignore'),
                        world_rank=_get_world_rank()[0:20])
        except KeyError:
            pass

        return dict(profile=profile,
                    score=user.score,
                    friends_rank=_get_friends(user)[0:20],
                    world_rank=_get_world_rank()[0:20])
    else:
        return HTTPFound(location=route_url('home', request))
Example #8
0
def dashboard(request):
    dbsession = DBSession()
    settings = request.registry.settings
    cookie = facebook.get_user_from_cookie(request.cookies,
                                           settings['facebook.app.id'],
                                           settings['facebook.app.secret'])
    if cookie:
        graph = _get_graph(cookie['access_token'])
        profile = graph.get_object('me')
        fb_id = profile['id']
        user = dbsession.query(User).filter(User.fb_id==fb_id).first()
        if not user:
            user = User(fb_id, cookie['access_token'], profile['updated_time'], 
                       profile['name'], 'gender' in profile and
                        profile['gender'] or None, 'location' in profile and
                        profile['location']['name'] or None, 
                        _get_lifescore(profile))
            dbsession.add(user)
            dbsession.commit()
            return dict(profile=profile, score=user.score,
                        friends_id=_get_friends_id(graph).encode('ascii','ignore'),
                        world_rank=_get_world_rank()[0:20])
        elif user.fb_access_token != cookie['access_token']:
            user.fb_access_token = cookie['access_token']
            if user.fb_updated_time != profile['update_time']:
                user.score = _get_lifescore(profile)
            dbsession.merge(user)
            dbsession.commit()

        try:
            debug = request.GET['debug']
            return dict(profile=profile, score=user.score,
                        friends_id=_get_friends_id(graph).encode('ascii','ignore'),
                        world_rank=_get_world_rank()[0:20])
        except KeyError:
            pass
        
        return dict(profile=profile, score=user.score, 
                    friends_rank=_get_friends(user)[0:20], 
                    world_rank=_get_world_rank()[0:20])
    else:
        return HTTPFound(location=route_url('home', request))
Example #9
0
def _get_jobs():
    dbsession = DBSession()
    jobs = dbsession.query(Job.prestige, Job.job).all()
    return dict([(job.job.lower(), job.prestige) for job in jobs])
Example #10
0
def _get_all_majors():
    dbsession = DBSession()
    majors = dbsession.query(Major.name).order_by(
        desc(Major.avg_starting_salary)).limit(40)
    return dict([(m.name, 1) for m in majors])
Example #11
0
def _get_friends(user):
    dbsession = DBSession()
    return dbsession.query(Friend).filter(Friend.user_id==user.id).\
            order_by(desc(Friend.score)).all()
Example #12
0
def _get_friends(user):
    dbsession = DBSession()
    return dbsession.query(Friend).filter(Friend.user_id==user.id).\
            order_by(desc(Friend.score)).all()
Example #13
0
def _get_top_companies():
    dbsession = DBSession()

    companies = dict([(c.name, 1)
                      for c in dbsession.query(Company.name).all()])
    return companies
Example #14
0
def _get_jobs():
    dbsession = DBSession()
    jobs = dbsession.query(Job.prestige, Job.job).all()
    return dict([(job.job.lower(), job.prestige) for job in jobs])
Example #15
0
def _get_all_majors():
    dbsession = DBSession()
    majors = dbsession.query(Major.name).order_by(
        desc(Major.avg_starting_salary)).limit(40)
    return dict([(m.name, 1) for m in majors])
Example #16
0
def _get_top_companies():
    dbsession = DBSession()
    
    companies = dict([(c.name, 1) 
                      for c in dbsession.query(Company.name).all()])
    return companies
Example #17
0
def _get_user_from_fb_id(fb_id):
    dbsession = DBSession()
    return dbsession.query(User).filter(User.fb_id==fb_id).first()
Example #18
0
def _get_user_from_fb_id(fb_id):
    dbsession = DBSession()
    return dbsession.query(User).filter(User.fb_id == fb_id).first()