Пример #1
0
    def special(self):
        LL = ListOfLinks(linkid=-1)
        LL.name = "Smart Keywords"
        LL.links = MYGLOBALS.g_db.getSpecialLinks()

        env.globals['MYGLOBALS.g_db'] = MYGLOBALS.g_db
        return env.get_template('list.html').render(L=LL, keyword="special")
Пример #2
0
    def default(self, *rest, **kwargs):
        self.redirectIfNotFullHostname()

        keyword = rest[0]
        rest = rest[1:]

        forceListDisplay = False
        # action = kwargs.get("action", "list")

        if keyword[0] == ".":  # force list page instead of redirect
            forceListDisplay = True
            keyword = keyword[1:]

        if rest:
            keyword += "/"
        elif forceListDisplay and cherrypy.request.path_info[-1] == "/":
            # allow go/keyword/ to redirect to go/keyword but go/.keyword/
            #  to go to the keyword/ index
            keyword += "/"

        # try it as a list
        try:
            ll = MYGLOBALS.g_db.getList(keyword, create=False)
        except InvalidKeyword as e:
            return self.notfound(str(e))

        if not ll:  # nonexistent list
            # check against all special cases
            matches = []
            for R in MYGLOBALS.g_db.regexes.values():
                matches.extend([(R, L, genL) for L, genL in R.matches(keyword)])

            if not matches:
                kw = tools.sanitary(keyword)
                if not kw:
                    return self.notfound("No match found for '%s'" % keyword)

                # serve up empty fake list
                return env.get_template('list.html').render(L=ListOfLinks(linkid=0), keyword=kw)
            elif len(matches) == 1:
                R, L, genL = matches[0]  # actual regex, generated link
                R.clicked()
                L.clicked()
                return self.redirect(tools.deampify(genL.url()))
            else:  # len(matches) > 1
                LL = ListOfLinks(linkid=-1)  # -1 means non-editable
                LL.links = [genL for R, L, genL in matches]
                return env.get_template('list.html').render(L=LL, keyword=keyword)

        listtarget = ll.getDefaultLink()

        if listtarget and not forceListDisplay:
            ll.clicked()
            listtarget.clicked()
            return self.redirect(tools.deampify(listtarget.url()))

        tmplList = env.get_template('list.html')
        return tmplList.render(L=ll, keyword=keyword)