Beispiel #1
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),
    }
Beispiel #2
0
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,
           }
Beispiel #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),
           }
Beispiel #4
0
def tag_complete(request):
    """Complete a tag based on the given text

    :@param tag: GET string, tag=sqlalchemy
    :@param current: GET string of tags we already have python+database

    """
    params = request.GET

    if request.user:
        username = request.user.username
    else:
        username = None

    if 'current' in params and params['current'] != "":
        current_tags = params['current'].split()
    else:
        current_tags = None

    if 'tag' in params and params['tag']:
        tag = params['tag']

        tags = TagMgr.complete(tag, current=current_tags, username=username)
    else:
        tags = []

    # reset this for the payload join operation
    if current_tags is None:
        current_tags = []

    return {'current': ",".join(current_tags), 'tags': [t.name for t in tags]}
Beispiel #5
0
def tag_complete(request):
    """Complete a tag based on the given text

    :@param tag: GET string, tag=sqlalchemy
    :@param current: GET string of tags we already have python+database

    """
    params = request.GET
    username = request.user.username

    if 'current' in params and params['current'] != "":
        current_tags = params['current'].split()
    else:
        current_tags = None

    if 'tag' in params and params['tag']:
        tag = params['tag']

        tags = TagMgr.complete(tag,
                               current=current_tags,
                               username=username)

        # reset this for the payload join operation
        if current_tags is None:
            current_tags = []

    return {
        'current': ",".join(current_tags),
        'tags': [tag.name for tag in tags]
    }
Beispiel #6
0
def tags_complete(request):
    """Complete a tag based on the given text

    :@param tag: GET string, tag=sqlalchemy
    :@param current: GET string of tags we already have python+database

    """
    params = request.GET
    request.response.content_type = 'text/xml'

    if 'current' in params and params['current'] != "":
        current_tags = params['current'].split()
    else:
        current_tags = None

    LOG.debug('current_tags')
    LOG.debug(current_tags)

    if 'tag' in params and params['tag']:
        tag = params['tag']
        tags = TagMgr.complete(tag,
                               current=current_tags,
                               username=request.user.username)

        # we need to escape any html entities in things
        return {'tags': tags}
Beispiel #7
0
def tags_complete(request):
    """Complete a tag based on the given text

    :@param tag: GET string, tag=sqlalchemy
    :@param current: GET string of tags we already have python+database

    """
    params = request.GET
    request.response.content_type = 'text/xml'

    if 'current' in params and params['current'] != "":
        current_tags = params['current'].split()
    else:
        current_tags = None

    LOG.debug('current_tags')
    LOG.debug(current_tags)

    if 'tag' in params and params['tag']:
        tag = params['tag']
        tags = TagMgr.complete(tag,
                               current=current_tags,
                               username=request.user.username)

        # we need to escape any html entities in things
        return {'tags': tags}
Beispiel #8
0
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,
        }
Beispiel #9
0
    def run(bmark):
        """Update this bookmark to toread status"""
        if ToRead.read_tag not in bmark.tags:
            res = TagMgr.find(tags=[ToRead.read_tag])
            if res:
                bmark.tags[ToRead.read_tag] = res[0]

        return bmark
Beispiel #10
0
def tag_list(request):
    """Display a list of your tags"""
    tags_found = TagMgr.find()

    return {
        'tag_list': tags_found,
        'tag_count': len(tags_found),
    }
Beispiel #11
0
def tag_list(request):
    """Display a list of your tags"""
    tags_found = TagMgr.find()

    return {
        'tag_list': tags_found,
        'tag_count': len(tags_found),
    }
Beispiel #12
0
    def run(bmark):
        """Update this bookmark to toread status"""
        if ToRead.read_tag not in bmark.tags:
            res = TagMgr.find(tags=[ToRead.read_tag])
            if res:
                bmark.tags[ToRead.read_tag] = res[0]

        return bmark
Beispiel #13
0
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()
Beispiel #14
0
def tag_list(request):
    """Display a list of your tags"""
    rdict = request.matchdict
    username = rdict.get("username", None)

    tags_found = TagMgr.find(username=username)

    return {"tag_list": tags_found, "tag_count": len(tags_found), "username": username}
Beispiel #15
0
    def test_total_ct(self):
        """Verify that our total count method is working"""
        ct = 5
        for i in range(ct):
            t = Tag(gen_random_word(10))
            DBSession.add(t)

        ct = TagMgr.count()
        eq_(5, ct, 'We should have a total of 5: ' + str(ct))
