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


Python Helper.resolveTemplatePath方法代码示例

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


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

示例1: BasePage

# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import resolveTemplatePath [as 别名]
class BasePage(webapp2.RequestHandler):
    def __init__(self, request, response):
        self.initialize(request, response)
        self.helper = Helper()
        self._siteInformationRepository = SiteInformationRepository()
        self._sharkAttackRepository = SharkAttackRepository()
        self._pageTemplate = "main.html"
        self._host = os.environ.get("HTTP_HOST")
        self._urlScheme = os.environ.get("wsgi.url_scheme")
        self._path = os.environ.get("PATH_INFO")
        self._fullUrl = "%s://%s%s" % (self._urlScheme, self._host, self._path)
        self._isSiteMaintenancePage = False

    def isGsaf(self):
        return self.__class__.__name__.startswith("Gsaf")

    def get(self, *args, **kwargs):
        self.respond(*args, **kwargs)

    def head(self, *args, **kwargs):
        self.respond(*args, **kwargs)

    def respond(self, *args, **kwargs):
        siteInfo = self._siteInformationRepository.get()
        if siteInfo.status == SiteInformation.STATUS_OFFLINE and not self._isSiteMaintenancePage:
            self.response.status = "307 Temporary Redirect"
            self.response.headers["Location"] = "/site-maintenance?%s" % urllib.urlencode({ "referrer": self._path })
            return
        else:
            try:
                pageDict = self.handle(*args)
            except PageNotFoundException as nfe:
                if nfe.correctPath is not None:
                    self.response.status = "301 Moved Permanently"
                    self.response.headers["Location"] = nfe.correctPath
                else:
                    ErrorHandlers.generate404(self.request, self.response, 404)
                return

        template_values = {
            "title": "Shark Attack Data",
            "subtemplate": self.resolveTemplatePath("basepage.html"),
            "show_social_media_buttons": True,
            "og_image": "%s://%s/assets/images/Sharks-1920-1200.jpg" % (self._urlScheme, self._host),
            "meta_description": Constants.SiteDescription,
            "full_url": self._fullUrl
            }
        
        for key, value in pageDict.iteritems():
            template_values[key] = value

        template = JINJA_ENVIRONMENT.get_template(self.resolveTemplatePath(self._pageTemplate))
        self.response.write(template.render(template_values))

    def getBreadcrumbData(self, node):
        retval = []
        firstRun = True
        site = ""
        if self.isGsaf():
            site = "gsaf"
        while node is not None:
            if firstRun:
                if node._get_kind() == "SharkAttack":
                    retval.append({ "name": node.key.id(), "url": "" })
                else:
                    retval.append({ "name": node.name, "url": "" })
            else:
                retval.append({ "name": node.name, "url": self.helper.getUrlForNode(site, node) })
            firstRun = False
            parentKey = node.key.parent()
            if parentKey is None:
                node = None
            else:
                node = parentKey.get()

        retval.append({ "name": "Countries", "url": "" if firstRun else self.helper.getUrlForNode(site, None) })

        retval.reverse()
        return retval

    def resolveTemplatePath(self, relativePath):
        return self.helper.resolveTemplatePath(relativePath, self.isGsaf())
开发者ID:ikarajas,项目名称:sharkattackdata,代码行数:84,代码来源:basepage.py


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