Exemplo n.º 1
0
def project_details(request, slug, template_name='projects/details.html'):
    project_key = ndb.Key('Project', slug)
    project = project_key.get()
    if project is None:
        raise Http404("Project Not Found.")
    
    limit = 100
    cursor = request.GET.get('cursor')
    if cursor:
        cursor = Cursor(urlsafe=cursor)
    
    # TODO: pagination
    user_future = User.query().filter(ndb.GenericProperty('projects') == project.url).fetch_async(100)
    query = Commit.query().filter(Commit.project_slug == slug).order(-Commit.timestamp)
    
    commit_future = query.fetch_page_async(limit, start_cursor=cursor)
    
    commits, next_cursor, more = commit_future.get_result()
    users = user_future.get_result()
    
    if next_cursor is not None:
        next_cursor = next_cursor.urlsafe()
    
    return render_to_response(template_name,
        {'project': project, 'users': users, 'commits': commits,
         'next': next_cursor, 'more': more},
        context_instance=RequestContext(request))
Exemplo n.º 2
0
def users_by_location(request, location_slug, 
                      template_name='people/people_list.html'):

    users = User.query(User.location_slug == location_slug)
    users.order(-ndb.GenericProperty('total')).fetch(1000)

    location = Location.get_by_id(location_slug)
    
    return render_to_response(template_name, 
                             {'users':users, 'location': location, 'slug': location_slug}, 
                             context_instance=RequestContext(request)) 
Exemplo n.º 3
0
def users_by_location(request, location_slug, 
                      template_name='people/people_list.html'):

    users = User.query(User.location_slug == location_slug)
    users.order(-ndb.GenericProperty('total')).fetch(1000)

    location = Location.get_by_id(location_slug)
    
    return render_to_response(template_name, 
                             {'users':users, 'location': location, 'slug': location_slug}, 
                             context_instance=RequestContext(request)) 
Exemplo n.º 4
0
def fix_team(slug, cursor=None, total=0):

    # Don't try to lookup slugs that are the empty string.
    # hint they don't exist!
    if not slug:
        return

    team_slug = slug
    team = Team.get_or_insert(team_slug)

    projects = set([])

    if cursor:
        # we are looping Grab the existing project list so we don't
        # wipe out the earlier runs work
        team_p = getattr(team, 'projects', [])
        projects = set(team_p)
        cursor = Cursor(urlsafe=cursor)

    people = User.query().filter(ndb.GenericProperty('team_slug') == team_slug)

    # Go through the users in chucks
    models, next_cursor, more = people.fetch_page(100, start_cursor=cursor)

    for model in models:
        user_projects = getattr(model, 'projects', [])
        user_total = getattr(model, 'total', 0)
        # Do a little math to figure out how many commits they have
        commits = user_total - (len(user_projects) * 10)
        if commits > 0:
            logging.info('Adding %s to %s', commits, team_slug)
            total += commits
        # Add the users projects to the project set (this filters duplicates)
        projects.update(user_projects)

    # Run update in a transaction
    projects = list(projects)
    total = total + (len(projects) * 10)

    @ndb.transactional
    def txn():
        team = Team.get_or_insert(team_slug)
        team.total = total
        team.projects = projects
        team.put()

    txn()

    if more:
        # We have more people to loop through!!
        return deferred.defer(fix_team,
                              team_slug,
                              cursor=next_cursor.urlsafe(),
                              total=total)
Exemplo n.º 5
0
def project_details(request, slug, template_name='projects/details.html'):
    project_key = ndb.Key('Project', slug)
    project = project_key.get()
    if project is None:
        raise Http404("Project Not Found.")
    
    # TODO: pagination
    users = User.query().filter(ndb.GenericProperty('projects') == project.url).fetch(1000)
    
    return render_to_response(template_name,
        {'project': project, 'users': users},
        context_instance=RequestContext(request))
