Example #1
0
File: tags.py Project: akn/Bookie
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),
               }
Example #2
0
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),
    }
Example #3
0
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),
           }
Example #4
0
File: bmarks.py Project: akn/Bookie
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),
           }
Example #5
0
def recent(request):
    """Most recent list of bookmarks capped at MAX"""
    rdict = request.matchdict

    # check if we have a page count submitted
    page = int(rdict.get('page', '0'))

    recent_list = BmarkMgr.recent(limit=RESULTS_MAX, with_tags=True, page=page)

    return {
        'bmarks': recent_list,
        'max_count': RESULTS_MAX,
        'count': len(recent_list),
        'page': page,
        'allow_edit': access.edit_enabled(request.registry.settings),
    }
Example #6
0
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()
Example #7
0
def recent(request):
    """Most recent list of bookmarks capped at MAX"""
    rdict = request.matchdict

    # check if we have a page count submitted
    page = int(rdict.get('page', '0'))

    recent_list = BmarkMgr.recent(limit=RESULTS_MAX,
                           with_tags=True,
                           page=page)

    return {
             'bmarks': recent_list,
             'max_count': RESULTS_MAX,
             'count': len(recent_list),
             'page': page,
             'allow_edit': access.edit_enabled(request.registry.settings),
           }
Example #8
0
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()
Example #9
0
File: bmarks.py Project: akn/Bookie
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