def _new_route(self, request, path_components):
    """
    Rewrite route method in order to handle languages fallbacks
    """
    # copied from wagtail/contrib/wagtailroutablepage/models.py mixin ##
    # Override route when Page is also RoutablePage
    if isinstance(self, RoutablePageMixin):
        if self.live:
            try:
                path = '/'
                if path_components:
                    path += '/'.join(path_components) + '/'

                view, args, kwargs = self.resolve_subpage(path)
                return RouteResult(self, args=(view, args, kwargs))
            except Http404:
                pass

    if path_components:
        # request is for a child of this page
        child_slug = path_components[0]
        remaining_components = path_components[1:]

        subpages = self.get_children()
        for page in subpages:
            if page.slug == child_slug:
                return page.specific.route(request, remaining_components)
        raise Http404

    else:
        # request is for this very page
        if self.live:
            return RouteResult(self)
        else:
            raise Http404
Exemple #2
0
    def route(self, request, path_components):
        if path_components:
            # Request is for a child of this page.
            child_slug = path_components[0]
            remaining_components = path_components[1:]

            try:
                subpage = self.get_children().get(slug=child_slug)
            except Page.DoesNotExist:
                raise Http404

            return subpage.specific.route(request, remaining_components)

        else:
            # Request is for this very page.
            # If we're on the production site, make sure the version of the page
            # displayed is the latest version that has `live` set to True for
            # the live site or `shared` set to True for the staging site.
            staging_hostname = os.environ.get('STAGING_HOSTNAME')
            revisions = self.revisions.all().order_by('-created_at')
            for revision in revisions:
                page_version = json.loads(revision.content_json)
                if request.site.hostname != staging_hostname:
                    if page_version['live']:
                        return RouteResult(revision.as_page_object())
                else:
                    if page_version['shared']:
                        return RouteResult(revision.as_page_object())
            raise Http404
Exemple #3
0
 def route(self, request, path_components):
     if path_components:
         return RouteResult(self,
                            kwargs={'path_components': path_components})
     else:
         if self.live:
             return RouteResult(self)
         else:
             raise Http404
 def route(self, request, components):
     # see http://docs.wagtail.io/en/latest/reference/pages/model_recipes.html
     if components:
         # tell Wagtail to call self.serve() with an additional kwargs
         return RouteResult(self, kwargs=self._parsePath(components))
     else:
         if self.live:
             # tell Wagtail to call self.serve() with no further args
             return RouteResult(self)
         else:
             raise Http404
Exemple #5
0
    def route(self, request, path_components):
        # If this page is not published, raise 404 error
        if not self.live:
            raise Http404

        if path_components:
            # Request is for a screen
            return RouteResult(self,
                               kwargs=dict(screen=path_components[0],
                                           extra_path='/'.join(
                                               path_components[1:])))
        else:
            # Request is for screens index
            return RouteResult(self)
def _new_route(self, request, path_components):
    """
    Rewrite route method in order to handle languages fallbacks
    """

    request_language = get_language()
    if path_components:
        # request is for a child of this page
        child_slug = path_components[0]
        remaining_components = path_components[1:]

        subpages = self.get_children()
        for page in subpages:
            if page.specific.slug == child_slug:
                return page.specific.route(request, remaining_components)

            for language, _ in settings.LANGUAGES:
                if getattr(page.specific, 'slug_{}'.format(language),
                           None) == child_slug:
                    if not remaining_components:
                        raise WagtailLanguageRedirect(page.url)

                    return page.specific.route(request, remaining_components)

        raise Http404
    else:
        # request is for this very page

        if self.live:
            return RouteResult(self)
        else:
            raise Http404
Exemple #7
0
    def route(self, request, path_components):

        if path_components:
            """
            Customized to correctly route legacy blog posts with too long slugs.
            Additionally customized handle tags url
            """
            if path_components[0] == 'tags':
                # If first component is "tags", we handle that tag
                # URL for tags is /blog/tags/tag_name
                tag_slug = path_components[1]

                # Check if Tag with given name exists, if not raise 404.
                try:
                    tag = Tag.objects.get(slug__iexact=tag_slug)
                except Tag.DoesNotExist:
                    raise Http404

                if self.live:
                    return RouteResult(self, kwargs={"tag": tag})

                # if not components nor it's live
                raise Http404

            else:
                # If the first component is not "tags", handle legacy blog slug
                # Legacy blog posts have slugs with max_length=255 so we need
                # to make them compatible with new Wagtail's 50 chars limit.
                path_components[0] = path_components[0][:50]

        return super(BlogIndexPage, self).route(request, path_components)
Exemple #8
0
def _new_route(self, request, path_components):
    """
    Rewrite route method in order to handle languages fallbacks
    """
    if path_components:
        # request is for a child of this page
        child_slug = path_components[0]
        remaining_components = path_components[1:]

        # try:
        #     q = Q()
        #     for lang in settings.LANGUAGES:
        #         tr_field_name = 'slug_%s' % (lang[0])
        #         condition = {tr_field_name: child_slug}
        #         q |= Q(**condition)
        #     subpage = self.get_children().get(q)
        # except Page.DoesNotExist:
        #     raise Http404

        # return subpage.specific.route(request, remaining_components)

        subpages = self.get_children()
        for page in subpages:
            if page.specific.slug == child_slug:
                return page.specific.route(request, remaining_components)
        raise Http404

    else:
        # request is for this very page
        if self.live:
            return RouteResult(self)
        else:
            raise Http404
