本文整理汇总了Python中bookie.models.DBSession.delete方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.delete方法的具体用法?Python DBSession.delete怎么用?Python DBSession.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bookie.models.DBSession
的用法示例。
在下文中一共展示了DBSession.delete方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin_bmark_remove
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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'])
})
示例2: delete
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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()
示例3: test_activation_delete
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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)))
示例4: del_user
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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: ' + del_username
})
except Exception, exc:
# There might be cascade issues or something that causes us to fail in
# removing.
LOG.error(exc)
request.response.status_int = 500
return _api_response(request, {
'error': 'Bad Request: ' + str(exc)
})
示例5: delete
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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()
示例6: posts_delete
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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" />'
示例7: posts_delete
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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" />'
示例8: bmark_remove
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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'])
}
示例9: test_activation_cascade
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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')
示例10: activate
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
def activate(self):
"""Remove this activation"""
DBSession.delete(self)
示例11: defaultdict
# 需要导入模块: from bookie.models import DBSession [as 别名]
# 或者: from bookie.models.DBSession import delete [as 别名]
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()