Exemplo n.º 6
0
def fix_team(slug, cursor=None, total=0):
    
    # Don't try to lookup slugs that are the empty string.
    # hint they don't exist!
    if not slug:
        return
    
    team_slug = slug
    team = Team.get_or_insert(team_slug)
    
    projects = set([])
    
    if cursor:
        # we are looping Grab the existing project list so we don't
        # wipe out the earlier runs work
        team_p = getattr(team, 'projects', [])
        projects = set(team_p)
        cursor = Cursor(urlsafe=cursor)
    
    people = User.query().filter(ndb.GenericProperty('team_slug') == team_slug)
    
    # Go through the users in chucks
    models, next_cursor, more = people.fetch_page(100, start_cursor=cursor)
    
    for model in models:
        user_projects = getattr(model, 'projects', [])
        user_total = getattr(model, 'total', 0)
        # Do a little math to figure out how many commits they have
        commits = user_total - (len(user_projects) * 10)
        if commits > 0:
            logging.info('Adding %s to %s', commits, team_slug)
            total += commits
        # Add the users projects to the project set (this filters duplicates)
        projects.update(user_projects)
    
    
    # Run update in a transaction    
    projects = list(projects)
    total = total + (len(projects) * 10)
    @ndb.transactional
    def txn():
        team = Team.get_or_insert(team_slug)
        team.total = total
        team.projects = projects
        team.put()
    
    txn()

    if more:
        # We have more people to loop through!!
        return deferred.defer(fix_team, team_slug, 
            cursor=next_cursor.urlsafe(), total=total)
Exemplo n.º 7
0
def leaderboard(request, template_name='people/leaderboard.html'):
    limit = 100
    cursor = request.GET.get('cursor')
    if cursor:
        cursor = Cursor(urlsafe=cursor)
    
    query = User.query().order(-ndb.GenericProperty('total'))
    models, next_cursor, more = query.fetch_page(limit, start_cursor=cursor)

    return render_to_response(template_name, 
                             {'next':next_cursor, 'more':more, 
                              'users':models},
                             context_instance=RequestContext(request)) 
Exemplo n.º 8
0
def fix_players(cursor=None):
    """Fix all the players"""
    
    if cursor:
        cursor = Cursor(urlsafe=cursor)
        
    query = User.query()
    models, next_cursor, more = query.fetch_page(15, start_cursor=cursor)
    
    for model in models:
        deferred.defer(fix_player_counts, 'own:%s' % model.username)
        
    if more:
        deferred.defer(fix_players, cursor=next_cursor.urlsafe())
Exemplo n.º 9
0
def fix_players(cursor=None):
    """Fix all the players"""

    if cursor:
        cursor = Cursor(urlsafe=cursor)

    query = User.query()
    models, next_cursor, more = query.fetch_page(15, start_cursor=cursor)

    for model in models:
        deferred.defer(fix_player_counts, 'own:%s' % model.username)

    if more:
        deferred.defer(fix_players, cursor=next_cursor.urlsafe())
Exemplo n.º 10
0
def users_by_location(request, location_slug, 
                      template_name='people/people_list.html'):

    limit = 100
    cursor = request.GET.get('cursor')
    if cursor:
        cursor = Cursor(urlsafe=cursor)

    query = User.query(User.location_slug == location_slug)
    query = query.order(-ndb.GenericProperty('total'))
        
    models, next_cursor, more = query.fetch_page(limit, start_cursor=cursor)

    location = Location.get_by_id(location_slug)
    return render_to_response(template_name, 
                             {'next':next_cursor, 'more':more, 
                              'users':models,
                              'location': location, 'slug': location_slug}, 
                             context_instance=RequestContext(request)) 
Exemplo n.º 11
0
def team_details(request, team_slug, template_name='people/team_details.html'):
    limit = 100
    cursor = request.GET.get('cursor')
    if cursor:
        cursor = Cursor(urlsafe=cursor)

    query = User.query(ndb.GenericProperty('team_slug') == team_slug)
    query = query.order(-ndb.GenericProperty('total'))

    models, next_cursor, more = query.fetch_page(limit, start_cursor=cursor)
    
    if next_cursor is not None:
        next_cursor = next_cursor.urlsafe()
    
    team = Team.get_by_id(team_slug)
    return render_to_response(template_name, 
                             {'next':next_cursor, 'more':more, 
                              'users':models,
                              'team': team, 'slug': team_slug}, 
                             context_instance=RequestContext(request))
Exemplo n.º 12
0
def fix_accounts(cursor=None):
    """Fix all the accounts in chunks"""
    
    if cursor:
        cursor = Cursor(urlsafe=cursor)
        
    query = User.query()
    models, next_cursor, more = query.fetch_page(15, start_cursor=cursor)
    
    for account in models:
        username = getattr(account, 'username', None)
        if username is None:
            logging.error('No user name set for: %s', account)
            continue
        
        added, _ = account.add_auth_id('own:%s' % username)
        if not added:
            logging.error("Unable to add username: %s", account.username)
            
    if more:
        deferred.defer(fix_accounts, cursor=next_cursor.urlsafe())