Exemple #9
0
    def route(self, request, path_components):
        """
        This hooks the subpage urls into Wagtails routing.
        """
        try:
            route_result = super(SuperPage,
                                 self).route(request, path_components)

            # Don't allow supers route method to serve this page
            if route_result.page == self:
                raise Http404

            return route_result
        except Http404 as e:
            if self.live:
                try:
                    path = '/'.join(path_components)
                    if path:
                        path += '/'

                    return RouteResult(self, self.resolve_subpage(path))
                except Resolver404:
                    pass

            # Reraise
            raise e
Exemple #10
0
 def route(self, request, path_components):
     result = super(AjaxBlogPage, self).route(request, path_components)
     if isinstance(result, RouteResult):
         result_page = result[0]
         if result_page == self.blog_page or result_page == self or self.blog_page.get_descendants(
         ).filter(id__in=[result_page.id]).exists():
             return RouteResult(self,
                                kwargs={'true_request_page': result_page})
     return result
Exemple #11
0
    def route(self, request, path_components):

        # Try the default to allow children to resolve
        try:
            return super(NewsIndexPage, self).route(request, path_components)
        except Http404:
            pass

        if path_components:
            # tell Wagtail to call self.serve() with an additional 'path_components' kwarg
            return RouteResult(self,
                               kwargs={'path_components': path_components})
        else:
            raise Http404
Exemple #12
0
    def route(self, request, path_components):
        """
        This hooks the subpage URLs into Wagtail's routing.
        """
        if self.live:
            try:
                path = '/'
                if path_components:
                    path += '/'.join(path_components) + '/'

                view, args, kwargs = self.resolve_subpage(path)
                return RouteResult(self, args=(view, args, kwargs))
            except Http404:
                pass

        return super(RoutablePageMixin, self).route(request, path_components)
Exemple #13
0
    def route(self, request, path_components):
        if path_components:
            # Request is for a child of this page.
            child_slug = path_components[0]
            remaining_components = path_components[1:]

            try:
                subpage = self.get_children().get(slug=child_slug)
            except Page.DoesNotExist:
                raise Http404

            return subpage.specific.route(request, remaining_components)

        else:
            # Request is for this very page.
            page = util.get_appropriate_page_version(request, self)
            if page:
                return RouteResult(page)
            raise Http404
Exemple #14
0
    def route(self, request, path_components):
        if path_components:
            # request is for a child of this page
            child_slug = path_components[0]
            remaining_components = path_components[1:]

            try:
                subpage = self.get_children().get(slug=child_slug)
            except Page.DoesNotExist:
                raise Http404

            return subpage.specific.route(request, remaining_components)

        else:
            # request is for this very page
            if self.live:
                return RouteResult(self)
            else:
                raise Http404
Exemple #15
0
def _new_route(self, request, path_components):
    """
    Rewrite route method in order to handle languages fallbacks
    """
    if path_components:
        # request is for a child of this page
        child_slug = path_components[0]
        remaining_components = path_components[1:]

        subpages = self.get_children()
        for page in subpages:
            if page.specific.slug == child_slug:
                return page.specific.route(request, remaining_components)
        raise Http404

    else:
        # request is for this very page
        if self.live:
            return RouteResult(self)
        else:
            raise Http404
Exemple #16
0
    def route(self, request, path_components):
        # TODO: possibly better to use routable mix-in. Also may be better if this handles routing for (child) categories?
        # also need to create month/day logic.
        if path_components:
            # request is for a child of this page
            child_path = '/'.join(path_components + [''])

            try:  # try posts or first level categories
                subpage = self.get_children().get(url_path=self.url_path +
                                                  child_path)
            except Page.DoesNotExist:  # use Page's route to get deeper categories
                return super(BlogType, self).route(request, path_components)

            return subpage.specific.route(request, None)

        else:
            # request is for this very page
            if self.live:
                return RouteResult(self)
            else:
                raise Http404
Exemple #17
0
 def route(self, request, path_components):
     try:
         return super(TstrHanlderPage, self).route(request, path_components)
     except Http404:
         return RouteResult(self)
Exemple #18
0
 def route(self, request, path_components):
     try:
         return super(BankingIndexPage, self).route(request,
                                                    path_components)
     except Http404:
         return RouteResult(self)
Exemple #19
0
    def route(self, request, path_components):
        if len(path_components) == 1 and path_components[0] == 'feed':
            return RouteResult(self, kwargs={'format': 'rss'})

        return super(FilterableFeedPageMixin,
                     self).route(request, path_components)
Exemple #20
0
 def route(self, request, path_components):
     if len(request.GET):
         return RouteResult(self,
                            kwargs={'template': 'roadmap/track/base.html'})
     else:
         return super(Track, self).route(request, path_components)