def tools_forum_flags_action(id): cuser = muser.getCurrentUser() if not cuser.isMod(): abort(404) flagged = mreviews.CustomQueue.getItemData(id) flagged = dict(flagged) if not flagged or (flagged["item_type"] != "forum.question" and flagged["item_type"] != "forum.answer"): abort(404) if flagged["item_type"] == "forum.question": flagged["post"] = mforum.Article(flagged["item_id"]) elif flagged["item_type"] == "forum.answer": flagged["post"] = mforum.Answer(flagged["item_id"]) if flagged["state"] == 0: flags = request.json["flags"] for f in flags: mreviews.CustomQueue.manageFlag(id, f, request.json["result"], request.json["response"]) if mreviews.CustomQueue.getItemOpenFlagsCount(id) == 0: return "{ok:last}" return "{ok}" return "{ok:last}"
def _prepare(d): d = dict(d) if d["item_type"] == "forum.question": d["post"] = mforum.Article(d["item_id"]) elif d["item_type"] == "forum.answer": d["post"] = mforum.Answer(d["item_id"]) return d
def tools_forum_flags_item(id): cuser = muser.getCurrentUser() if not cuser.isMod(): abort(404) flagged = mreviews.CustomQueue.getItemData(id) flagged = dict(flagged) if not flagged or (flagged["item_type"] != "forum.question" and flagged["item_type"] != "forum.answer"): abort(404) if flagged["item_type"] == "forum.question": flagged["post"] = mforum.Article(flagged["item_id"]) elif flagged["item_type"] == "forum.answer": flagged["post"] = mforum.Answer(flagged["item_id"]) flags = mreviews.CustomQueue.getItemFlags(id) def _prepare(d): d = dict(d) d["flagger"] = muser.User.from_id(d["flagger_id"]) return d flags = list(map(_prepare, flags)) has_open_flags = mreviews.CustomQueue.getItemOpenFlagsCount(id) != 0 return render_template("tools/forum_flag_item.html", title="Werkzeuge - Beitragsmeldungen", thispage="tools", item=flagged, flags=flags, has_open_flags=has_open_flags)
def tools_forum_flags_finish(id): cuser = muser.getCurrentUser() if not cuser.isMod(): abort(404) flagged = mreviews.CustomQueue.getItemData(id) flagged = dict(flagged) if not flagged or (flagged["item_type"] != "forum.question" and flagged["item_type"] != "forum.answer"): abort(404) if flagged["item_type"] == "forum.question": flagged["post"] = mforum.Article(flagged["item_id"]) elif flagged["item_type"] == "forum.answer": flagged["post"] = mforum.Answer(flagged["item_id"]) if flagged["state"] == 0: mreviews.CustomQueue.completeReview(id) return "{ok}"
def user_activity_page(id, name=None): try: id = int(id) except: abort(404) if muser.User.exists(id): user = muser.User.from_id(id) cuser = muser.getCurrentUser() mt = user.getDetail("mergeto") if mt and not cuser.isMod(): return redirect(url_for("user_edit_page", id=mt)) if user.isDeleted(): if not cuser.isMod(): abort(404) else: return redirect(url_for("user_deleted_page", id=id)) if name != user.getDetail("name"): return redirect( url_for("user_activity_page", id=id, name=user.getDetail("name"))) else: if request.values.get("page", "summary") == "summary": return render_template("user/activity/summary.html", data=user, thispage="user", title="Aktivität " + user.getHTMLName(False), courses=mcourses.Courses) elif request.values.get("page", "summary") == "courses": return render_template( "user/activity/courses.html", data=user, thispage="user", title="Kurse von " + user.getHTMLName(False), mcourses=mcourses.Courses, mproposals=mproposal.Proposal, prs=mpull_requests.PullRequest.getByUser(user.id, None)) elif request.values.get("page", "summary") == "forum": return render_template("user/activity/forum.html", data=user, thispage="user", title="Forenbeiträge von " + user.getHTMLName(False), mquestions=mforum.Article, manswers=mforum.Answer, mquestion=lambda x: mforum.Article(x)) elif request.values.get("page", "summary") == "reputation": return render_template("user/activity/reputation.html", data=user, thispage="user", title="Reputation von " + user.getHTMLName(False)) elif request.values.get("page", "summary") == "badges": return render_template("user/activity/badges.html", data=user, thispage="user", title="Abzeichen von " + user.getHTMLName(False), getCollectedBadges=mbadges.Badge.byUser) elif request.values.get("page", "summary") == "flags": if user.id != cuser.id and not cuser.isMod(): abort(403) closure_filter = request.values.get("closure", "all") closure_data = mreviews.PostClosure.getFromUser(user) cd = [] closure_helpful = closure_pending = closure_declined = closure_total = 0 for row in closure_data: closure_total += 1 if row["state"] == 0: closure_pending += 1 if closure_filter not in ["all", "pending"]: continue elif row["state"] > 0: closure_helpful += 1 if closure_filter not in ["all", "helpful"]: continue elif row["state"] == -2: closure_declined += 1 if closure_filter not in ["all", "declined"]: continue row["item"] = mforum.Article(row["item_id"]) cd.append(row) post_deletion_filter = request.values.get( "post_deletion", "all") post_deletion_data = mreviews.PostDeletion.getFromUser(user) pdd = [] post_deletion_helpful = post_deletion_pending = post_deletion_declined = post_deletion_total = 0 for row in post_deletion_data: post_deletion_total += 1 if row["state"] == 0: post_deletion_pending += 1 if post_deletion_filter not in ["all", "pending"]: continue elif row["state"] > 0: post_deletion_helpful += 1 if post_deletion_filter not in ["all", "helpful"]: continue elif row["state"] == -2: post_deletion_declined += 1 if post_deletion_filter not in ["all", "declined"]: continue row["item"] = mforum.Article(row["item_id"]) pdd.append(row) custom_filter = request.values.get("custom", "all") custom_data = mreviews.CustomQueue.getFromUser(user) customd = [] custom_helpful = custom_pending = custom_declined = custom_total = 0 for row in custom_data: custom_total += 1 if row["state"] == 0: custom_pending += 1 if custom_filter not in ["all", "pending"]: continue elif row["state"] > 0: custom_helpful += 1 if custom_filter not in ["all", "helpful"]: continue elif row["state"] == -2: custom_declined += 1 if custom_filter not in ["all", "declined"]: continue if row["item_type"] == "forum.question": row["item"] = mforum.Article(row["item_id"]) elif row["item_type"] == "forum.answer": row["item"] = mforum.Answer(row["item_id"]) elif row["item_type"] == "user": row["item"] = muser.User.from_id(row["item_id"]) customd.append(row) return render_template( "user/activity/flags.html", data=user, closure_flags=cd, post_deletion_flags=pdd, custom_flags=customd, thispage="user", title="Meldungen von " + user.getHTMLName(False), closure_helpful=closure_helpful, closure_pending=closure_pending, closure_declined=closure_declined, closure_total=closure_total, post_deletion_helpful=post_deletion_helpful, post_deletion_pending=post_deletion_pending, post_deletion_declined=post_deletion_declined, post_deletion_total=post_deletion_total, custom_helpful=custom_helpful, custom_pending=custom_pending, custom_declined=custom_declined, custom_total=custom_total) else: abort(404) else: abort(404)