def make_player(player): if player is None: pl = Player('BYE', 'T', -10000, 0, 0, 0) pl.dbpl = None return pl try: rating = player.current_rating pl = Player( player.tag, player.race, rating.rating, rating.rating_vp, rating.rating_vt, rating.rating_vz, rating.dev, rating.dev_vp, rating.dev_vt, rating.dev_vz, ) except: pl = Player( player.tag, player.race, start_rating(player.country, etn(lambda: get_latest_period().id) or 1), 0.0, 0.0, 0.0, INIT_DEV, INIT_DEV, INIT_DEV, INIT_DEV, ) pl.dbpl = player return pl
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
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
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