def from_path(self, request, path=None, lang=None): """ Resolve a request to an alias. returns a ``PageAlias`` object or None if the url matches no page at all. The aliasing system supports plain aliases (``/foo/bar``) as well as aliases containing GET parameters (like ``index.php?page=foo``). """ from pages.utils import normalize_url from pages.models import Page,PageAlias url = normalize_url(path) # §1: try with complete query string if ("QUERY_STRING" in request.META and request.META["QUERY_STRING"] != ""): url = url + '?' + request.META["QUERY_STRING"] try: alias = PageAlias.objects.get(url=url) return alias except PageAlias.DoesNotExist: pass # §2: try with path only url = normalize_url(path) try: alias = PageAlias.objects.get(url=url) return alias except PageAlias.DoesNotExist: pass # §3: not alias found, we give up return None
def from_path(self, request, path, lang): """ Resolve a request to an alias. returns a :class:`PageAlias <pages.models.PageAlias>` if the url matches no page at all. The aliasing system supports plain aliases (``/foo/bar``) as well as aliases containing GET parameters (like ``index.php?page=foo``). :param request: the request object :param path: the complete path to the page :param lang: not used """ from pages.models import PageAlias url = normalize_url(path) # §1: try with complete query string query = request.META.get('QUERY_STRING') if query: url = url + '?' + query try: alias = PageAlias.objects.get(url=url) return alias except PageAlias.DoesNotExist: pass # §2: try with path only url = normalize_url(path) try: alias = PageAlias.objects.get(url=url) return alias except PageAlias.DoesNotExist: pass # §3: not alias found, we give up return None
def save(self, *args, **kwargs): # normalize url self.url = normalize_url(self.url) super(PageAlias, self).save(*args, **kwargs)