Пример #1
0
    def renderWebItem(self, node, item, headerTemplate):
        i, webItemNode = item
        node.atts['class'] = i % 2 and 'altrow' or ''

        if isinstance(webItemNode, WebItemNode):
            webitem = webItemNode.webitem
            node = node.placeHolder
            node.checkbox.atts['name'] = str(webitem.id)
            node.itemDescription.content = unicode(webitem)
            if util.isFileURL(webitem.url):
                href = 'javascript:open_url(%s,"%s")' % (webitem.id, webitem.url)
                node.itemDescription.atts['href'] = href
            else:
                node.itemDescription.atts['href'] = webitem.url
            node.itemDescription.atts['title'] = '%s %s' % (webitem.modified, webitem.description)
            node.itemTag.tag.repeat(self.renderWebItemTag, webitem.tags)
            node.edit.atts['href'] %= webitem.id
            node.delete.atts['href'] = '%s/%s?method=delete' % (request.WEBLIB_URL, webitem.id)
#            if webitem.fetched:
#                node.cache.atts['href'] = '%s/%s/snapshotFrame' % (request.WEBLIB_URL, webitem.id)
#                node.cache.content = webitem.fetched
#            else:
#                node.cache.atts['href'] = '%s/%s/snapshot/get' % (request.WEBLIB_URL, webitem.id)
#                node.cache.content = 'download'
        else:
            tag = webItemNode.tag
            node.placeHolder = headerTemplate
            node.placeHolder.prefix.content = webItemNode.prefix
            node.placeHolder.itemHeader.content = unicode(tag) + webItemNode.suffix
            node.placeHolder.itemHeader.atts['href'] = request.tag_url([tag])
Пример #2
0
    def render(self, node,
        tags,
        selectedTag,
        defaultTag,
        categoryList,
        webItems,
        ):
        """
        @param tags - list of all tags
        @param selectedTag - tag selected or None
        @param defaultTag - a Tag (e.g. inbox)
        @param webItems - list of WebItemNode of WebItemTagNode
        """

        lSelectedTagName = selectedTag and selectedTag.name.lower() or ''

        # ------------------------------------------------------------------------
        # tag list
        lst = [(tag.name.lower(), tag.name, tag.id) for tag in tags]
        lst = [(name,id) for _,name,id in sorted(lst)]
        lst = [('',None)] + lst
        node.tagListForm.atts['action'] = selectedTag and '/weblib/@%s' % selectedTag.id or ''
        node.tagListForm.tag.repeat(self.renderTag, lst, lSelectedTagName)


        # ------------------------------------------------------------------------
        # default Tag
        node.defaultTag.atts['href'] = request.tag_url([defaultTag])
        node.defaultTag.content = unicode(defaultTag)
        if defaultTag.match(selectedTag):
            node.defaultTag.atts['class'] = 'highlight'
# Actually need to make sure it is not doing search
#        if not lTagSelected:
#            node.rootTag.atts['class'] = 'highlight'

        # category
        node.catList.repeat(self.renderCatItem, categoryList, lSelectedTagName)

        # ------------------------------------------------------------------------
        # Matching message
        count = sum(1 for item in webItems if isinstance(item, WebItemNode))
        node.found_msg.count.content = str(count)
        from minds import search_engine
        if search_engine.getEngines():
            node.found_msg.search_engine.engine.repeat(self.renderSearchEngine, search_engine.getEngines())
            node.found_msg.search_engine.querytxt.content = self.querytxt
        else:
            node.found_msg.search_engine.omit()

        if not webItems:
            node.web_items.omit()
            return

        # ------------------------------------------------------------------------
        # webitems
        headerTemplate = node.web_items.headerTemplateHolder.headerTemplate
        # headerTemplateHolder is only a holder for headerTemplate, hide it
        node.web_items.headerTemplateHolder.omit()

        node.web_items.webItem.repeat(self.renderWebItem, enumerate(webItems), headerTemplate)
Пример #3
0
def main(rfile, wfile, env):
    wlib = store.getWeblib()

    req = request.WeblibRequest(rfile, env)
    log.debug(unicode(req))
    path = req.path

    if req.rid:
        # rid based (note rid maybe -1)
        if path and path.startswith('go;'):
            doGoResource(wfile, req)
        elif path and path == 'url':
            doLaunchURL(wfile, req)
        elif path and path.startswith('snapshot'):
            weblibSnapshot.main(wfile, env, req.method, req.form, req.rid, path)
        elif path == 'form':
            doWeblibForm(wfile, req)
        else:
            # show form by default
            doWeblibForm(wfile, req)

    elif req.tid:
        doweblibTagForm(wfile, req)

    else:
        if path == 'load':
            doLoad(wfile, req)
        elif path == 'save':
            doSave(wfile, req)
        else:
            # query
            querytxt = req.param('query')
            tag = req.param('tag')

            # redirect to default tag (if it is defined)
            if not ('tag' in req.form or querytxt):
                dt = wlib.getDefaultTag()
                if dt:
                    url = request.tag_url([dt])
                    response.redirect(wfile, url)
                    return

