Ejemplo n.º 1
0
def search(request):
    base = base_ctx(request=request)

    query = get_param(request, 'q', '')
    results = tools_search(query)
    if results is None:
        return redirect('/')

    players, teams, events = results

    # {{{ Redirect if only one hit
    if   players.count() == 1 and teams.count() == 0 and events.count() == 0:
        return redirect('/players/%i-%s/' % (players.first().id, urlfilter(players.first().tag)))
    elif players.count() == 0 and teams.count() == 1 and events.count() == 0:
        return redirect('/teams/%i-%s/' % (teams.first().id, urlfilter(teams.first().name)))
    elif players.count() == 0 and teams.count() == 0 and events.count() == 1:
        return redirect('/results/events/%i-%s/' % (events.first().id, urlfilter(events.first().fullname)))
    # }}}

    base.update({
        'players':  players,
        'teams':    teams,
        'events':   events,
        'query':    query,
    })

    base.update({'title': _('Search results')})

    return render_to_response('search.html', base)
Ejemplo n.º 2
0
def search(request):
    base = base_ctx(request=request)

    query = get_param(request, 'q', '')
    results = tools_search(query)
    if results is None:
        return redirect('/')

    players, teams, events = results

    # {{{ Redirect if only one hit
    if players.count() == 1 and teams.count() == 0 and events.count() == 0:
        return redirect('/players/%i-%s/' %
                        (players.first().id, urlfilter(players.first().tag)))
    elif players.count() == 0 and teams.count() == 1 and events.count() == 0:
        return redirect('/teams/%i-%s/' %
                        (teams.first().id, urlfilter(teams.first().name)))
    elif players.count() == 0 and teams.count() == 0 and events.count() == 1:
        return redirect(
            '/results/events/%i-%s/' %
            (events.first().id, urlfilter(events.first().fullname)))
    # }}}

    base.update({
        'results': zip_longest(players, teams, events, fillvalue=None),
        'players': players,
        'teams': teams,
        'events': events,
        'query': query,
    })

    return render_to_response('search.djhtml', base)
Ejemplo n.º 3
0
def search(request, q=""):
    base = base_ctx(request=request)

    if q == "":
        q = request.GET["q"]

    terms = shlex.split(q.encode())

    players = ratings.tools.find_player(terms, make=False, soft=True)

    teams = Group.objects.all()
    for qpart in terms:
        if qpart.strip() == "":
            continue
        query = Q(name__icontains=qpart) | Q(alias__name__icontains=qpart)
        teams = teams.filter(query)
    teams = teams.distinct()

    events = Event.objects.filter(type__in=["category", "event"])
    for qpart in terms:
        if qpart.strip() == "":
            continue
        events = events.filter(Q(fullname__icontains=qpart))
    events = events.order_by("lft")

    if players.count() == 1 and teams.count() == 0 and events.count() == 0:
        return redirect("/players/%i-%s/" % (players[0].id, urlfilter(players[0].tag)))
    elif players.count() == 0 and teams.count() == 1 and events.count() == 0:
        return redirect("/teams/%i-%s/" % (teams[0].id, urlfilter(teams[0].name)))
    elif players.count() == 0 and teams.count() == 0 and events.count() == 1:
        return redirect("/results/events/%i-%s/" % (events[0].id, urlfilter(events[0].fullname)))

    base.update({"players": players, "query": q, "teams": teams, "events": events})

    return render_to_response("search.html", base)
