예제 #1
0
def postdeletemedal(user):
    medalid = request.form.get("medalid", None)
    medals = json.loads(user.medals) if user.medals is not None else None
    if medals is not None and medalid is not None:
        medals = [x for x in medals if x['id'] != int(medalid)]
        sql.updateMedals(user.login, json.dumps(medals) if len(medals) else None)
    flash("User updated !", "success")
예제 #2
0
def postaddmedal(user):
    newmedal = request.form.get("newmedal")
    if newmedal != "":
        medals = json.loads(user.medals) if user.medals is not None else []
        medalid = (medals[-1]["id"] + 1) if len(medals) else 1
        medals.append({"id": medalid, "text": newmedal})
        sql.updateMedals(user.login, json.dumps(medals))
    flash("User updated !", "success")