Remove achievement when nobody endorses it

This commit is contained in:
Robbe Van Herck 2018-11-28 16:14:15 +01:00
parent 10b81c454f
commit a284514663
No known key found for this signature in database
GPG key ID: 4D1C8E8FBD1C7188

View file

@ -36,5 +36,11 @@ def unendorse_achievement(id):
return "Can't unendorse if you never endorsed..."
achievement.endorsed_by.remove(current_user)
db.session.add(achievement)
db.session.commit()
return redirect(url_for("get_achievement", id=id))
if len(achievement.endorsed_by) == 0:
db.session.delete(achievement)
db.session.commit()
return redirect(url_for("all_users"))
else:
db.session.commit()
return redirect(url_for("get_achievement", id=id))