Ejemplo n.º 4
0
def search(request, q=''):
    base = base_ctx(request=request)

    if q == '':
        q = request.GET['q']

    players = find_player(q.split(' '), make=False, soft=True)

    teams = Team.objects.all()
    for qpart in q.split(' '):
        if qpart.strip() == '':
            continue
        query = Q(name__icontains=qpart) | Q(alias__name__icontains=q)
        teams = teams.filter(query)
    teams = teams.distinct()

    events = Event.objects.filter(type__in=['category','event'])
    for qpart in q.split(' '):
        if qpart.strip() == '':
            continue
        events = events.filter(Q(fullname__icontains=qpart))
    events = events.order_by('lft')

    if players.count() == 1 and teams.count() == 0 and events.count() == 0:
        return redirect('/players/%i-%s/' % (players[0].id, urlfilter(players[0].tag)))
    elif players.count() == 0 and teams.count() == 1 and events.count() == 0:
        return redirect('/teams/%i-%s/' % (teams[0].id, urlfilter(teams[0].name)))
    elif players.count() == 0 and teams.count() == 0 and events.count() == 1:
        return redirect('/results/events/%i-%s/' % (events[0].id, urlfilter(events[0].fullname)))

    base.update({'players': players, 'query': q, 'teams': teams, 'events': events})

    return render_to_response('search.html', base)
Ejemplo n.º 5
0
def search(request):
    base = base_ctx(request=request)

    query = get_param(request, "q", "")
    results = tools_search(query)
    if results is None:
        return redirect("/")

    players, teams, events = results

    # {{{ Redirect if only one hit
    if players.count() == 1 and teams.count() == 0 and events.count() == 0:
        return redirect("/players/%i-%s/" % (players.first().id, urlfilter(players.first().tag)))
    elif players.count() == 0 and teams.count() == 1 and events.count() == 0:
        return redirect("/teams/%i-%s/" % (teams.first().id, urlfilter(teams.first().name)))
    elif players.count() == 0 and teams.count() == 0 and events.count() == 1:
        return redirect("/results/events/%i-%s/" % (events.first().id, urlfilter(events.first().fullname)))
    # }}}

    base.update(
        {
            "results": zip_longest(players, teams, events, fillvalue=None),
            "players": players,
            "teams": teams,
            "events": events,
            "query": query,
        }
    )

    return render_to_response("search.djhtml", base)
Ejemplo n.º 6
0
def search(request):
    base = base_ctx(request=request)

    # {{{ Split query
    query = get_param(request, 'q', '')
    terms = [s.strip() for s in shlex.split(query) if s.strip() != '']
    if len(terms) == 0:
        return redirect('/')
    # }}}

    # {{{ Search for players, teams and events
    players = find_player(lst=terms, make=False, soft=True)

    teams = Group.objects.filter(is_team=True)
    events = Event.objects.filter(type__in=[TYPE_CATEGORY, TYPE_EVENT]).order_by('idx')
    for term in terms:
        teams = teams.filter(Q(name__icontains=term) | Q(alias__name__icontains=term))
        events = events.filter(Q(fullname__icontains=term))
    teams = teams.distinct()
    # }}}

    # {{{ Redirect if only one hit
    if   players.count() == 1 and teams.count() == 0 and events.count() == 0:
        return redirect('/players/%i-%s/' % (players.first().id, urlfilter(players.first().tag)))
    elif players.count() == 0 and teams.count() == 1 and events.count() == 0:
        return redirect('/teams/%i-%s/' % (teams.first().id, urlfilter(teams.first().name)))
    elif players.count() == 0 and teams.count() == 0 and events.count() == 1:
        return redirect('/results/events/%i-%s/' % (events.first().id, urlfilter(events.first().fullname)))
    # }}}

    base.update({
        'players':  players,
        'teams':    teams,
        'events':   events,
        'query':    query,
    })

    base.update({"title": "Search results"})

    return render_to_response('search.html', base)
