当前位置: 首页>>代码示例>>Python>>正文


Python Page.exists方法代码示例

本文整理汇总了Python中Sycamore.Page.Page.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Page.exists方法的具体用法?Python Page.exists怎么用?Python Page.exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sycamore.Page.Page的用法示例。


在下文中一共展示了Page.exists方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
        def process(self):
            if not self.query:
                return
            # processes the search
            enquire = xapian.Enquire(self.text_database)
            enquire.set_query(self.query)
            t0 = time.time()

            matches = self._get_matchset(enquire, self.text_database,
                                         self.p_start_loc, self.num_results+1)
            
            self.estimated_results = matches.get_matches_estimated()
            t1 = time.time()
            for match in matches:
                id = match[xapian.MSET_DOCUMENT].get_value(0)
                wiki_name = self.request.config.wiki_name
                if config.wiki_farm:
                    title, wiki_name = get_id(id)
                    # xapian uses utf-8
                    title = title.decode('utf-8')
                    wiki_name = wiki_name.decode('utf-8')
                else:
                    title = get_id(id).decode('utf-8')
                page = Page(title, self.request, wiki_name=wiki_name)
                if not page.exists():
                    continue
                percentage = match[xapian.MSET_PERCENT]
                data = page.get_raw_body()
                search_item = searchResult(title, data, percentage,
                                           page.page_name, wiki_name)
                self.text_results.append(search_item)
    
            enquire = xapian.Enquire(self.title_database)
            enquire.set_query(self.query)
            matches = self._get_matchset(enquire, self.text_database,
                                         self.t_start_loc, self.num_results+1)

            self.estimated_results += matches.get_matches_estimated()
            for match in matches:
                id = match[xapian.MSET_DOCUMENT].get_value(0)
                wiki_name = self.request.config.wiki_name
                if config.wiki_farm:
                    title, wiki_name = get_id(id)
                    # xapian uses utf-8
                    title = title.decode('utf-8')
                    wiki_name = wiki_name.decode('utf-8')
                else:
                    title = get_id(id).decode('utf-8')
                page = Page(title, self.request, wiki_name=wiki_name)
                if not page.exists():
                    continue
                percentage = match[xapian.MSET_PERCENT]
                data = page.page_name
                search_item = searchResult(title, data, percentage,
                                           page.page_name, wiki_name)
                self.title_results.append(search_item)
开发者ID:ivanov,项目名称:sycamore,代码行数:58,代码来源:search.py

示例2: _consider_talk_link

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
    def _consider_talk_link(self, links):
        if not self.request.config.talk_pages:
            return links
        lower_links = [ link.lower() for link in links ]
        from Sycamore.Page import Page
        pagename = self.key
        page = Page(pagename, self.request)
        linkto_name = None
        if page.isTalkPage():
            article_page = Page(wikiutil.talk_to_article_pagename(pagename),
                                self.request)
            article_pagename = article_page.proper_name()
            if article_pagename.lower() not in lower_links:
                links.append(article_pagename)
        else:
            talk_pagename = wikiutil.article_to_talk_pagename(pagename)
            talk_page = Page(talk_pagename, self.request)

            # add dependency so that editing/creating the talk page
            # has an affect on the article page's links
            dependency(pagename, talk_pagename.lower(), self.request)

            if talk_page.exists():
                talk_pagename = talk_page.proper_name()
                if talk_pagename.lower() not in lower_links:
                    links.append(talk_pagename)

        return links
开发者ID:ivanov,项目名称:sycamore,代码行数:30,代码来源:caching.py

示例3: testExist

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
 def testExist(self):
     """Tests if Page().exists() is working correctly."""
     from Sycamore.Page import Page
     cannot_possibly_exist = make_impossible_pages(self.request, 200)
     for pagename in cannot_possibly_exist:
         page = Page(pagename, self.request)
         self.assertFalse(page.exists())
开发者ID:ivanov,项目名称:sycamore,代码行数:9,代码来源:page.py

示例4: execute

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
def execute(macro, args, formatter):
    if not formatter:
        formatter = macro.formatter
    # get number of wanted links        
    try:
        links = max(int(args), 1)
    except StandardError:
        links = 1

    # select the pages from the page list
    random_list = wikiutil.getRandomPages(macro.request)
    pages = []
    while len(pages) < links and random_list:
        pagename = random.choice(random_list)
        page = Page(pagename, macro.request)
        if macro.request.user.may.read(page) and page.exists() and not page.isRedirect():
		if page.proper_name()[0:6] != 'Users/' and page.proper_name()[-5:] != '/Talk':
	            pages.append(page)

    # return a single page link
    if links == 1:
        return pages[0].link_to()

    # return a list of page links
    pages.sort()
    result = [macro.formatter.bullet_list(1)]
    for page in pages:
        result.append("%s%s%s" %
                      (macro.formatter.listitem(1), page.link_to(),
                       macro.formatter.listitem(0)))
    result.append(macro.formatter.bullet_list(0))

    return ''.join(result)
