def problem_data(): _user = user.get_user().first() if not user.is_admin(): if not user.in_team(_user): raise WebException("You need a team.") problems = get_problems(_user.tid, admin=user.is_admin()) problems_return = [ ] for problem in problems: solves = get_solves(problem.pid) solved = Solves.query.filter_by(pid=problem.pid, tid=session.get("tid", None), correct=1).first() solved = ["Solved", "Unsolved"][solved is None] description = process_description(problem.description) data = { "pid": problem.pid, "title": problem.title, "category": problem.category, "description": description, "hint": problem.hint, "value": problem.value, "solves": solves, "solved": solved } admin_data = { "description_source": problem.description, "threshold": problem.threshold, "weightmap": problem.weightmap, "grader_contents": open(problem.grader, "r").read(), "bonus": problem.bonus, "autogen": problem.autogen == True } if "admin" in session and session["admin"]: data.update(admin_data) if problem.autogen: grader = imp.load_source("grader", problem.grader) tid = session.get("tid", "team") try: data.update(grader.generate_problem(autogen.get_random(problem.pid, tid), problem.pid)) except Exception, e: logger.log(__name__, "The grader for \"%s\" has thrown an error: %s" % (problem.title, e)) problems_return.append(data)
def course_data(): if request.method == "GET": all_course_data = courses.get_course_details() if(all_course_data == None): all_course_data = [""] return render_template("courses.html", all_course_data=all_course_data, club_names=clubs.get_club_names(), user=user) if request.method == "POST": course_name = request.form['courseName'] club_name = request.form['club'] pars = request.form.getlist('par') lengths = request.form.getlist('length') if(user.is_admin()): courses.add_course(club_name, course_name, pars, lengths) return redirect("/courses")
def ticket_data(): opened = [] closed = [] _user = user.get_user().first() if _user is None: raise WebException("User does not exist.") params = utils.flat_multi(request.args) htid = params.get("htid") if htid is not None: result = get_ticket(htid=htid).first() elif user.is_admin(): result = get_ticket().all() else: result = get_ticket(author=_user.uid).all() if result is not None: if htid is not None: tickets = [result] else: tickets = result for ticket in tickets: tmp = user.get_user(uid=ticket.author).first() if tmp is not None: username = tmp.username uid = tmp.uid else: username = "" uid = "" replies = ticket.get_replies() d = { "htid": ticket.htid, "date": utils.isoformat(ticket.date), "opened": ticket.opened, "username": username, "uid": uid, "title": ticket.title, "body": markdown2.markdown(ticket.body), "replies": replies, "participants": list(set([username] + [reply["username"] for reply in replies])), "you": { "username": _user.username, "uid": _user.uid } } if htid is None: if d["opened"] == True: opened.append(d) else: closed.append(d) else: data = d else: data = {} if htid is None: data = [opened, closed] return {"success": 1, "data": data}
def ticket_data(): opened = [] closed = [] _user = user.get_user().first() if _user is None: raise WebException("User does not exist.") params = utils.flat_multi(request.args) htid = params.get("htid") if htid is not None: result = get_ticket(htid=htid).first() elif user.is_admin(): result = get_ticket().all() else: result = get_ticket(author=_user.uid).all() if result is not None: if htid is not None: tickets = [result] else: tickets = result for ticket in tickets: tmp = user.get_user(uid=ticket.author).first() if tmp is not None: username = tmp.username uid = tmp.uid else: username = "" uid = "" replies = ticket.get_replies() d = { "htid": ticket.htid, "date": utils.isoformat(ticket.date), "opened": ticket.opened, "username": username, "uid": uid, "title": ticket.title, "body": markdown2.markdown(ticket.body), "replies": replies, "participants": list(set([username] + [reply["username"] for reply in replies])), "you": { "username": _user.username, "uid": _user.uid } } if htid is None: if d["opened"] == True: opened.append(d) else: closed.append(d) else: data = d else: data = {} if htid is None: data = [opened, closed] return { "success": 1, "data": data }
def _require_admin(self, user): if not user.is_admin(): raise ListError(_("You don't have permission to do that.\n"))
def wrapper(*args, **kwds): if not user.is_admin(): return {"success": 0, "message": "Not authorized."} return f(*args, **kwds)
def wrapper(*args, **kwds): if not user.is_admin(): return { "success": 0, "message": "Not authorized." } return f(*args, **kwds)