Make shelf names required unique

This commit is contained in:
Jan Broer 2015-10-13 19:12:18 +02:00
parent 350285607b
commit 2b846b1e6b

View File

@ -477,12 +477,16 @@ def create_shelf():
shelf.is_public = 1 shelf.is_public = 1
shelf.name = to_save["title"] shelf.name = to_save["title"]
shelf.user_id = int(current_user.id) shelf.user_id = int(current_user.id)
try: existing_shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.name == shelf.name).first()
ub.session.add(shelf) if existing_shelf:
ub.session.commit() flash("A shelf with the name '%s' already exists." % to_save["title"], category="error")
flash("Shelf %s created" % to_save["title"], category="success") else:
except: try:
flash("there was an error", category="error") ub.session.add(shelf)
ub.session.commit()
flash("Shelf %s created" % to_save["title"], category="success")
except:
flash("There was an error", category="error")
return render_template('shelf_edit.html', title="create a shelf") return render_template('shelf_edit.html', title="create a shelf")
else: else:
return render_template('shelf_edit.html', title="create a shelf") return render_template('shelf_edit.html', title="create a shelf")