开发者ID:rtucker,项目名称:sycamore,代码行数:35,代码来源:randompage.py

示例5: rebuild_page_cache

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
 def rebuild_page_cache():
     """
     Rebuilds the page cache.
     """
     if not request.generating_cache and not request.previewing_page:
         from Sycamore import caching
         from Sycamore.Page import Page
         page = Page(dict['pagename'], request)
         if page.exists():
             page.buildCache()
开发者ID:ivanov,项目名称:sycamore,代码行数:12,代码来源:wikidb.py

示例6: do_user_browser

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
def do_user_browser(request):
    """ Browser for SystemAdmin macro. """
    from Sycamore.util.dataset import TupleDataset, Column
    from Sycamore.Page import Page
    _ = request.getText

    data = TupleDataset()
    data.columns = [
        Column('id', label=('ID'), align='right'),
        Column('name', label=('Username')),
        Column('email', label=('Email')),
        Column('action', label=_('Action')),
    ]

    # Iterate over users
    for uid in user.getUserList(self.request.cursor):
        account = user.User(request, uid)

        userhomepage = Page(account.name, self.request)
        if userhomepage.exists():
            namelink = userhomepage.link_to()
        else:
            namelink = account.name

        data.addRow((
            request.formatter.code(1) + uid + request.formatter.code(0),
            request.formatter.rawHTML(namelink),
            request.formatter.url('mailto:' + account.email, account.email,
                                  'external', pretty_url=1, unescaped=1),
            '',
        ))

    if data:
        from Sycamore.widget.browser import DataBrowserWidget

        browser = DataBrowserWidget(request)
        browser.setData(data)
        return browser.toHTML()

    # No data
    return ''
开发者ID:rtucker,项目名称:sycamore,代码行数:43,代码来源:userform.py

示例7: talkicon

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
    def talkicon(self, d):
        if not self.request.config.talk_pages:
            return ''

        if d['page'].isTalkPage():
           article_name = wikiutil.talk_to_article_pagename(d['page_name'])

           icon = self.get_editable_icon('articleicon.png', 'Article')
           
           return ('<td class="pageIcon"><span id="articleIcon">'
                   '%s</span></td>' %
                   (wikiutil.link_tag_explicit(
                       'style="text-decoration: none;"', self.request,
                       wikiutil.quoteWikiname(article_name), icon,
                       script_name=d['script_name'])))
        else:
            talk_page = Page(wikiutil.article_to_talk_pagename(d['page_name']),
                             self.request)

            icon = self.get_editable_icon('talkicon.png', 'Talk')

            if talk_page.exists():
                return ('<td class="pageIcon"><span id="talkIcon">'
                        '%s</span></td>' %
                        (wikiutil.link_tag_explicit(
                            'style="text-decoration: none;"', self.request,
                            wikiutil.quoteWikiname(d['page_name'])+'/Talk',
                            icon, script_name=d['script_name'])))
            else:
                # if the viewer can't edit the talk page, let's spare them
                # from looking at a useless link to an empty page:
                if not self.request.user.may.edit(talk_page):
                    return ''
                return ('<td class="pageIcon"><span id="talkIcon">'
                        '%s</span></td>' %
                        (wikiutil.link_tag_explicit(
                            'class="tinyNonexistent"', self.request,
                            wikiutil.quoteWikiname(d['page_name'])+'/Talk',
                            icon, script_name=d['script_name'])))
开发者ID:rtucker,项目名称:sycamore,代码行数:41,代码来源:eggheadbeta.py

