Skip to content

Commit

Permalink
Remove renduntant changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NathHorrigan committed Mar 27, 2020
1 parent 4525bd7 commit b7a0d19
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
2 changes: 1 addition & 1 deletion example/example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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)),
Expand Down
55 changes: 24 additions & 31 deletions grapple/types/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -169,7 +164,6 @@ class Mixin:
PageInterface,
id=graphene.Int(),
slug=graphene.String(),
url=graphene.String(),
token=graphene.String(),
content_type=graphene.String(),
)
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion grapple/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b7a0d19

Please sign in to comment.