add bookmark collection editor
This commit is contained in:
@@ -24,7 +24,7 @@ def get_bookmark_dropdown():
|
||||
except ValueError:
|
||||
return 'error', 400
|
||||
is_thread = concept_kind == 'thread'
|
||||
collections = BookmarkCollections.findall({'user_id': user.id})
|
||||
collections = BookmarkCollections.get_for_user(user.id)
|
||||
in_collection = None
|
||||
note = ''
|
||||
for collection in collections:
|
||||
|
||||
@@ -448,6 +448,69 @@ def bookmarks(username):
|
||||
username = username.lower()
|
||||
return 'stub'
|
||||
|
||||
@bp.get('/<username>/bookmarks/collections/')
|
||||
@login_required
|
||||
@user_required
|
||||
@redirect_to_own
|
||||
def bookmark_collections(username):
|
||||
user = get_active_user()
|
||||
collections = BookmarkCollections.get_for_user(user.id)
|
||||
return render_template('users/manage_collections.html', collections=collections)
|
||||
|
||||
@bp.post('/<username>/bookmarks/collections/')
|
||||
@login_required
|
||||
@user_required
|
||||
@redirect_to_own
|
||||
def edit_bookmark_collections(username):
|
||||
user = get_active_user()
|
||||
ids = request.form.getlist('id[]')
|
||||
names = request.form.getlist('name[]')
|
||||
if len(ids) == 0 or len(ids) != len(names):
|
||||
abort(400)
|
||||
deleted_ids = filter(lambda x: x.strip(), request.form.get('deleted_ids', '').split(';'))
|
||||
try:
|
||||
deleted_ids = map(lambda x: int(x), deleted_ids)
|
||||
except ValueError:
|
||||
abort(400)
|
||||
|
||||
with db.transaction():
|
||||
for new_order, id in enumerate(ids):
|
||||
new_name = names[new_order]
|
||||
if id == 'new':
|
||||
bc = BookmarkCollections.create({
|
||||
'user_id': user.id,
|
||||
'is_default': False,
|
||||
'name': new_name,
|
||||
'sort_order': new_order,
|
||||
})
|
||||
continue
|
||||
id = int(id)
|
||||
bc = BookmarkCollections.find({'id': id})
|
||||
if not bc:
|
||||
continue
|
||||
if bc.user_id != user.id:
|
||||
continue
|
||||
if bc.is_default:
|
||||
new_order = 0
|
||||
elif new_order == 0:
|
||||
new_order = 1
|
||||
bc.update({
|
||||
'name': new_name,
|
||||
'sort_order': new_order,
|
||||
})
|
||||
|
||||
for deleted_id in deleted_ids:
|
||||
bc = BookmarkCollections.find({'id': deleted_id})
|
||||
if not bc:
|
||||
continue
|
||||
if bc.user_id != user.id:
|
||||
continue
|
||||
if bc.is_default:
|
||||
continue
|
||||
bc.delete()
|
||||
|
||||
return redirect(url_for('.bookmark_collections', username=username))
|
||||
|
||||
@bp.get('/<username>/delete-confirm/')
|
||||
@login_required
|
||||
@redirect_to_own
|
||||
|
||||
Reference in New Issue
Block a user