diff --git a/example/example/urls.py b/example/example/urls.py index 05fe60d1..bad90cf6 100644 --- a/example/example/urls.py +++ b/example/example/urls.py @@ -10,7 +10,6 @@ from search import views as search_views urlpatterns = [ - url(r"", include(grapple_urls)), url(r"^django-admin/", admin.site.urls), url(r"^admin/", include(wagtailadmin_urls)), url(r"^documents/", include(wagtaildocs_urls)), @@ -19,6 +18,7 @@ # Wagtail's page serving mechanism. This should be the last pattern in # the list: url(r"", include(wagtail_urls)), + url(r"", include(grapple_urls)), # Alternatively, if you want Wagtail pages to be served from a subpath # of your site, rather than the site root: # url(r'^pages/', include(wagtail_urls)), diff --git a/grapple/types/pages.py b/grapple/types/pages.py index d7719658..dbea8cd9 100644 --- a/grapple/types/pages.py +++ b/grapple/types/pages.py @@ -123,38 +123,33 @@ def get_specific_page(id, slug, url, token, content_type=None, info=None): Get a spcecific page, also get preview if token is passed """ page = None - # try: - # Generate queryset based on given key & Optimise query based on request AST - pages = WagtailPage.objects.live().public() - pages = QueryOptimzer.query(pages, info) - if id: - page = pages.get(id=id) - elif slug: - page = pages.get(slug=slug) - elif url: - for matching_page in pages.filter(url_path__contains=url): - if matching_page.url == url: - page = matching_page - break - - if page: - page = page.specific - - if token: + try: + # Generate queryset based on given key & Optimise query based on request AST + pages = WagtailPage.objects.live().public() + pages = QueryOptimzer.query(pages, info) + if id: + page = pages.get(id=id) + elif slug: + page = pages.get(slug=slug) + if page: - page_type = type(page) - if hasattr(page_type, "get_page_from_preview_token"): - page = page_type.get_page_from_preview_token(token) + page = page.specific + + if token: + if page: + page_type = type(page) + if hasattr(page_type, "get_page_from_preview_token"): + page = page_type.get_page_from_preview_token(token) - elif content_type: - app_label, model = content_type.lower().split(".") - mdl = ContentType.objects.get(app_label=app_label, model=model) - cls = mdl.model_class() - if hasattr(cls, "get_page_from_preview_token"): - page = cls.get_page_from_preview_token(token) + elif content_type: + app_label, model = content_type.lower().split(".") + mdl = ContentType.objects.get(app_label=app_label, model=model) + cls = mdl.model_class() + if hasattr(cls, "get_page_from_preview_token"): + page = cls.get_page_from_preview_token(token) - # except BaseException: - # page = None + except BaseException: + page = None return page @@ -169,7 +164,6 @@ class Mixin: PageInterface, id=graphene.Int(), slug=graphene.String(), - url=graphene.String(), token=graphene.String(), content_type=graphene.String(), ) @@ -185,7 +179,6 @@ def resolve_page(self, info, **kwargs): return get_specific_page( id=kwargs.get("id"), slug=kwargs.get("slug"), - url=kwargs.get("url"), token=kwargs.get("token"), content_type=kwargs.get("content_type"), info=info, diff --git a/grapple/utils.py b/grapple/utils.py index f07070f7..c4beddb1 100644 --- a/grapple/utils.py +++ b/grapple/utils.py @@ -1,7 +1,6 @@ import os import base64 import tempfile -import graphene_django_optimizer as gql_optimizer from PIL import Image, ImageFilter from django.conf import settings from wagtail.search.index import class_is_indexed