Exemplo n.º 13
0
def fix_accounts(cursor=None):
    """Fix all the accounts in chunks"""

    if cursor:
        cursor = Cursor(urlsafe=cursor)

    query = User.query()
    models, next_cursor, more = query.fetch_page(15, start_cursor=cursor)

    for account in models:
        username = getattr(account, 'username', None)
        if username is None:
            logging.error('No user name set for: %s', account)
            continue

        added, _ = account.add_auth_id('own:%s' % username)
        if not added:
            logging.error("Unable to add username: %s", account.username)

    if more:
        deferred.defer(fix_accounts, cursor=next_cursor.urlsafe())
Exemplo n.º 14
0
def index(request):
    """Render the home page"""

    # For now we are just using hard coded sections
    #sections = cache.get('front_page')
    #if sections is None:
    #    sections = Section.all().order('order').fetch(10)
    #    cache.set('front_page', sections, 120)

    stats = []
    total = 0
    people = []
    locations = []
    projects = []
    teams = []
    messages = []
    token = ''

    # this is only shown on authenticated page loads
    # to save on the overhead.
    if True:
        stats = Accumulator.get_histogram('global')
        total = sum(stats)
        location_future = Location.query().order(-Location.total).fetch_async(
            15)
        people_future = User.query().order(
            -ndb.GenericProperty('total')).fetch_async(10)
        project_future = Project.query().order(-Project.total).fetch_async(10)
        team_future = Team.query().order(-Team.total).fetch_async(15)
        message_future = Message.query().order(-Message.timestamp).fetch_async(
            30)

        # Julython live stuffs
        #token_key = 'live_token:%s' % request.user.username
        #token = memcache.get(token_key)
        #if token is None:
        #token = channel.create_channel(request.user.username)
        #memcache.set(token_key, token, time=7000)

        locations = location_future.get_result()
        people = people_future.get_result()
        projects = project_future.get_result()
        teams = team_future.get_result()
        message_models = message_future.get_result()

        m_list = [to_dict(m) for m in message_models]
        m_list.reverse()
        messages = json.dumps(m_list)

    ctx = Context({
        'sections': [],
        'people': people,
        'projects': projects,
        'locations': locations,
        'teams': teams,
        'stats': json.dumps(stats),
        'total': total,
        'token': token,
        'messages': messages,
        'user': request.user,
        'MEDIA_URL': settings.MEDIA_URL,
        'STATIC_URL': settings.STATIC_URL
    })

    return render_to_response('index.html', context_instance=ctx)
Exemplo n.º 15
0
def index(request):
    """Render the home page"""
    
    # For now we are just using hard coded sections
    #sections = cache.get('front_page')
    #if sections is None:
    #    sections = Section.all().order('order').fetch(10)
    #    cache.set('front_page', sections, 120)
    
    stats = []
    total = 0
    people = []
    locations = []
    projects = []
    teams = []
    messages = []
    token = ''
    
    # this is only shown on authenticated page loads
    # to save on the overhead. 
    if True:
        stats = Accumulator.get_histogram('global')
        total = sum(stats)
        location_future = Location.query().order(-Location.total).fetch_async(15)
        people_future = User.query().order(-ndb.GenericProperty('total')).fetch_async(10)
        project_future = Project.query().order(-Project.total).fetch_async(10)
        team_future = Team.query().order(-Team.total).fetch_async(15)
        message_future = Message.query().order(-Message.timestamp).fetch_async(30)
        
        # Julython live stuffs
        #token_key = 'live_token:%s' % request.user.username
        #token = memcache.get(token_key)
        #if token is None:
            #token = channel.create_channel(request.user.username)
            #memcache.set(token_key, token, time=7000)

        
        locations = location_future.get_result()
        people = people_future.get_result()
        projects = project_future.get_result()
        teams = team_future.get_result()
        message_models = message_future.get_result()
        
        m_list = [to_dict(m) for m in message_models]
        m_list.reverse()
        messages = json.dumps(m_list)
    
    ctx = Context({
        'sections': [],
        'people': people,
        'projects': projects,
        'locations': locations,
        'teams': teams,
        'stats': json.dumps(stats),
        'total': total,
        'token': token,
        'messages': messages,
        'user': request.user,
        'MEDIA_URL': settings.MEDIA_URL,
        'STATIC_URL': settings.STATIC_URL})
    
    return render_to_response('index.html', context_instance=ctx)