def testQuery(wlib, querytxt, tags):
    tags,unknown = weblib.parseTags(wlib, tags)
    if unknown:
        print 'Ignore unknown tags', unknown

    result = query(wlib, querytxt, tags)

    for item, score in result:
        tags = [tag.name for tag in item.tags]
        print '  %s [%s] (%s)' % (unicode(item), score, ','.join(tags))
Пример #2
0
def queryWebLib(wfile, req, tag, querytxt):
    go_direct = req.param('submit') == '>'
    if querytxt.endswith('>'):
        querytxt = querytxt[:-1]
        go_direct = True

    wlib = store.getWeblib()
    tags, _ = weblib.parseTags(wlib, tag)

    # query
    result = query_wlib.query(wlib, querytxt, tags)

    # quick jump?
    if go_direct and result:
        top_item = result[0][0]
        #top_item = wlib.visit(top_item)
        response.redirect(wfile, top_item.url)
        return

    # category pane
    categoryList = _buildCategoryList(wlib)
    tag = tags and wlib.getTagByName(tags[-1]) or None

    # webitem pane
    webItems = []
    if querytxt:
        tags_matched = query_wlib.query_tags(wlib, querytxt, tags)
        for tag in tags_matched:
            node = WebItemTagNode(tag)
            node.suffix = '...'
            webItems.append(node)

    for item,_ in result:
        webItems.append(WebItemNode(item))

    renderer = WeblibRenderer(wfile)
    renderer.setLayoutParam(querytxt=querytxt)
    renderer.output(
        wlib.tags,
        None,
        wlib.getDefaultTag(),
        categoryList,
        webItems)
def main(argv):
    tags = None
    url = None
    querytxt = ''
    if len(argv) <= 1:
        pass
    elif argv[1] == '-a':
        testShowAll()
        sys.exit(0)
    elif argv[1] == '-h':
        print __doc__
        sys.exit(-1)
    elif argv[1] == '-q':
        querytxt = argv[2]
        del argv[:2]
    elif argv[1] == '-t':
        tags = argv[2]
        del argv[:2]
    elif argv[1] == '-u':
        url = argv[2]
        del argv[:2]

    from minds.weblib import store
    wlib = store.getWeblib()

    if tags:
        tags, unknown = weblib.parseTags(wlib, tags)
        positions = query_by_tag(wlib, tags[0])
        for pos in positions:
            pos.items.sort()
            print pos
            for i in pos.items:
                print '  ' + str(i)

    elif url:
        test_find_url(url)

    elif querytxt:
        testQuery(wlib, querytxt, '')

    else:
        pprint(queryRoot(wlib))
def doPost(wfile, req):
    wlib = store.getWeblib()
    entries = _buildEntries(req)
    checklist = _buildChecklist(req)
    errors = []

    # parse add tags
    tags_description = req.param('add_tags')
    if weblib.Tag.hasIllegalChar(tags_description.replace(',',' ')):
        errors.append('These characters are not allowed in tag name: ' + weblib.Tag.ILLEGAL_CHARACTERS)
        tags_description = ''

    # check for new tags and the create_tags flag
    _, unknown = weblib.parseTags(wlib, tags_description)
    if unknown and (not req.param('create_tags')):
        tags = u', '.join(unknown)
        errors.append('These tags are not previous used: ' + tags)
        tags_description = ''

    # note: validation should be done, new tags will be created here
    set_tags = weblib.makeTags(store.getStore(), tags_description)
    remove_tags = []

    # going through checklist, add to set_tags, delete_tags
    for tag, flag in checklist:
        if flag:
            if tag not in set_tags:
                set_tags.append(tag)
        else:
            remove_tags.append(tag)

    if errors:
        doShowForm(wfile, req, errors, checklist=checklist, new_tags=unknown)
        return

    log.debug('EditTags for %s entries set(%s) remove(%s).', len(entries), set_tags, remove_tags)
    wlib.editTags(entries, [], set_tags, remove_tags)
    store.getStore().refresh_when_needed()

    response.redirect(wfile, '/updateParent')
Пример #5
0
def queryWebLib(wfile, req, tag, sort, querytxt):
    go_direct = req.param('submit') == '>'
    if querytxt.endswith('>'):
        querytxt = querytxt[:-1]
        go_direct = True

    wlib = store.getWeblib()
    tags, _ = weblib.parseTags(wlib, tag)

    # query
    result = query_wlib.query(wlib, querytxt, tags)

    # quick jump?
    if go_direct and result:
        top_item = result[0][0]
        #top_item = wlib.visit(top_item)
        response.redirect(wfile, top_item.url)
        return

    # category pane
    categoryList = _buildCategoryList(wlib)
    tag = tags and wlib.getTagByName(tags[-1]) or None

    # upgrade_info
    upgrade_info = upgrade_checker.pollUpgradeInfo()

    # webitem pane
    webItems = []
    if querytxt:
        tags_matched = query_wlib.query_tags(wlib, querytxt, tags)
        for tag in tags_matched:
            node = WebItemTagNode(tag)
            node.suffix = '...'
            webItems.append(node)

    # sort result?
    col, order = SORT.parse_token(sort)
    if col == SORT.TITLE or col == SORT.DATE:
        lst = []
        for r in result:
            item = r[0]
            if col == SORT.TITLE:
                key = item.name.lower()
            else:
                key = item.created
            lst.append((key,r))
        lst.sort(reverse=(order==SORT.DESC))
        result = [r for _,r in lst]

    for item,_ in result:
        webItems.append(WebItemNode(item))

    # reconstuct the base url
    qs = urllib.quote_plus(querytxt.encode('utf8'))
    base_url = '/weblib?query=' + qs

    renderer = WeblibRenderer(wfile)
    if sort:
        renderer.cookie['weblib_sort'] = sort
    renderer.setLayoutParam(querytxt=querytxt)
    renderer.output(
        base_url,
        wlib.tags,
        None,
        wlib.getDefaultTag(),
        categoryList,
        upgrade_info,
        sort,
        webItems,
        )
 def _parseTags(self, req):
     """ Parse the 'tags' parameter. Check for exsiting and new tags. """
     wlib = store.getWeblib()
     tags_description = req.param('tags')
     self.item.tags, self.newTags = weblib.parseTags(wlib, tags_description)
     self.item.tags_description = tags_description