Ejemplo n.º 7
0
def base_ctx(section=None, subpage=None, request=None, context=None):
    curp = Period.objects.filter(computed=True).order_by("-start")[0]
    menu = [
        ("Ranking", "/periods/%i" % curp.id),
        ("Teams", "/teams/"),
        ("Records", "/records/history"),
        ("Results", "/results/"),
        ("Reports", "/reports/"),
        ("Predict", "/predict/"),
        ("About", "/faq/"),
        ("Submit", "/add/"),
    ]

    base = {"curp": curp, "menu": menu, "debug": DEBUG, "cur_path": request.get_full_path()}
    base.update(csrf(request))

    if request != None:
        base["adm"] = request.user.is_authenticated()
        base["user"] = request.user.username

    if section == "Records":
        base["submenu"] = [
            ("History", "/records/history/"),
            ("HoF", "/records/hof/"),
            ("All", "/records/race/?race=all"),
            ("Protoss", "/records/race/?race=P"),
            ("Terran", "/records/race/?race=T"),
            ("Zerg", "/records/race/?race=Z"),
        ]
    elif section == "Results":
        base["submenu"] = [("By Date", "/results/"), ("By Event", "/results/events/"), ("Search", "/results/search/")]
    elif section == "Submit" and base["adm"]:
        base["submenu"] = [
            ("Matches", "/add/"),
            ("Review", "/add/review/"),
            ("Events", "/add/events/"),
            ("Open events", "/add/open_events/"),
            ("Integrity", "/add/integrity/"),
            ("Misc", "/add/misc/"),
        ]
    elif section == "Teams":
        base["submenu"] = [("Ranking", "/teams/"), ("Transfers", "/player_transfers/")]
    elif section == "Ranking":
        base["submenu"] = [("Current", "/periods/%i" % curp.id), ("History", "/periods/"), ("Earnings", "/earnings/")]
    elif section == "Predict":
        base["submenu"] = [
            ("Predict", "/predict/"),
            # ('Factoids', '/factoids/'),
            ("Compare", "/compare/"),
        ]
    elif section == "About":
        base["submenu"] = [
            ("FAQ", "/faq/"),
            ("Blog", "/blog/"),
            # ('Staff', '/staff/'),
            ("Database", "/db/"),
        ]
    elif section == "Reports":
        pass

    if section != None:
        base["curpage"] = section

    if subpage != None:
        base["cursubpage"] = subpage

    if context != None:
        if type(context) == Player:
            rating = Rating.objects.filter(player=context, decay=0).order_by("-period")
            earnings = Earnings.objects.filter(player=context)

            base_url = "/players/%i-%s/" % (context.id, urlfilter(context.tag))

            base["submenu"] += [None, ("%s:" % context.tag, base_url)]

            if rating.exists():
                base["submenu"].append(("Rating history", base_url + "historical/"))

            base["submenu"].append(("Match history", base_url + "results/"))

            if earnings.exists():
                base["submenu"].append(("Earnings", base_url + "earnings/"))

            if rating.exists():
                base["submenu"].append(("Adjustments", base_url + "period/%i/" % rating[0].period.id))

    base["messages"] = []

    return base
