def admin_bmark_remove(request): """Remove this bookmark from the system""" rdict = request.matchdict username = rdict.get('username') hash_id = rdict.get('hash_id') try: bmark = BmarkMgr.get_by_hash(hash_id, username=username) print bmark if bmark: DBSession.delete(bmark) return _api_response(request, { 'message': "done", }) else: return _api_response(request, { 'error': 'Bookmark not found.', }) except NoResultFound: request.response.status_code = 404 return _api_response(request, { 'error': 'Bookmark with hash id {0} not found.'.format( rdict['hash_id']) })
def admin_bmark_remove(request): """Remove this bookmark from the system""" rdict = request.matchdict username = rdict.get('username') hash_id = rdict.get('hash_id') try: bmark = BmarkMgr.get_by_hash(hash_id, username=username) print bmark if bmark: DBSession.delete(bmark) return { 'message': "done", } else: return { 'error': 'Bookmark not found.', } except NoResultFound: request.response.status_code = 404 return { 'error': 'Bookmark with hash id {0} not found.'.format(rdict['hash_id']) }
def test_activation_delete(self): """Make sure removing an activation does not remove a user.""" tst = User() tst.username = gen_random_word(10) tst.activation = Activation('signup') DBSession.add(tst) DBSession.flush() DBSession.delete(tst.activation) users = UserMgr.get_list() # We still have the admin user as well so the count is two. eq_(2, len(users), 'We should have a total of 2 users still: ' + str(len(users)))
def delete(request): """Remove the bookmark in question""" rdict = request.POST # make sure we have an id value bid = int(rdict.get('bid', 0)) if bid: found = Bmark.query.get(bid) if found: DBSession.delete(found) return HTTPFound(location=request.route_url('bmark_recent')) return HTTPNotFound()
def test_activation_delete(self): """Make sure removing an activation does not remove a user.""" tst = User() tst.username = gen_random_word(10) tst.activation = Activation(u'signup') DBSession.add(tst) DBSession.flush() DBSession.delete(tst.activation) users = UserMgr.get_list() # We still have the admin user as well so the count is two. self.assertEqual( 2, len(users), 'We should have a total of 2 users still: ' + str(len(users)))
def del_user(request): """Remove a bad user from the system via the api. For admin use only. Removes all of a user's bookmarks before removing the user. """ mdict = request.matchdict # Submit a username. del_username = mdict.get('username', None) if del_username is None: LOG.error('No username to remove.') request.response.status_int = 400 return _api_response(request, { 'error': 'Bad Request: No username to remove.', }) u = UserMgr.get(username=del_username) if not u: LOG.error('Username not found.') request.response.status_int = 404 return _api_response(request, { 'error': 'User not found.', }) try: # Delete all of the bmarks for this year. Bmark.query.filter(Bmark.username == u.username).delete() DBSession.delete(u) return _api_response(request, { 'success': True, 'message': 'Removed user: '******'error': 'Bad Request: ' + str(exc) })
def posts_delete(request): """Remove a bmark from the system""" params = request.GET request.response_content_type = "text/xml" with Authorize(request.registry.settings.get("api_key", ""), params.get("api_key", None)): if "url" in params and params["url"]: try: bmark = BmarkMgr.get_by_url(params["url"]) session = DBSession() session.delete(bmark) return '<result code="done" />' except NoResultFound: # if it's not found, then there's not a bookmark to delete return '<result code="Bad Request: bookmark not found" />'
def test_activation_cascade(self): """Removing a user cascades the activations as well.""" tst = User() tst.username = gen_random_word(10) tst.activation = Activation('signup') DBSession.add(tst) DBSession.flush() DBSession.delete(tst) users = UserMgr.get_list() # We still have the admin user as well so the count is one. eq_(1, len(users), 'We should have a total of 1 user still: ' + str(len(users))) activations = DBSession.query(Activation).all() eq_(0, len(activations), 'There should be no activations left')
def posts_delete(request): """Remove a bmark from the system""" params = request.params request.response.content_type = 'text/xml' if 'url' in params and params['url']: try: bmark = BmarkMgr.get_by_url(params['url'], username=request.user.username) session = DBSession() session.delete(bmark) return '<result code="done" />' except NoResultFound: # if it's not found, then there's not a bookmark to delete return '<result code="Bad Request: bookmark not found" />'
def delete(request): """Remove the bookmark in question""" rdict = request.POST if not access.edit_enabled(request.registry.settings): raise HTTPForbidden("Auth to edit is not enabled") # make sure we have an id value bid = int(rdict.get('bid', 0)) if bid: found = Bmark.query.get(bid) if found: DBSession.delete(found) return HTTPFound(location=request.route_url('bmark_recent')) return HTTPNotFound()
def bmark_remove(request): """Remove this bookmark from the system""" rdict = request.matchdict user = request.user try: bmark = BmarkMgr.get_by_hash(rdict['hash_id'], username=user.username) DBSession.delete(bmark) return { 'message': "done", } except NoResultFound: request.response.status_code = 404 return { 'error': 'Bookmark with hash id {0} not found.'.format(rdict['hash_id']) }
def bmark_remove(request): """Remove this bookmark from the system""" rdict = request.matchdict user = request.user try: bmark = BmarkMgr.get_by_hash(rdict['hash_id'], username=user.username) DBSession.delete(bmark) return { 'message': "done", } except NoResultFound: request.response.status_code = 404 return { 'error': 'Bookmark with hash id {0} not found.'.format( rdict['hash_id']) }
def posts_delete(request): """Remove a bmark from the system""" params = request.GET request.response_content_type = 'text/xml' with Authorize(request.registry.settings.get('api_key', ''), params.get('api_key', None)): if 'url' in params and params['url']: try: bmark = BmarkMgr.get_by_url(params['url']) session = DBSession() session.delete(bmark) return '<result code="done" />' except NoResultFound: # if it's not found, then there's not a bookmark to delete return '<result code="Bad Request: bookmark not found" />'
def del_user(request): """Remove a bad user from the system via the api. For admin use only. Removes all of a user's bookmarks before removing the user. """ mdict = request.matchdict # Submit a username. del_username = mdict.get('username', None) if del_username is None: LOG.error('No username to remove.') request.response.status_int = 400 return _api_response(request, { 'error': 'Bad Request: No username to remove.', }) u = UserMgr.get(username=del_username) if not u: LOG.error('Username not found.') request.response.status_int = 404 return _api_response(request, { 'error': 'User not found.', }) try: # Delete all of the bmarks for this year. Bmark.query.filter(Bmark.username == u.username).delete() DBSession.delete(u) return _api_response(request, { 'success': True, 'message': 'Removed user: '******'error': 'Bad Request: ' + str(exc)})
def test_activation_cascade(self): """Removing a user cascades the activations as well.""" tst = User() tst.username = gen_random_word(10) tst.activation = Activation('signup') DBSession.add(tst) DBSession.flush() DBSession.delete(tst) users = UserMgr.get_list() # We still have the admin user as well so the count is one. eq_( 1, len(users), 'We should have a total of 1 user still: ' + str(len(users))) activations = DBSession.query(Activation).all() eq_(0, len(activations), 'There should be no activations left')
bookmarks = Bmark.query.all() index = defaultdict(list) to_delete = [] for b in bookmarks: key = (b.username, b.hash_id) index[key].append(b) for k, v in index.iteritems(): if len(v) > 1: first = v[0] second = v[1] print first.hash_id to_delete.append(first) for name, tag in first.tags.items(): if name in second.tags: print "HAS IT" else: print "ADDING" + name second.tags[name] = tag assert len(first.tags) <= len(second.tags) print to_delete print len(to_delete) for b in to_delete: DBSession.delete(b) DBSession.flush() transaction.commit()
def activate(self): """Remove this activation""" DBSession.delete(self)