示例8: rename_old_user_pages

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
def rename_old_user_pages(request):
    from Sycamore import user
    for wikiname in wikiutil.getWikiList(request):
        request.switch_wiki(wikiname)
        user_pages = _get_user_pages(request) 
        num_user_pages = len(user_pages)
        n = 0
        for page in user_pages:
            new_user_pagename = config.user_page_prefix + page.proper_name()
            new_user_page = Page(new_user_pagename, request)
            if new_user_page.exists():
                # something crazzzzy is going on
                continue 
            old_pagename_propercased = page.proper_name()
            d = {'new_name': new_user_pagename.lower(), 'new_propercased_name': new_user_pagename,
                'old_pagename': page.page_name, 'wiki_id': request.config.wiki_id,
                'wiki_name': request.config.wiki_name, 'latest_ed_time': page.mtime(),
                'old_propercased_name': page.proper_name()}

            print page.page_name, '->', new_user_pagename
            _user_page_move(request, copy(d))
            _user_page_redirect(request, d)
            n += 1
开发者ID:ivanov,项目名称:sycamore,代码行数:25,代码来源:wikis.py

示例9: _subpages

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
    def _subpages(self):
        possible_subpages = self.pagename.split('/') 
        max_number_possible = len(possible_subpages)
        n = 1
        pagelinks = []
        pagenames_queue = []
        while n <= max_number_possible:
            pagename = possible_subpages[-n]
            parent_pagename = '/'.join(possible_subpages[:-n])
            parent_page = Page(parent_pagename, self.request)
            pagenames_queue.append(pagename)
            if parent_page.exists() or parent_page.page_name == 'users':
                pagenames_queue.reverse()
                display_name = '/'.join(pagenames_queue)
                pagelinks.append(
                    ('%s/%s' % (parent_pagename, display_name), display_name))
                pagenames_queue = []

            n += 1

        pagenames_queue.reverse()
        pagelinks.append(('/'.join(pagenames_queue), '/'.join(pagenames_queue)))
        pagelinks.reverse()
        return pagelinks
开发者ID:ivanov,项目名称:sycamore,代码行数:26,代码来源:subpagelinks.py

示例10: execute

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
def execute(macro, args, formatter=None):
    formatter = macro.formatter
    pages = []
    debug = []
    if not args:
        # use the current page
        pages.append(macro.formatter.page)
    else:
        pagenames = args.split(',')
        do_union = False
        if pagenames[0] == 'or':
            do_union = True
            del(pagenames[0])
        elif pagenames[0] == 'and':
            del(pagenames[0])

        lastpage = []
        for pagename in pagenames:
            curpage = Page(pagename, macro.request)
            if not curpage.exists():
                # The page doesn't exist.  Either someone's making
                # stuff up, or there's a comma in the page name.
                debug.append('<!-- "%s" does not exist -->' % curpage.page_name)
                if lastpage:
                    # We have something to try from last time.
                    lastpage.append(pagename)
                    debug.append('<!-- trying "%s" -->' % ','.join(lastpage))
                    curpage = Page(','.join(lastpage), macro.request)
                    if curpage.exists():
                        # awesome!
                        debug.append('<!-- "%s" does exist -->' % curpage.page_name)
                        lastpage = []
                        pages.append(curpage)
                else:
                    debug.append('<!-- "%s" appended to rescanner -->' % pagename)
                    lastpage.append(pagename)
            else:
                debug.append('<!-- "%s" does exist -->' % curpage.page_name)
                lastpage = []
                pages.append(curpage)

    # iterate through the pages, find links
    linkset = None
    for page in pages:
        links_here = page.getPageLinksTo()
        pages_deco = [(pagename.lower(), pagename) for pagename in links_here]
        links_here = set([word for lower_word, word in pages_deco])
        if not linkset:
            # first time through
            linkset = links_here.copy()
        elif do_union:
            # OR the list
            linkset = linkset.union(links_here)
        else:
            # AND the list
            linkset = linkset.intersection(links_here)
        debug.append('<!-- DEBUG: "%s" yielded %i links -->' % (page.page_name, len(links_here)))

    text = []
    if linkset:
        text.append(formatter.bullet_list(1))
        for link in sorted(linkset):
            text.append('%s%s%s' % (formatter.listitem(1),
                                    formatter.pagelink(link, generated=True),
                                    formatter.listitem(0)))
        text.append(formatter.bullet_list(0))

    text.extend(debug)
    
    return ''.join(text)
开发者ID:rtucker,项目名称:sycamore,代码行数:72,代码来源:linkshere.py