Ejemplo n.º 8
0
def base_ctx(section=None, subpage=None, request=None, context=None):
    curp = get_latest_period()

    base = {
        'curp':
        curp,
        'debug':
        DEBUG,
        'cur_path':
        request.get_full_path(),
        'messages': [],
        'lang':
        request.LANGUAGE_CODE,
        'menu': [
            {
                'id':
                'Ranking',
                'name':
                _('Ranking'),
                'url':
                '/periods/latest/',
                'submenu': [
                    ('Current', _('Current'), '/periods/latest/'),
                    ('History', _('History'), '/periods/'),
                    ('Earnings', _('Earnings'), '/earnings/'),
                ]
            },
            {
                'id':
                'Teams',
                'name':
                _('Teams'),
                'url':
                '/teams/',
                'submenu': [
                    ('Ranking', _('Ranking'), '/teams/'),
                    ('Transfers', _('Transfers'), '/transfers/'),
                ]
            },
            {
                'id':
                'Records',
                'name':
                _('Records'),
                'url':
                '/records/history/',
                'submenu': [
                    ('History', _('History'), '/records/history/'),
                    # Translators: Hall of fame
                    ('HoF', _('HoF'), '/records/hof/'),
                    ('All', _('All'), '/records/race/?race=all'),
                    ('Protoss', _('Protoss'), '/records/race/?race=P'),
                    ('Terran', _('Terran'), '/records/race/?race=T'),
                    ('Zerg', _('Zerg'), '/records/race/?race=Z'),
                ]
            },
            {
                'id':
                'Results',
                'name':
                _('Results'),
                'url':
                '/results/',
                'submenu': [
                    ('By Date', _('By Date'), '/results/'),
                    ('By Event', _('By Event'), '/results/events/'),
                    ('Search', _('Search'), '/results/search/'),
                ]
            },
            {
                'id': 'Inference',
                'name': _('Inference'),
                'url': '/inference/',
                'submenu': [
                    ('Predict', _('Predict'), '/inference/'),
                ]
            },
            {
                'id':
                'Misc',
                'name':
                _('Misc'),
                'url':
                '/misc/',
                'submenu':
                [('Balance Report', _('Balance Report'), '/misc/balance/'),
                 ('Days Since…', _('Days Since…'), '/misc/days/'),
                 ('Compare', _('Compare'), '/misc/compare/')]
            },
            {
                'id':
                'About',
                'name':
                _('About'),
                'url':
                '/about/faq/',
                'submenu': [
                    ('FAQ', _('FAQ'), '/about/faq/'),
                    ('Blog', _('Blog'), '/about/blog/'),
                    ('Database', _('Database'), '/about/db/'),
                    ('API', _('API'), '/about/api/'),
                ]
            },
            {
                'id':
                'Submit',
                'name':
                _('Submit'),
                'url':
                '/add/',
                'submenu': [
                    # Translators: Matches as in SC2-matches, not search matches.
                    ('Matches', _('Matches'), '/add/'),
                    ('Review', _('Review'), '/add/review/'),
                    ('Events', _('Events'), '/add/events/'),
                    ('Open events', _('Open events'), '/add/open_events/'),
                    ('Player info', _('Player info'), '/add/player_info/'),
                    ('Misc', _('Misc'), '/add/misc/'),
                ]
            }
        ]
    }
    base.update({"subnav": None})

    def add_subnav(title, url):
        if base["subnav"] is None:
            base["subnav"] = []
        base["subnav"].append((title, url))

    base.update(csrf(request))

    # Log in if possible
    if request.method == 'POST' and 'username' in request.POST and 'password' in request.POST:
        user = authenticate(username=request.POST['username'],
                            password=request.POST['password'])
        if user != None and user.is_active:
            login(request, user)

    # Check for admin rights (must belong to match uploader group, but this is the only group that exists)
    if request != None:
        base[
            'adm'] = request.user.is_authenticated and request.user.groups.exists(
            )
        base['user'] = request.user.username
    else:
        base['adm'] = False

    if not base['adm']:
        base['menu'][-1]['submenu'] = base['menu'][-1]['submenu'][:1]

    if section is not None:
        base['curpage'] = section

    if subpage is not None:
        base['cursubpage'] = subpage

    if context is not None:
        if isinstance(context, Player):
            rating = context.get_latest_rating_update()
            earnings = context.has_earnings()

            base_url = '/players/%i-%s/' % (context.id, urlfilter(context.tag))
            add_subnav(_('Summary'), base_url)

            if rating is not None:
                add_subnav(_('Rating history'), base_url + 'historical/')

            add_subnav(_('Match history'), base_url + 'results/')

            if context.has_earnings():
                add_subnav(_('Earnings'), base_url + 'earnings/')

            if rating is not None:
                add_subnav(_('Adjustments'),
                           base_url + 'period/%i/' % rating.period.id)

    if DEBUG:
        p = subprocess.Popen(['git', '-C', PROJECT_PATH, 'rev-parse', 'HEAD'],
                             stdout=subprocess.PIPE)
        base['commithash'] = p.communicate()[0].decode().strip()[:8]

        p = subprocess.Popen(
            ['git', '-C', PROJECT_PATH, 'rev-parse', '--abbrev-ref', 'HEAD'],
            stdout=subprocess.PIPE)
        base['commitbranch'] = p.communicate()[0].decode().strip()

    return base
