def scoreboard(): city, promo = sql.getListCityPromo() promo.insert(0, "all") city.insert(0, "All") users = [u._asdict() for u in sql.getUsers()] if not"admin" in session or not session["admin"]: users = [u for u in users if u['hide'] == 0] tasks = sorted(sql.getTasks(), key=lambda x: (x.categorie, x.points, x.level)) lastrank = 0 lastpoints = 0 for idx, u in enumerate(users): if u['medals']: u['medals'] = "".join('<div class="medal" title="'+m["text"]+'"></div>' for m in u['medals']) txt = '<a class="lower task {solved}" title="{name}" href="/task/{name}"></a>\n' u["solved"] = "".join(txt.format(name=t.name, solved="solved" if t.id in u['solved'] else "unsolved") for t in tasks) u['rank'] = idx + 1 if u['points'] != lastpoints else lastrank lastrank = u['rank'] lastpoints = u['points'] return render_template("main.html", view="scoreboard.html", users=users, city=city, promo=promo)
def user(name): try: user = sql.getUser(name) except sql.SQLError: abort(404) tasks = sorted(sql.getTasks(), key=lambda x: (x.categorie, x.points, x.level)) return render_template("main.html", view="user.html", user=user, tasks=tasks, solved=sql.getSolved(user.login))
def admin_user(): if not "admin" in session or not session["admin"]: abort(404) login = request.args.get("login", None) try: user = sql.getUser(login) except sql.SQLError: flash("No such user", "danger") return redirect(url_for('admin')) if request.method == 'POST': ret = doPost(user) if ret: return ret user = sql.getUser(login) tasks = sorted(sql.getTasks(), key=(lambda x : (x.categorie, x.points, x.level))) medals = json.loads(user.medals) if user.medals is not None else None csrf_token = uuid.uuid4() session['csrf_token'] = csrf_token return render_template("main.html", view="admin_user.html", user=user, tasks=tasks, solved=sql.getSolved(user.login), medals=medals, csrf_token=csrf_token)
def show_tasks(): tasks = sorted(sql.getTasks(), key=lambda x: (x.categorie, x.points, x.level)) return render_template("main.html", view="tasks.html", tasks=tasks, solved=sql.getSolved(session["login"]) if ("login" in session) else [])