示例11: checkSpelling

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
def checkSpelling(page, request, own_form=1):
    """
    Do spell checking, return a tuple with the result.
    """
    _ = request.getText

    # first check to see if we we're called with a "newwords" parameter
    if request.form.has_key('button_newwords'):
        _addLocalWords(request)

    # load words
    wordsdict = _loadDict(request)

    localwords = {}
    lsw_page = Page(request.config.page_local_spelling_words, request)
    if lsw_page.exists():
        _loadWordsString(request, localwords, lsw_page.get_raw_body())

    # init status vars & load page
    badwords = {}
    text = page.get_raw_body()

    # checker regex and matching substitute function
    word_re = re.compile(r'([%s]?[%s]+)' % (
        config.upperletters, config.lowerletters))

    def checkword(match, wordsdict=wordsdict, badwords=badwords,
                  localwords=localwords, num_re=re.compile(r'^\d+$')):
        word = match.group(1)
        if len(word) == 1:
            return ""
        if not (wordsdict.has_key(word) or
                wordsdict.has_key(word.lower()) or
                localwords.has_key(word) or
                localwords.has_key(word.lower()) ):
            if not num_re.match(word):
                badwords[word] = 1
        return ""

    # do the checking
    for line in text.encode('utf-8').split('\n'):
        if line == '' or line[0] == '#': continue
        word_re.sub(checkword, line)

    if badwords:
        badwords = badwords.keys()
        badwords.sort(lambda x,y: cmp(x.lower(), y.lower()))

        # build regex recognizing the bad words
        badwords_re = r'(^|(?<!\w))(%s)(?!\w)'
        badwords_re = badwords_re % ("|".join(map(re.escape, badwords)),)
        # XXX UNICODE re.UNICODE !?
        badwords_re = re.compile(badwords_re)

        lsw_msg = ''
        if localwords:
            lsw_msg = ' ' + _('(including %(localwords)d %(pagelink)s)') % {
                'localwords': len(localwords), 'pagelink': lsw_page.link_to()}
        msg = _('The following %(badwords)d words could not be found '
                'in the dictionary of '
                '%(totalwords)d words%(localwords)s and are '
                'highlighted below:') % {
            'badwords': len(badwords),
            'totalwords': len(wordsdict)+len(localwords),
            'localwords': lsw_msg} + "<br>"

        # figure out what this action is called
        action_name = os.path.splitext(os.path.basename(__file__))[0]

        # add a form containing the bad words
        if own_form:
            msg = msg + (
                '<form method="POST" action="%s">'
                '<input type="hidden" name="action" value="%s">'
                % (page.url(request), action_name,))
        checkbox = ('<input type="checkbox" name="newwords" '
                           'value="%(word)s">%(word)s&nbsp;&nbsp;')
        msg = msg + (
            " ".join(map(
                lambda w, cb=checkbox: cb % {'word': wikiutil.escape(w),},
                badwords)) +
            '<p><input type="submit" name="button_newwords" value="%s"></p>' %
                _('Add checked words to dictionary')
        )
        if own_form:
            msg = msg + '</form>'
    else:
        badwords_re = None
        msg = _("No spelling errors found!")

    return badwords, badwords_re, msg
开发者ID:ivanov,项目名称:sycamore,代码行数:93,代码来源:SpellCheck.py

示例12: get_group_members

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import exists [as 别名]
  group = wikiacl.Group(groupname, req)
  groupdict = get_group_members(groupname, req)
  group.update(groupdict)
  group.save()

print "  ", admin_group, "->", 'Admin'
group = wikiacl.Group('Admin', req)
groupdict = get_group_members(admin_group, req)
group.update(groupdict)
group.save()

print "  ", banned_group, "->", 'Banned'
group = wikiacl.Group('Banned', req)
groupdict = get_group_members(banned_group, req)
group.update(groupdict)
group.save()

# note on group page that this is not how it's defined any more
for groupname in defined_user_groups + [admin_group, banned_group]:
    p = Page(groupname, req)
    if p.exists():
       new_body = p.get_raw_body() + '\n\n' + group_changed_message
       p.set_raw_body(new_body)
       req.cursor.execute("UPDATE curPages set text=%(new_body)s where name=%(pagename)s and wiki_id=%(wiki_id)s", {'new_body':new_body, 'pagename':p.page_name, 'wiki_id':req.config.wiki_id}, isWrite=True)
       req.cursor.execute("UPDATE allPages set text=%(new_body)s where name=%(pagename)s and editTime=%(mtime)s and wiki_id=%(wiki_id)s", {'new_body':new_body, 'pagename':p.page_name, 'mtime':p.mtime(), 'wiki_id':req.config.wiki_id}, isWrite=True)
       p.buildCache()

 
req.db_disconnect()
print "..Done!"
开发者ID:ivanov,项目名称:sycamore,代码行数:32,代码来源:2006_08_30_acl.py


注:本文中的Sycamore.Page.Page.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。