Ejemplo n.º 9
0
def base_ctx(section=None, subpage=None, request=None, context=None):
    curp = get_latest_period()

    menu = [
        ('Ranking',    '/periods/latest/'),
        ('Teams',      '/teams/'),
        ('Records',    '/records/history'),
        ('Results',    '/results/'),
        ('Reports',    '/reports/'),
        ('Inference',  '/inference/'),
        ('About',      '/faq/'),
        ('Submit',     '/add/'),
    ]

    base = {
        'curp':      curp,
        'menu':      menu,
        'debug':     DEBUG,
        'cur_path':  request.get_full_path(),
        'messages':  [],
        'menu':      [{
            'name': 'Ranking',
            'url': '/periods/latest/',
            'submenu': [
                ('Current',  '/periods/latest/'),
                ('History',  '/periods/'),
                ('Earnings', '/earnings/'),
        ]}, {
            'name': 'Teams',
            'url': '/teams/',
            'submenu': [
                ('Ranking', '/teams/'),
                ('Transfers', '/transfers/'),
        ]}, {
            'name': 'Records',
            'url': '/records/history/',
            'submenu': [
                ('History', '/records/history/'),
                ('HoF', '/records/hof/'),
                ('All', '/records/race/?race=all'),
                ('Protoss', '/records/race/?race=P'),
                ('Terran', '/records/race/?race=T'),
                ('Zerg', '/records/race/?race=Z'),
        ]}, {
            'name': 'Results',
            'url': '/results/',
            'submenu': [
                ('By Date', '/results/'),
                ('By Event', '/results/events/'),
                ('Search', '/results/search/'),
        ]}, {
            'name': 'Reports',
            'url': '/reports/',
            'submenu': [
                ('Balance', '/reports/balance/'),
        ]}, {
            'name': 'Inference',
            'url': '/inference/',
            'submenu': [
                ('Predict', '/inference/'),
        ]}, {
            'name': 'About',
            'url': '/about/faq/',
            'submenu': [
                ('FAQ', '/about/faq/'),
                ('Blog', '/about/blog/'),
                ('Database', '/about/db/'),
                ('API', '/about/api/'),
        ]}, {
            'name': 'Submit',
            'url': '/add/',
            'submenu': [
                ('Matches', '/add/'),
                ('Review', '/add/review/'),
                ('Events', '/add/events/'),
                ('Open events', '/add/open_events/'),
                ('Misc', '/add/misc/'),
        ]}]
    }
    base.update({"subnav": None})
    def add_subnav(title, url):
        if base["subnav"] is None:
            base["subnav"] = []
        base["subnav"].append((title, url))
    base.update(csrf(request))

    # Log in if possible
    if request.method == 'POST' and 'username' in request.POST and 'password' in request.POST:
        user = authenticate(username=request.POST['username'], password=request.POST['password'])
        if user != None and user.is_active:
            login(request, user)

    # Check for admin rights (must belong to match uploader group, but this is the only group that exists)
    if request != None:
        base['adm'] = request.user.is_authenticated() and request.user.groups.exists()
        base['user'] = request.user.username
    else:
        base['adm'] = False

    if not base['adm']:
        base['menu'][-1]['submenu'] = base['menu'][-1]['submenu'][:1]

    if section is not None:
        base['curpage'] = section

    if subpage is not None:
        base['cursubpage'] = subpage

    if context is not None:
        if isinstance(context, Player):
            rating = context.get_latest_rating_update()
            earnings = context.has_earnings()

            base_url = '/players/%i-%s/' % (context.id, urlfilter(context.tag))
            add_subnav('Summary', base_url)

            if rating is not None:
                add_subnav('Rating history', base_url + 'historical/')

            add_subnav('Match history', base_url + 'results/')

            if context.has_earnings():
                add_subnav('Earnings', base_url + 'earnings/')

            if rating is not None:
                add_subnav('Adjustments', base_url + 'period/%i/' % rating.period.id)

    return base