Beispiel #16
0
    def test_total_ct(self):
        """Verify that our total count method is working"""
        ct = 5
        for i in range(ct):
            t = Tag(gen_random_word(10))
            DBSession.add(t)

        ct = TagMgr.count()
        eq_(5, ct, 'We should have a total of 5: ' + str(ct))
Beispiel #17
0
    def test_case_insensitive(self):
        """Suggestion does not care about case of the prefix."""
        # Generate demo tag into the system
        tags = [make_tag() for i in range(5)]
        [DBSession.add(t) for t in tags]

        test_str = tags[0].name[0:4].upper()
        suggestions = TagMgr.complete(test_str)
        ok_(tags[0] in suggestions,
            "The sample tag was found in the completion set")
Beispiel #18
0
    def test_case_insensitive(self):
        """Suggestion does not care about case of the prefix."""
        # Generate demo tag into the system
        tags = [make_tag() for i in range(5)]
        [DBSession.add(t) for t in tags]

        test_str = tags[0].name[0:4].upper()
        suggestions = TagMgr.complete(test_str)
        ok_(tags[0] in suggestions,
            "The sample tag was found in the completion set")
Beispiel #19
0
    def test_basic_complete(self):
        """Tags should provide completion options."""
        # Generate demo tag into the system
        tags = [make_tag() for i in range(5)]
        [DBSession.add(t) for t in tags]

        test_str = tags[0].name[0:2]
        suggestions = TagMgr.complete(test_str)

        ok_(tags[0] in suggestions,
            "The sample tag was found in the completion set")
Beispiel #20
0
    def test_basic_complete(self):
        """Tags should provide completion options."""
        # Generate demo tag into the system
        tags = [make_tag() for i in range(5)]
        [DBSession.add(t) for t in tags]

        test_str = tags[0].name[0:2]
        suggestions = TagMgr.complete(test_str)

        ok_(tags[0] in suggestions,
            "The sample tag was found in the completion set")
Beispiel #21
0
def tag_list(request):
    """Display a list of your tags"""
    rdict = request.matchdict
    username = rdict.get("username", None)

    tags_found = TagMgr.find(username=username)

    return {
        'tag_list': tags_found,
        'tag_count': len(tags_found),
        'username': username,
    }
Beispiel #22
0
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()
Beispiel #23
0
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),
               }
Beispiel #24
0
def _update_mark(mark, params):
    """Update the bookmark found with settings passed in"""
    mark.description = params.get('description', mark.description)
    mark.extended = params.get('extended', mark.extended)

    new_tag_str = params.get('tags', None)

    # if the only new tags are commands, then don't erase the
    # existing tags
    # we need to process any commands associated as well
    new_tags = TagMgr.from_string(new_tag_str)
    found_cmds = Commander.check_commands(new_tags)

    if new_tag_str and len(new_tags) == len(found_cmds):
        # the all the new tags are command tags, just tack them on
        # for processing, but don't touch existing tags
        for command_tag in new_tags.values():
            mark.tags[command_tag.name] = command_tag
    else:
        if new_tag_str:
            # in this case, rewrite the tags wit the new ones
            mark.update_tags(new_tag_str)

    return mark
Beispiel #25
0
def _update_mark(mark, params):
    """Update the bookmark found with settings passed in"""
    mark.description = params.get('description', mark.description)
    mark.extended = params.get('extended', mark.extended)

    new_tag_str = params.get('tags', None)

    # if the only new tags are commands, then don't erase the
    # existing tags
    # we need to process any commands associated as well
    new_tags = TagMgr.from_string(new_tag_str)
    found_cmds = Commander.check_commands(new_tags)

    if new_tag_str and len(new_tags) == len(found_cmds):
        # the all the new tags are command tags, just tack them on
        # for processing, but don't touch existing tags
        for command_tag in new_tags.values():
            mark.tags[command_tag.name] = command_tag
    else:
        if new_tag_str:
            # in this case, rewrite the tags wit the new ones
            mark.update_tags(new_tag_str)

    return mark
Beispiel #26
0
 def count_total_tags():
     """Count the total number of tags in the system"""
     total = TagMgr.count()
     stat = StatBookmark(attrib=TAG_CT, data=total)
     DBSession.add(stat)