#            if req.param('action') == 'cancel':
#                response.redirect(wfile, request.WEBLIB_URL)

            if tag:
                queryTag(wfile, req, tag)
            elif querytxt:
                queryWebLib(wfile, req, tag, querytxt)
            else:
                queryRoot(wfile, req)
Пример #4
0
 def renderSubCat(self, node, catNode, lSelectedTagName):
     if catNode == CategoryNode.BEGIN_HIGHLIGHT:
         node.omittags()
         node.link.omittags()
         node.link.raw="<span class='highlight'>"
     elif catNode == CategoryNode.END_HIGHLIGHT:
         node.omittags()
         node.link.omittags()
         node.link.raw='</span>'
     else:
         if catNode.level > 1:
             node.atts['class'] = 'SubCat2'
         node.link.content = catNode.tagName + (catNode.comma and ',' or '')
         node.link.atts['href'] = request.tag_url(catNode.tagName)
         if  catNode.tagName.lower() == lSelectedTagName:
             node.link.atts['class'] = 'highlight'
Пример #5
0
 def renderCatItem(self, node, item, lSelectedTagName):
     catNode, subcats = item
     isCurrent = catNode.tagName.lower() == lSelectedTagName
     iscollapse = not isCurrent and catNode.tag and ('c' in catNode.tag.flags)
     node.toggleSwitch.atts['id'] = '@%s' % catNode.id
     node.toggleSwitch.content = iscollapse and '+' or '-'
     node.link.content = catNode.tagName
     if catNode.id > 0:
         node.link.atts['href'] = request.tag_url(catNode.tagName)
         if isCurrent:
             node.atts['class'] = 'highlight'
     else:
         # otherwise it is a pseudo tag
         del node.link.atts['href']
     node.subcat.atts['class'] =  iscollapse and 'subcategoriesCollapsed'  or 'subcategories'
     node.subcat.catItem.repeat(self.renderSubCat, subcats, lSelectedTagName)
Пример #6
0
def queryTag(wfile, req, nameOrId, sort):
    wlib = store.getWeblib()

    tag = weblib.parseTag(wlib, nameOrId)
    tagName = tag and tag.name or ''

    # Note: URL is expected to have valid tag parameter. If it turns up
    # nothing, one possibility is user has entered an invalid URL
    # manually. In that case the query below should turn out empty
    # result. We choose not go for the alternative or redirecting user
    # to / or inbox because it seems even more confusing.

    # category pane
    categoryList = _buildCategoryList(wlib, tagName)

    # upgrade_info
    upgrade_info = upgrade_checker.pollUpgradeInfo()

    # webitem pane
    if tag:
        webItems = _query_by_tag(wlib, tag, sort)
    else:
        # TODO: HACK!!!
        # Create a fake tag to fill something in the result
        # Seems WeblibRenderer() is OK with this
        fakeTagNode = WebItemTagNode(nameOrId)
        webItems = [fakeTagNode]

    renderer = WeblibRenderer(wfile)
    if tag:
        renderer.cookie['weblib_tag'] = '@%s' % tag.id
    if sort:
        renderer.cookie['weblib_sort'] = sort
    renderer.setLayoutParam(None)
    renderer.output(
        request.tag_url(nameOrId),
        wlib.tags,
        tag,
        wlib.getDefaultTag(),
        categoryList,
        upgrade_info,
        sort,
        webItems,
        )
Пример #7
0
def doQuery(wfile, req):
    wlib = store.getWeblib()
    querytxt = req.param('query')
    tag = req.param('tag')
    sort = _get_sort_preference(req)
    # No tag specified? Use fallback: 1. cookie, 2. default tag
    if not ('tag' in req.form or querytxt):
        def_tag = _tag_from_cookie(req) or wlib.getDefaultTag()
        if def_tag:
            url = request.tag_url([def_tag])
            if sort:
                url = '%s&sort=%s' % (url, sort)
            response.redirect(wfile, url)
            return

    if tag:
        queryTag(wfile, req, tag, sort)
    elif querytxt:
        queryWebLib(wfile, req, tag, sort, querytxt)
    else:
        queryRoot(wfile, req, sort)