Ejemplo n.º 10
0
def base_ctx(section=None, subpage=None, request=None, context=None):
    curp = Period.objects.filter(computed=True).order_by('-start')[0]
    menu = [('Ranking', '/periods/%i' % curp.id),\
            ('Teams', '/teams/'),\
            ('Records', '/records/'),\
            ('Results', '/results/'),\
            ('Reports', '/reports/'),\
            ('Predict', '/predict/'),\
            ('About', '/faq/'),\
            ('Submit', '/add/')]

    base = {'curp': curp, 'menu': menu, 'debug': DEBUG}

    if request != None:
        base['adm'] = request.user.is_authenticated()

    if section == 'Records':
        base['submenu'] = [('HoF', '/records/?race=hof'),\
                           ('All', '/records/?race=all'),\
                           ('Protoss', '/records/?race=P'),\
                           ('Terran', '/records/?race=T'),\
                           ('Zerg', '/records/?race=Z')]
    elif section == 'Results':
        base['submenu'] = [('By Date', '/results/'),\
                           ('By Event', '/results/events/'),\
                           ('Search', '/results/search/')]
    elif section == 'Submit' and base['adm']:
        base['submenu'] = [('Matches', '/add/'),\
                           ('Review', '/add/review/'),\
                           ('Events', '/add/events/'),\
                           ('Integrity', '/add/integrity/'),\
                           ('Misc', '/add/misc/')]
    elif section == 'Teams':
        base['submenu'] = [('Ranking', '/teams/'),\
                           ('Transfers', '/player_transfers/')]
    elif section == 'Ranking':
        base['submenu'] = [('Current', '/periods/%i' % curp.id),\
                           ('History', '/periods/'),\
                           ('Earnings', '/earnings/')]
    elif section == 'About':
        base['submenu'] = [('FAQ', '/faq/'),
                           ('Blog', '/blog/'),
                           ('Database', '/db/')]
    elif section == 'Reports':
        pass

    if section != None:
        base['curpage'] = section

    if subpage != None:
        base['cursubpage'] = subpage

    if context != None:
        if type(context) == Player:
            rating = Rating.objects.filter(player=context, comp_rat__isnull=False).order_by('-period')
            earnings = Earnings.objects.filter(player=context)

            base_url = '/players/%i-%s/' % (context.id, urlfilter(context.tag))

            base['submenu'] += [None, ('%s:' % context.tag, base_url)]

            if rating.exists():
                base['submenu'].append(('Rating history', base_url + 'historical/'))

            base['submenu'].append(('Match history', base_url + 'results/'))
            
            if earnings.exists():
                base['submenu'].append(('Earnings', base_url + 'earnings/'))

            if rating.exists():
                base['submenu'].append(('Adjustments', base_url + 'period/%i' % rating[0].period.id))

    return base
