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, }
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, }
def bmark_list(request): """Display the list of bookmarks for this tag""" route_name = request.matched_route.name rdict = request.matchdict params = request.params # check if we have a page count submitted tags = rdict.get('tags') 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,) if 'ajax' in route_name: html = render('bookie:templates/tag/bmarks.mako', { 'tags': tags, 'bmark_list': bmarks, 'max_count': RESULTS_MAX, 'count': len(bmarks), 'page': page, 'allow_edit': access.edit_enabled(request.registry.settings), }, request=request) return { 'success': True, 'message': "", 'payload': { 'html': html, } } else: return {'tags': tags, 'bmark_list': bmarks, 'max_count': RESULTS_MAX, 'count': len(bmarks), 'page': page, 'allow_edit': access.edit_enabled(request.registry.settings), }
def recent(request): """Most recent list of bookmarks capped at MAX""" rdict = request.matchdict params = request.params LOG.debug('in recent!') # check if we have a page count submitted page = int(params.get('page', '0')) # do we have any tags to filter upon tags = rdict.get('tags', None) if isinstance(tags, str): tags = [tags] # check for auth related stuff # are we looking for a specific user username = rdict.get('username', None) # 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() recent_list = BmarkMgr.find(limit=RESULTS_MAX, order_by=Bmark.stored.desc(), tags=tags, page=page, username=username) ret = { 'bmarks': recent_list, 'max_count': RESULTS_MAX, 'count': len(recent_list), 'page': page, 'tags': tags, 'username': username, } return ret
def popular(request): """Most popular list of bookmarks capped at MAX""" rdict = request.matchdict params = request.params # check if we have a page count submitted tags = rdict.get('tags', None) page = int(params.get('page', '0')) recent_list = BmarkMgr.find(limit=RESULTS_MAX, order_by=Bmark.stored.desc(), tags=tags, page=page) return { 'bmarks': recent_list, 'max_count': RESULTS_MAX, 'count': len(recent_list), 'page': page, 'allow_edit': access.edit_enabled(request.registry.settings), } rdict = request.matchdict # check if we have a page count submitted page = int(rdict.get('page', '0')) popular_list = BmarkMgr.popular(limit=RESULTS_MAX, with_tags=True, page=page) return { 'bmarks': popular_list, 'max_count': RESULTS_MAX, 'count': len(popular_list), 'page': page, 'allow_edit': access.edit_enabled(request.registry.settings), }
def recent(request): """Most recent list of bookmarks capped at MAX""" rdict = request.matchdict params = request.params # check if we have a page count submitted page = int(params.get('page', '0')) # 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() LOG.debug('tags') LOG.debug(tags) recent_list = BmarkMgr.find(limit=RESULTS_MAX, order_by=Bmark.stored.desc(), tags=tags, page=page) ret = { 'bmarks': recent_list, 'max_count': RESULTS_MAX, 'count': len(recent_list), 'page': page, 'tags': tags, 'allow_edit': access.edit_enabled(request.registry.settings), } return ret
def bmark_recent(request): """Get a list of the 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 = _check_with_content(params) # we only want to do the username if the username is in the url username = rdict.get('username', None) # 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() # @todo fix this! # if we allow showing of content the query hangs and fails on the # postgres side. Need to check the query and figure out what's up. # see bug #142 with_content = False recent_list = BmarkMgr.find(limit=count, order_by=Bmark.stored.desc(), page=page, tags=tags, username=username, with_content=with_content, with_tags=True, ) result_set = [] for res in recent_list: return_obj = dict(res) return_obj['tags'] = [dict(tag[1]) for tag in res.tags.items()] # we should have the hashed information, we need the url and clicks as # total clicks to send back return_obj['url'] = res.hashed.url return_obj['total_clicks'] = res.hashed.clicks if with_content: return_obj['readable'] = dict(res.readable) if res.readable else {} result_set.append(return_obj) return { 'bmarks': result_set, 'max_count': RESULTS_MAX, 'count': len(recent_list), 'page': page, 'tag_filter': tags, }
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 = _check_with_content(params) if request.user and request.user.username: username = request.user.username else: username = None # 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, }
def bmark_recent(request, with_content=False): """Get a list of the 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)) # we only want to do the username if the username is in the url username = rdict.get('username', None) # 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() # @todo fix this! # if we allow showing of content the query hangs and fails on the # postgres side. Need to check the query and figure out what's up. # see bug #142 # We don't allow with_content by default because of this bug. recent_list = BmarkMgr.find( limit=count, order_by=Bmark.stored.desc(), page=page, tags=tags, username=username, with_tags=True, ) result_set = [] for res in recent_list: return_obj = dict(res) return_obj['tags'] = [dict(tag[1]) for tag in res.tags.items()] # we should have the hashed information, we need the url and clicks as # total clicks to send back return_obj['url'] = res.hashed.url return_obj['total_clicks'] = res.hashed.clicks if with_content: return_obj['readable'] = dict(res.readable) if res.readable else {} result_set.append(return_obj) return { 'bmarks': result_set, 'max_count': RESULTS_MAX, 'count': len(recent_list), 'page': page, 'tag_filter': tags, }