Use different flair for edit

This commit is contained in:
Hans5958 2022-04-10 17:53:26 +07:00
parent d9107ac6df
commit 41ab1f0d20

View file

@ -89,7 +89,7 @@ def set_flair(submission, flair):
else:
continue
if (submission.link_flair_text == "New Entry"):
if submission.link_flair_text == "New Entry" or submission.link_flair_text == "Edit Entry":
try:
@ -106,12 +106,10 @@ def set_flair(submission, flair):
if submission_json:
submission_json_dummy = {"id": submission.id, "edit": True, "contributors": []}
if submission.link_flair_text == "Edit Entry":
if (submission_json.id != 0):
submission_json_dummy["id"] = submission_json.id
else:
del submission_json_dummy["edit"]
assert submission_json["id"] != 0, "ID is tampered, it must not be 0!"
submission_json_dummy = {"id": submission_json["id"], "edit": True, "contributors": []}
if "submitted_by" in submission_json:
submission_json_dummy["contributors"].append(submission_json['submitted_by'])
@ -125,6 +123,24 @@ def set_flair(submission, flair):
except AttributeError:
submission_json_dummy["contributors"].append("unknown")
else:
assert submission_json["id"] == 0, "ID is tampered, it must be 0!"
submission_json_dummy = {"id": submission.id, "contributors": []}
if "submitted_by" in submission_json:
submission_json_dummy["contributors"].append(submission_json['submitted_by'])
del submission_json['submitted_by']
elif "contributors" in submission_json:
submission_json_dummy["contributors"] = submission_json["contributors"]
try:
if not submission.author.name in submission_json_dummy:
submission_json_dummy["contributors"].append(submission.author.name)
except AttributeError:
submission_json_dummy["contributors"].append("unknown")
for key in submission_json:
if not key in submission_json_dummy:
submission_json_dummy[key] = submission_json[key];