Ejemplo n.º 11
0
def base_ctx(section=None, subpage=None, request=None, context=None):
    curp = get_latest_period()

    base = {
        'curp':      curp,
        'debug':     DEBUG,
        'cur_path':  request.get_full_path(),
        'messages':  [],
        'lang':      request.LANGUAGE_CODE,
        'menu':      [{
            'id': 'Ranking',
            'name': _('Ranking'),
            'url': '/periods/latest/',
            'submenu': [
                ('Current', _('Current'),  '/periods/latest/'),
                ('History', _('History'),  '/periods/'),
                ('Earnings', _('Earnings'), '/earnings/'),
        ]}, {
            'id': 'Teams',
            'name': _('Teams'),
            'url': '/teams/',
            'submenu': [
                ('Ranking', _('Ranking'), '/teams/'),
                ('Transfers', _('Transfers'), '/transfers/'),
        ]}, {
            'id': 'Records',
            'name': _('Records'),
            'url': '/records/history/',
            'submenu': [
                ('History', _('History'), '/records/history/'),
                # Translators: Hall of fame
                ('HoF', _('HoF'), '/records/hof/'),
                ('All', _('All'), '/records/race/?race=all'),
                ('Protoss', _('Protoss'), '/records/race/?race=P'),
                ('Terran', _('Terran'), '/records/race/?race=T'),
                ('Zerg', _('Zerg'), '/records/race/?race=Z'),
        ]}, {
            'id': 'Results',
            'name': _('Results'),
            'url': '/results/',
            'submenu': [
                ('By Date', _('By Date'), '/results/'),
                ('By Event', _('By Event'), '/results/events/'),
                ('Search', _('Search'), '/results/search/'),
        ]}, {
            'id': 'Inference',
            'name': _('Inference'),
            'url': '/inference/',
            'submenu': [
                ('Predict', _('Predict'), '/inference/'),
        ]}, {
            'id': 'Misc',
            'name': _('Misc'),
            'url': '/misc/',
            'submenu': [
                ('Balance Report', _('Balance Report'), '/misc/balance/'),
                ('Days Since…', _('Days Since…'), '/misc/days/'),
                ('Compare', _('Compare'), '/misc/compare/')
        ]}, {
            'id': 'About',
            'name': _('About'),
            'url': '/about/faq/',
            'submenu': [
                ('FAQ', _('FAQ'), '/about/faq/'),
                ('Blog', _('Blog'), '/about/blog/'),
                ('Database', _('Database'), '/about/db/'),
                ('API', _('API'), '/about/api/'),
        ]}, {
            'id': 'Submit',
            'name': _('Submit'),
            'url': '/add/',
            'submenu': [
                # Translators: Matches as in SC2-matches, not search matches.
                ('Matches', _('Matches'), '/add/'),
                ('Review', _('Review'), '/add/review/'),
                ('Events', _('Events'), '/add/events/'),
                ('Open events', _('Open events'), '/add/open_events/'),
                ('Player info', _('Player info'), '/add/player_info/'),
                ('Misc', _('Misc'), '/add/misc/'),
        ]}]
    }
    base.update({"subnav": None})
    def add_subnav(title, url):
        if base["subnav"] is None:
            base["subnav"] = []
        base["subnav"].append((title, url))
    base.update(csrf(request))

    # Log in if possible
    if request.method == 'POST' and 'username' in request.POST and 'password' in request.POST:
        user = authenticate(username=request.POST['username'], password=request.POST['password'])
        if user != None and user.is_active:
            login(request, user)

    # Check for admin rights (must belong to match uploader group, but this is the only group that exists)
    if request != None:
        base['adm'] = request.user.is_authenticated() and request.user.groups.exists()
        base['user'] = request.user.username
    else:
        base['adm'] = False

    if not base['adm']:
        base['menu'][-1]['submenu'] = base['menu'][-1]['submenu'][:1]

    if section is not None:
        base['curpage'] = section

    if subpage is not None:
        base['cursubpage'] = subpage

    if context is not None:
        if isinstance(context, Player):
            rating = context.get_latest_rating_update()
            earnings = context.has_earnings()

            base_url = '/players/%i-%s/' % (context.id, urlfilter(context.tag))
            add_subnav(_('Summary'), base_url)

            if rating is not None:
                add_subnav(_('Rating history'), base_url + 'historical/')

            add_subnav(_('Match history'), base_url + 'results/')

            if context.has_earnings():
                add_subnav(_('Earnings'), base_url + 'earnings/')

            if rating is not None:
                add_subnav(_('Adjustments'), base_url + 'period/%i/' % rating.period.id)


    if DEBUG:
        p = subprocess.Popen(['git', '-C', PROJECT_PATH, 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
        base['commithash'] = p.communicate()[0].decode().strip()[:8]

        p = subprocess.Popen(['git', '-C', PROJECT_PATH, 'rev-parse', '--abbrev-ref', 'HEAD'],
                             stdout=subprocess.PIPE)
        base['commitbranch'] = p.communicate()[0].decode().strip()

    return base