Пример #8
0
 def renderWebItemTag(self, node, tag):
     node.content = unicode(tag)
     node.atts['href'] = request.tag_url([tag])
Пример #9
0
    def render(self, node,
        base_url,
        tags,
        selectedTag,
        defaultTag,
        categoryList,
        upgrade_info,
        sort,
        webItems,
        ):
        """
        @param base_url - base URL that invoke this page (without the sort parameter)
        @param tags - list of all tags
        @param selectedTag - tag selected or None
        @param defaultTag - a Tag (e.g. inbox)
        @param webItems - sequence of intermixed WebItemNode and WebItemTagNode
        """

        lSelectedTagName = selectedTag and selectedTag.name.lower() or ''

        # ------------------------------------------------------------------------
        # tag list
        lst = [(tag.name.lower(), tag.name, tag.id) for tag in tags]
        lst = [(name,id) for _,name,id in sorted(lst)]
        lst = [('',None)] + lst
        node.tagListForm.atts['action'] = selectedTag and '/weblib/@%s' % selectedTag.id or ''
        node.tagListForm.tag.repeat(self.renderTag, lst, lSelectedTagName)


        # ------------------------------------------------------------------------
        # default Tag
        node.defaultTag.atts['href'] = request.tag_url([defaultTag])
        node.defaultTag.content = unicode(defaultTag)
        if defaultTag.match(selectedTag):
            node.defaultTag.atts['class'] = 'highlight'
# Actually need to make sure it is not doing search
#        if not lTagSelected:
#            node.rootTag.atts['class'] = 'highlight'

        # category
        node.catList.repeat(self.renderCatItem, categoryList, lSelectedTagName)

        # ------------------------------------------------------------------------
        # upgrade info
        if not upgrade_info:
            node.upgrade_notification.omit()
        else:
            node.upgrade_notification.link.atts['href']     = upgrade_info.url
            node.upgrade_notification.link.title.content    = upgrade_info.title
            node.upgrade_notification.link.summary.content  = upgrade_info.summary

        # ------------------------------------------------------------------------
        # Matching message
        count = sum(1 for item in webItems if isinstance(item, WebItemNode))
        node.found_msg.count.content = str(count)
        from minds import search_engine
        if search_engine.getEngines():
            node.found_msg.search_engine.engine.repeat(self.renderSearchEngine, search_engine.getEngines())
            node.found_msg.search_engine.querytxt.content = self.querytxt
        else:
            node.found_msg.search_engine.omit()

        if not webItems:
            node.web_items.omit()
            return

        # ------------------------------------------------------------------------
        # webitems Heading
        h = node.web_items.heading
        if '?' in base_url:
            s_url = base_url + '&sort='
        else:
            s_url = base_url + '?sort='

        if sort == SORT.TITLE_ASC:
            h.title.icon.atts['src'] = '/img/arrowUp.gif'
            h.title.atts['href'] = s_url + SORT.TITLE_DESC
        elif sort == SORT.TITLE_DESC:
            h.title.icon.atts['src'] = '/img/arrowDown.gif'
            h.title.atts['href'] = s_url + SORT.TITLE_ASC
        else:
            h.title.icon.omit();
            h.title.atts['href'] = s_url + SORT.TITLE_ASC

        if sort == SORT.TAG_ASC:
            h.tag.icon.atts['src'] = '/img/arrowUp.gif'
            h.tag.atts['href'] = s_url + SORT.TAG_ASC    # tag is only ordered one way
        elif sort == SORT.TAG_DESC:
            h.tag.icon.atts['src'] = '/img/arrowDown.gif'
            h.tag.atts['href'] = s_url + SORT.TAG_ASC
        else:
            h.tag.icon.omit();
            h.tag.atts['href'] = s_url + SORT.TAG_ASC

        if sort == SORT.DATE_ASC:
            h.date.icon.atts['src'] = '/img/arrowUp.gif'
            h.date.atts['href'] = s_url + SORT.DATE_DESC
        elif sort == SORT.DATE_DESC:
            h.date.icon.atts['src'] = '/img/arrowDown.gif'
            h.date.atts['href'] = s_url + SORT.DATE_ASC
        else:
            h.date.icon.omit();
            h.date.atts['href'] = s_url + SORT.DATE_ASC

        # ------------------------------------------------------------------------
        # webitems
        headerTemplate = node.web_items.headerTemplateHolder.headerTemplate
        # headerTemplateHolder is only a holder for headerTemplate, hide it
        node.web_items.headerTemplateHolder.omit()

        node.web_items.webItem.repeat(self.renderWebItem, enumerate(webItems), headerTemplate)