Exemplo n.º 1
0
    def index(self, *args, **kwargs):
        """
			Default, SEO-Friendly fallback for view and list.

			:param args: The first argument - if provided - is interpreted as seoKey.
			:param kwargs: Used for the fallback list.
			:return: The rendered entity or list.
		"""
        if args and args[0]:
            # We probably have a Database or SEO-Key here
            seoKey = str(args[0]).lower()
            skel = self.viewSkel().all(_excludeFromAccessLog=True).filter(
                "viur.viurActiveSeoKeys =", seoKey).getSkel()
            if skel:
                db.currentDbAccessLog.get(set()).add(skel["key"])
                if not self.canView(skel):
                    raise errors.Forbidden()
                seoUrl = utils.seoUrlToEntry(self.moduleName, skel)
                # Check whether this is the current seo-key, otherwise redirect to it
                if currentRequest.get().request.path != seoUrl:
                    raise errors.Redirect(seoUrl, status=301)
                self.onView(skel)
                return self.render.view(skel)
        # This was unsuccessfully, we'll render a list instead
        if not kwargs:
            kwargs = self.getDefaultListParams()
        return self.list(kwargs)
Exemplo n.º 2
0
def seoUrlForEntry(render, *args, **kwargs):
	return utils.seoUrlToEntry(*args, **kwargs)