本文整理汇总了Python中bookie.models.BmarkMgr类的典型用法代码示例。如果您正苦于以下问题:Python BmarkMgr类的具体用法?Python BmarkMgr怎么用?Python BmarkMgr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BmarkMgr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_error
def edit_error(request):
rdict = request.matchdict
params = request.params
post = request.POST
with ReqAuthorize(request, username=rdict['username']):
if 'new' in request.url:
BmarkMgr.store(post['url'],
request.user.username,
post['description'],
post['extended'],
post['tags'])
else:
if 'hash_id' in rdict:
hash_id = rdict['hash_id']
elif 'hash_id' in params:
hash_id = params['hash_id']
bmark = BmarkMgr.get_by_hash(hash_id, request.user.username)
if bmark is None:
return HTTPNotFound()
bmark.fromdict(post)
bmark.update_tags(post['tags'])
# if this is a new bookmark from a url, offer to go back to that url
# for the user.
if 'go_back' in params and params['comes_from'] != "":
return HTTPFound(location=params['comes_from'])
else:
return HTTPFound(
location=request.route_url('user_bmark_recent',
username=request.user.username))
示例2: save_bookmark
def save_bookmark(self, url, desc, ext, tags, dt=None):
"""Save the bookmark to the db
:param url: bookmark url
:param desc: one line description
:param ext: extended description/notes
:param tags: The string of tags to store with this bmark
:param mark: Instance of Bmark that we're storing to db
"""
# we should make sure that this url isn't already bookmarked before
# adding it...if the hash matches, you must skip!
check_hash = generate_hash(url)
if check_hash not in self.hash_list:
BmarkMgr.store(url,
self.username,
desc,
ext,
tags,
dt=dt,
inserted_by=IMPORTED)
# add this hash to the list so that we can skip dupes in the same
# import set
self.hash_list.add(check_hash)
示例3: edit
def edit(request):
"""Manual add a bookmark to the user account
Can pass in params (say from a magic bookmarklet later)
url
description
extended
tags
"""
rdict = request.matchdict
params = request.params
new = False
with ReqAuthorize(request, username=rdict['username']):
if 'hash_id' in rdict:
hash_id = rdict['hash_id']
elif 'hash_id' in params:
hash_id = params['hash_id']
else:
hash_id = None
if hash_id:
bmark = BmarkMgr.get_by_hash(hash_id, request.user.username)
if bmark is None:
return HTTPNotFound()
else:
# hash the url and make sure that it doesn't exist
url = params.get('url', u"")
if url != u"":
new_url_hash = generate_hash(url)
test_exists = BmarkMgr.get_by_hash(new_url_hash,
request.user.username)
if test_exists:
location = request.route_url(
'user_bmark_edit',
hash_id=new_url_hash,
username=request.user.username)
return HTTPFound(location)
new = True
desc = params.get('description', None)
bmark = Bmark(url, request.user.username, desc=desc)
tag_suggest = TagMgr.suggestions(
url=bmark.hashed.url,
username=request.user.username
)
return {
'new': new,
'bmark': bmark,
'user': request.user,
'tag_suggest': tag_suggest,
}
示例4: posts_add
def posts_add(request):
"""Add a new bmark into the system given request params
For example usage make sure to check out the unit tests in the
test_delicious directory
"""
params = request.GET
with Authorize(request.registry.settings.get("api_key", ""), params.get("api_key", None)):
request.response_content_type = "text/xml"
if "url" in params and params["url"]:
# check if we already have this
try:
mark = BmarkMgr.get_by_url(params["url"])
mark.description = params.get("description", mark.description)
mark.extended = params.get("extended", mark.extended)
new_tags = params.get("tags", None)
if new_tags:
mark.update_tags(new_tags)
except NoResultFound:
# then let's store this thing
# if we have a dt param then set the date to be that manual
# date
if "dt" in request.params:
# date format by delapi specs:
# CCYY-MM-DDThh:mm:ssZ
fmt = "%Y-%m-%dT%H:%M:%SZ"
stored_time = datetime.strptime(request.params["dt"], fmt)
else:
stored_time = None
# we want to store fulltext info so send that along to the
# import processor
conn_str = request.registry.settings.get("sqlalchemy.url", False)
fulltext = get_fulltext_handler(conn_str)
BmarkMgr.store(
params["url"],
params.get("description", ""),
params.get("extended", ""),
params.get("tags", ""),
dt=stored_time,
fulltext=fulltext,
)
return '<result code="done" />'
else:
return '<result code="Bad Request: missing url" />'
示例5: count_rrd
def count_rrd():
"""Add these counts to the rrd graph"""
rrd = SystemCounts(
ini.get('rrd_data').format(here=HERE),
ini.get('rrd_graphs').format(here=HERE))
rrd.mark(
datetime.now(),
BmarkMgr.count(),
BmarkMgr.count(distinct=True),
TagMgr.count()
)
rrd.update()
示例6: save_bookmark
def save_bookmark(self, url, desc, ext, tags, dt=None, fulltext=None):
"""Save the bookmark to the db
:param url: bookmark url
:param desc: one line description
:param ext: extended description/notes
:param tags: The string of tags to store with this bmark
:param mark: Instance of Bmark that we're storing to db
:param fulltext: Fulltext handler instance used to store that info
"""
BmarkMgr.store(url, desc, ext, tags, dt=dt, fulltext=fulltext)
示例7: edit_error
def edit_error(request):
rdict = request.matchdict
params = request.params
post = request.POST
with ReqAuthorize(request, username=rdict['username']):
if 'new' in request.url:
try:
try:
bmark = BmarkMgr.get_by_url(post['url'])
except:
bmark = None
if bmark:
return {
'new': False,
'bmark': bmark,
'message': "URL already Exists",
'user': request.user,
}
bmark = BmarkMgr.store(
post['url'],
request.user.username,
post['description'],
post['extended'],
post['tags'])
# Assign a task to fetch this pages content and parse it out
# for storage and indexing.
DBSession.flush()
tasks.fetch_bmark_content.delay(bmark.bid)
except InvalidBookmark, exc:
# There was an issue using the supplied data to create a new
# bookmark. Send the data back to the user with the error
# message.
bmark = Bmark(
post['url'],
request.user.username,
desc=post['description'],
ext=post['extended'],
tags=post['tags'])
return {
'new': True,
'bmark': bmark,
'message': exc.message,
'user': request.user,
}
else:
示例8: bmark_popular
def bmark_popular(request):
"""Get a list of the most popular bmarks for the api call"""
rdict = request.matchdict
params = request.params
# check if we have a page count submitted
page = int(params.get('page', '0'))
count = int(params.get('count', RESULTS_MAX))
with_content = True if 'with_content' in params and params['with_content'] != "false" else False
username = request.user.username
# thou shalt not have more then the HARD MAX
# @todo move this to the .ini as a setting
if count > HARD_MAX:
count = HARD_MAX
# do we have any tags to filter upon
tags = rdict.get('tags', None)
if isinstance(tags, str):
tags = [tags]
# if we don't have tags, we might have them sent by a non-js browser as a
# string in a query string
if not tags and 'tag_filter' in params:
tags = params.get('tag_filter').split()
popular_list = BmarkMgr.find(limit=count,
order_by=Bmark.clicks.desc(),
page=page,
tags=tags,
username=username,
with_content=with_content,
with_tags=True,
)
result_set = []
for res in popular_list:
return_obj = dict(res)
return_obj['tags'] = [dict(tag[1]) for tag in res.tags.items()]
# the hashed object is there as well, we need to pull the url and
# clicks from it as total_clicks
return_obj['url'] = res.hashed.url
return_obj['total_clicks'] = res.hashed.clicks
if with_content:
return_obj['readable'] = dict(res.hashed.readable)
result_set.append(return_obj)
return {
'bmarks': result_set,
'max_count': RESULTS_MAX,
'count': len(popular_list),
'page': page,
'tag_filter': tags,
}
示例9: __init__
def __init__(self, import_io, username=None):
"""work on getting an importer instance"""
self.file_handle = import_io
self.username = username
# we need to get our list of hashes to make sure we check for dupes
self.hash_list = set([b[0] for b in BmarkMgr.hash_list(username=username)])
示例10: save_bookmark
def save_bookmark(self, url, desc, ext, tags, dt=None):
"""Save the bookmark to the db
:param url: bookmark url
:param desc: one line description
:param ext: extended description/notes
:param tags: The string of tags to store with this bmark
:param mark: Instance of Bmark that we're storing to db
"""
# If a bookmark has the tag "private" then we ignore it to prevent
# leaking user data.
if tags and "private" in tags.lower().split(" "):
return None
check_hash = generate_hash(url)
# We should make sure that this url isn't already bookmarked before
# adding it...if the hash matches, you must skip!
if check_hash not in self.hash_list:
bmark = BmarkMgr.store(url, self.username, desc, ext, tags, dt=dt, inserted_by=IMPORTED)
# Add this hash to the list so that we can skip dupes in the
# same import set.
self.hash_list.add(check_hash)
return bmark
# If we don't store a bookmark then just return None back to the
# importer.
return None
示例11: bmark_list
def bmark_list(request):
"""Display the list of bookmarks for this tag"""
rdict = request.matchdict
# check if we have a page count submitted
tag = rdict.get('tag')
page = int(rdict.get('page', 0))
# verify the tag exists before we go on
# 404 if the tag isn't found
exists = TagMgr.find(tags=[tag])
if not exists:
raise HTTPNotFound()
bmarks = BmarkMgr.by_tag(tag,
limit=RESULTS_MAX,
page=page)
return {'tag': tag,
'bmark_list': bmarks,
'max_count': RESULTS_MAX,
'count': len(bmarks),
'page': page,
'allow_edit': access.edit_enabled(request.registry.settings),
}
示例12: admin_bmark_remove
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'])
})
示例13: posts_get
def posts_get(request):
"""Return one or more bmarks based on search criteria
Supported criteria:
- url
TBI:
- tag={TAG}+{TAG}+
- dt={CCYY-MM-DDThh:mm:ssZ}
- hashes={MD5}+{MD5}+...+{MD5}
"""
params = request.GET
request.response_content_type = "text/xml"
try:
if "url" in params and params["url"]:
url = request.GET["url"]
bmark = BmarkMgr.get_by_url(url=url)
if not bmark:
return HTTPNotFound()
# we need to escape any html entities in things
return {"datefound": bmark.stored.strftime("%Y-%m-%d"), "posts": [bmark], "escape": escape}
else:
request.override_renderer = "string"
return '<result code="Not Found" />'
except NoResultFound:
request.override_renderer = "string"
return '<result code="Not Found" />'
示例14: bmark_list
def bmark_list(request):
"""Display the list of bookmarks for this tag"""
rdict = request.matchdict
params = request.params
# check if we have a page count submitted
tags = rdict.get('tags')
username = rdict.get("username", None)
page = int(params.get('page', 0))
# verify the tag exists before we go on
# 404 if the tag isn't found
exists = TagMgr.find(tags=tags)
if not exists:
raise HTTPNotFound()
bmarks = BmarkMgr.find(tags=tags,
limit=RESULTS_MAX,
page=page,
username=username)
return {
'tags': tags,
'bmark_list': bmarks,
'max_count': RESULTS_MAX,
'count': len(bmarks),
'page': page,
'username': username,
}
示例15: test_unique_ct
def test_unique_ct(self):
"""Verify that our unique count method is working"""
ct = 5
common = 'testing.com'
users = []
for i in range(ct):
user = User()
user.username = gen_random_word(10)
DBSession.add(user)
users.append(user)
for i in range(ct - 2):
b = Bmark(
url=gen_random_word(12),
username=users[i].username
)
DBSession.add(b)
# Add in our dupes
c = Bmark(
url=common,
username=users[3].username
)
DBSession.add(c)
DBSession.flush()
d = Bmark(
url=common,
username=users[4].username
)
DBSession.add(d)
DBSession.flush()
ct = BmarkMgr.count(distinct=True)
eq_(4, ct, 'We should have a total of 4: ' + str(ct))