def add_matches(request): base = base_ctx('Submit', 'Matches', request) login_message(base) if request.method == 'POST' and 'submit' in request.POST: form = AddMatchesForm(base['adm'], request=request) base['matches'] = display_matches(form.parse_matches(request.user), messages=False) base['messages'] += form.messages else: form = AddMatchesForm(base['adm']) try: get_event = Event.objects.get(id=request.GET['eventid']) if get_event.closed: get_event.open() base['messages'].append(Message(_("Reopened '%s'.") % get_event.fullname, type=Message.SUCCESS)) form['eventobj'].field.choices.append((get_event.id, get_event.fullname)) form['eventobj'].field.choices.sort(key=lambda e: e[1]) base['event_override'] = get_event.id except: pass base['form'] = form base.update({"title": _("Submit results")}) return render_to_response('add.html', base)
def changepwd(request): if not request.user.is_authenticated(): return redirect("/login/") base = base_ctx(request=request) login_message(base) if not ("old" in request.POST and "new" in request.POST and "newre" in request.POST): return render_to_response("changepwd.djhtml", base) if not request.user.check_password(request.POST["old"]): base["messages"].append( Message(_("The old password didn't match. Your password was not changed."), type=Message.ERROR) ) return render_to_response("changepwd.djhtml", base) if request.POST["new"] != request.POST["newre"]: base["messages"].append( Message(_("The new passwords didn't match. Your password was not changed."), type=Message.ERROR) ) return render_to_response("changepwd.djhtml", base) request.user.set_password(request.POST["new"]) request.user.save() base["messages"].append( Message(_("The password for %s was successfully changed.") % request.user.username, type=Message.SUCCESS) ) return render_to_response("changepwd.djhtml", base)
def misc(request): base = base_ctx('Submit', 'Misc', request) if not base['adm']: return redirect('/login/') login_message(base) mergeform = ( MergePlayersForm(request=request) if request.method == 'POST' and 'merge' in request.POST else MergePlayersForm() ) moveform = ( MoveEventForm(request=request) if request.method == 'POST' and 'move' in request.POST else MoveEventForm() ) if mergeform.is_bound: base['messages'] += mergeform.merge() if moveform.is_bound: base['messages'] += moveform.move() base.update({ 'mergeform': mergeform, 'moveform': moveform, }) return render_to_response('manage.html', base)
def review_matches(request): base = base_ctx('Submit', 'Review', request) if not base['adm']: return redirect('/login/') login_message(base) if request.method == 'POST': form = ReviewMatchesForm(request=request, submitter=request.user) base['messages'] += form.messages else: form = ReviewMatchesForm() base['form'] = form base['groups'] = ( PreMatchGroup.objects.filter(prematch__isnull=False) .prefetch_related('prematch_set') .order_by('id', 'event') .distinct() ) for g in base['groups']: g.prematches = display_matches(g.prematch_set.all(), messages=False, no_events=True) return render_to_response('review.djhtml', base)
def changepwd(request): if not request.user.is_authenticated(): return redirect('/login/') base = base_ctx(request=request) login_message(base) if not ('old' in request.POST and 'new' in request.POST and 'newre' in request.POST): return render_to_response('changepwd.djhtml', base) if not request.user.check_password(request.POST['old']): base['messages'].append( Message(_( "The old password didn't match. Your password was not changed." ), type=Message.ERROR)) return render_to_response('changepwd.djhtml', base) if request.POST['new'] != request.POST['newre']: base['messages'].append( Message(_( "The new passwords didn't match. Your password was not changed." ), type=Message.ERROR)) return render_to_response('changepwd.djhtml', base) request.user.set_password(request.POST['new']) request.user.save() base['messages'].append( Message(_('The password for %s was successfully changed.') % request.user.username, type=Message.SUCCESS)) return render_to_response('changepwd.djhtml', base)
def misc(request): base = base_ctx('Submit', 'Misc', request) if not base['adm']: return redirect('/login/') login_message(base) mergeform = ( MergePlayersForm(request=request) if request.method == 'POST' and 'merge' in request.POST else MergePlayersForm() ) moveform = ( MoveEventForm(request=request) if request.method == 'POST' and 'move' in request.POST else MoveEventForm() ) if mergeform.is_bound: base['messages'] += mergeform.merge() if moveform.is_bound: base['messages'] += moveform.move() base.update({ 'mergeform': mergeform, 'moveform': moveform, }) return render_to_response('manage.djhtml', base)
def add_matches(request): base = base_ctx('Submit', 'Matches', request) login_message(base) if request.method == 'POST' and 'submit' in request.POST: form = AddMatchesForm(base['adm'], request=request) base['matches'] = display_matches(form.parse_matches(request.user), messages=False) base['messages'] += form.messages else: form = AddMatchesForm(base['adm']) try: get_event = Event.objects.get(id=request.GET['eventid']) if get_event.closed: get_event.open() base['messages'].append( Message(_("Reopened '%s'.") % get_event.fullname, type=Message.SUCCESS)) form['eventobj'].field.choices.append( (get_event.id, get_event.fullname)) form['eventobj'].field.choices.sort(key=lambda e: e[1]) base['event_override'] = get_event.id except: pass base['form'] = form return render_to_response('add.djhtml', base)
def changepwd(request): if not request.user.is_authenticated(): return redirect('/login/') base = base_ctx(request=request) login_message(base) if not ('old' in request.POST and 'new' in request.POST and 'newre' in request.POST): return render_to_response('changepwd.html', base) if not request.user.check_password(request.POST['old']): base['messages'].append( Message("The old password didn't match. Your password was not changed.", type=Message.ERROR) ) return render_to_response('changepwd.html', base) if request.POST['new'] != request.POST['newre']: base['messages'].append( Message("The new passwords didn't match. Your password was not changed.", type=Message.ERROR) ) return render_to_response('changepwd.html', base) request.user.set_password(request.POST['new']) request.user.save() base['messages'].append( Message('The password for %s was successfully changed.' % request.user.username, type=Message.SUCCESS) ) base.update({"title": "Change password"}) return render_to_response('changepwd.html', base)
def events(request): base = base_ctx('Submit', 'Events', request) if not base['adm']: return redirect('/login/') login_message(base) if request.method == 'POST': form = AddEventsForm(request=request) base['messages'] += form.commit() else: form = AddEventsForm() base['form'] = form # Build event list events = ( Event.objects.filter(closed=False) .annotate(Max('uplink__distance')) .filter(uplink__distance__max=0) .filter(downlink__child__closed=False) .annotate(Max('downlink__distance')) .order_by('idx') ) #for e in events: #e.has_subtree = e.get_immediate_children().filter(closed=False).exists() base['nodes'] = events base.update({"title": _("Manage events")}) return render_to_response('eventmgr.html', base)
def review_matches(request): base = base_ctx('Submit', 'Review', request) if not base['adm']: return redirect('/login/') login_message(base) if request.method == 'POST': form = ReviewMatchesForm(request=request, submitter=request.user) base['messages'] += form.messages else: form = ReviewMatchesForm() base['form'] = form base['groups'] = ( PreMatchGroup.objects.filter(prematch__isnull=False) .prefetch_related('prematch_set') .order_by('id', 'event') .distinct() ) for g in base['groups']: g.prematches = display_matches(g.prematch_set.all(), messages=False) base.update({"title": _("Review results")}) return render_to_response('review.html', base)
def events(request): base = base_ctx('Submit', 'Events', request) if not base['adm']: return redirect('/login/') login_message(base) base['messages'].append( Message(_( "If you haven't used this tool before, ask before you do anything." ), type=Message.WARNING)) if request.method == 'POST': form = AddEventsForm(request=request) base['messages'] += form.commit() else: form = AddEventsForm() base['form'] = form # Build event list root_events = (Event.objects.filter(downlink__child__closed=False).filter( parent__isnull=True).order_by('idx').distinct()) subtreemap = {e.id: [] for e in root_events} tree = [{ 'event': e, 'subtree': subtreemap[e.id], 'inc': 0, } for e in root_events] events = root_events while events: events = (Event.objects.filter(downlink__child__closed=False).filter( parent__in=events).order_by('idx').distinct()) for e in events: subtreemap[e.id] = [] subtreemap[e.parent_id].append({ 'event': e, 'subtree': subtreemap[e.id], 'inc': 0, }) base['tree'] = [] def do_level(level, indent): for e in level: e['indent'] = indent base['tree'].append(e) if e['subtree']: base['tree'][-1]['inc'] += 1 do_level(e['subtree'], indent + 1) base['tree'][-1]['inc'] -= 1 do_level(tree, 0) return render_to_response('eventmgr.djhtml', base)
def open_events(request): base = base_ctx('Submit', 'Open events', request) if not base['adm']: return redirect('/login/') login_message(base) # {{{ Handle modifications if base['adm'] and 'open_games' in request.POST: ids = [int(i) for i in request.POST.getlist('open_games_ids')] for id in ids: Event.objects.get(id=id).close() base['messages'].append(Message('Successfully closed %i events.' % len(ids), type=Message.SUCCESS)) elif base['adm'] and 'pp_events' in request.POST: ids = [int(i) for i in request.POST.getlist('pp_events_ids')] nevents = Event.objects.filter(id__in=ids).update(prizepool=False) base['messages'].append(Message( 'Successfully marked %i events as having no prize pool.' % nevents, type=Message.SUCCESS)) # }}} # {{{ Open events with games base['open_games'] = ( Event.objects.filter(type=TYPE_EVENT, closed=False) .filter(downlink__child__match__isnull=False) .distinct() .prefetch_related('uplink__parent') .order_by('latest', 'idx', 'fullname') ) # }}} # {{{ Open events without games base['open_nogames'] = ( Event.objects.filter(type=TYPE_EVENT, closed=False) .exclude(downlink__child__match__isnull=False) .exclude(id=2) .distinct() .prefetch_related('uplink__parent') .order_by('fullname') ) # }}} # {{{ Closed non-team events with unknown prizepool status. base['pp_events'] = ( Event.objects.filter(type=TYPE_EVENT, prizepool__isnull=True) .filter(match__isnull=False, closed=True) .exclude(uplink__parent__category=CAT_TEAM) .distinct() .prefetch_related('uplink__parent') .order_by('idx', 'fullname') ) # }}} fill_aux_event(base['open_games']) fill_aux_event(base['open_nogames']) fill_aux_event(base['pp_events']) base.update({"title": "Open events"}) return render_to_response('events_open.html', base)
def open_events(request): base = base_ctx('Submit', 'Open events', request) if not base['adm']: return redirect('/login/') login_message(base) # Handle modifications if base['adm'] and 'open_games' in request.POST: ids = [int(i) for i in request.POST.getlist('open_games_ids')] for id in ids: Event.objects.get(id=id).close() base['messages'].append( Message( ungettext_lazy('Successfully closed %i event.', 'Successfully closed %i events.', len(ids)) % len(ids), type=Message.SUCCESS)) elif base['adm'] and 'pp_events' in request.POST: ids = [int(i) for i in request.POST.getlist('pp_events_ids')] nevents = Event.objects.filter(id__in=ids).update(prizepool=False) base['messages'].append( Message(ungettext_lazy( 'Successfully marked %i event as having no prize pool.', 'Successfully marked %i events as having no prize pool.', nevents) % nevents, type=Message.SUCCESS)) # Open events with games base['open_games'] = (Event.objects.filter( type=TYPE_EVENT, closed=False).filter( downlink__child__match__isnull=False).distinct().prefetch_related( 'uplink__parent').order_by('latest', 'idx', 'fullname')) # Open events without games base['open_nogames'] = (Event.objects.filter( type=TYPE_EVENT, closed=False).exclude(id__in=Event.objects.filter( downlink__child__match__isnull=False).distinct()).distinct( ).exclude( id=2).prefetch_related('uplink__parent').order_by('fullname')) # Closed non-team events with unknown prizepool status. base['pp_events'] = (Event.objects.filter( type=TYPE_EVENT, prizepool__isnull=True).filter( match__isnull=False, closed=True).exclude( uplink__parent__category=CAT_TEAM).distinct().prefetch_related( 'uplink__parent').order_by('idx', 'fullname')) fill_aux_event(base['open_games']) fill_aux_event(base['open_nogames']) fill_aux_event(base['pp_events']) return render_to_response('events_open.djhtml', base)
def login_view(request): base = base_ctx(request=request) login_message(base) return render_to_response('login.djhtml', base)
def player_info(request, choice=None): base = base_ctx('Submit', 'Player Info', request) if not base['adm']: return redirect('/login/') login_message(base) if request.method == 'POST': form = PlayerInfoForm(request.POST) if form.is_valid(): player = form.commit() base['messages'].append( Message( # Translators: Updated a player text=_("Updated %s") % player_filter(player), type=Message.SUCCESS ) ) page = 1 if 'page' in request.GET: try: page = int(request.GET['page']) except: pass country = 'all' if 'country' not in request.GET else request.GET['country'] base['country'] = country base['countries'] = country_list(Player.objects.all()) if country == 'all': all_count = Player.objects.count() else: all_count = Player.objects.filter(country=country).count() base["all_count"] = all_count q = Player.objects.all() if country != 'all': q = q.filter(country=country) queries = { 'birthday': q.filter(birthday__isnull=True), 'name': q.filter(name__isnull=True), 'country': q.filter(country__isnull=True) } base["subnav"] = [(_('Progress'), '/add/player_info/')] if all_count == 0: base['no_players'] = True elif choice is not None and choice in ('birthday', 'name', 'country'): q = queries[choice].extra(select=EXTRA_NULL_SELECT)\ .order_by( "-null_curr", "-current_rating__rating", "id" ) base["players"] = q[(page-1)*50:page*50] base["page"] = page base["next_page"] = q.count() > page * 50 base["form"] = PlayerInfoForm() else: values = dict() for k, v in queries.items(): c = all_count - v.count() values[k] = { 'count': c, 'pctg': '%.2f' % (100*float(c)/float(all_count)) } values["birthday"]["title"] = _("Players with birthday") values["name"]["title"] = _("Players with name") values["country"]["title"] = _("Players with country") base["values"] = list(values.items()) base["values"].sort(key=lambda x: x[0]) return render_to_response('player_info.djhtml', base)
def player_info(request, choice=None): base = base_ctx('Submit', 'Player Info', request) if not base['adm']: return redirect('/login/') login_message(base) if request.method == 'POST': form = PlayerInfoForm(request.POST) if form.is_valid(): player = form.commit() base['messages'].append( Message( # Translators: Updated a player text=_("Updated %s") % player_filter(player), type=Message.SUCCESS)) page = 1 if 'page' in request.GET: try: page = int(request.GET['page']) except: pass country = 'all' if 'country' not in request.GET else request.GET['country'] base['country'] = country base['countries'] = country_list(Player.objects.all()) if country == 'all': all_count = Player.objects.count() else: all_count = Player.objects.filter(country=country).count() base["all_count"] = all_count q = Player.objects.all() if country != 'all': q = q.filter(country=country) queries = { 'birthday': q.filter(birthday__isnull=True), 'name': q.filter(name__isnull=True), 'country': q.filter(country__isnull=True) } base["subnav"] = [(_('Progress'), '/add/player_info/')] if all_count == 0: base['no_players'] = True elif choice is not None and choice in ('birthday', 'name', 'country'): q = queries[choice].extra(select=EXTRA_NULL_SELECT)\ .order_by( "-null_curr", "-current_rating__rating", "id" ) base["players"] = q[(page - 1) * 50:page * 50] base["page"] = page base["next_page"] = q.count() > page * 50 base["form"] = PlayerInfoForm() else: values = dict() for k, v in queries.items(): c = all_count - v.count() values[k] = { 'count': c, 'pctg': '%.2f' % (100 * float(c) / float(all_count)) } values["birthday"]["title"] = _("Players with birthday") values["name"]["title"] = _("Players with name") values["country"]["title"] = _("Players with country") base["values"] = list(values.items()) base["values"].sort(key=lambda x: x[0]) return render_to_response('player_info.djhtml', base)
def events(request): base = base_ctx('Submit', 'Events', request) if not base['adm']: return redirect('/login/') login_message(base) base['messages'].append(Message( _("If you haven't used this tool before, ask before you do anything."), type=Message.WARNING)) if request.method == 'POST': form = AddEventsForm(request=request) base['messages'] += form.commit() else: form = AddEventsForm() base['form'] = form # Build event list root_events = ( Event.objects.filter(downlink__child__closed=False) .filter(parent__isnull=True) .order_by('idx') .distinct() ) subtreemap = { e.id: [] for e in root_events } tree = [{ 'event': e, 'subtree': subtreemap[e.id], 'inc': 0, } for e in root_events] events = root_events while events: events = ( Event.objects.filter(downlink__child__closed=False) .filter(parent__in=events) .order_by('idx') .distinct() ) for e in events: subtreemap[e.id] = [] subtreemap[e.parent_id].append({ 'event': e, 'subtree': subtreemap[e.id], 'inc': 0, }) base['tree'] = [] def do_level(level, indent): for e in level: e['indent'] = indent base['tree'].append(e) if e['subtree']: base['tree'][-1]['inc'] += 1 do_level(e['subtree'], indent+1) base['tree'][-1]['inc'] -= 1 do_level(tree, 0) return render_to_response('eventmgr.djhtml', base)
def login_view(request): base = base_ctx(request=request) login_message(base) base.update({"title": "Login"}) return render_to_response('login.html', base)