0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00

Replaces direct usages of Document model

We need to use `get_document_model` instead of `Document` directly
because Wagtail provides ability to define custom document model.
This commit is contained in:
Mikalai Radchuk 2016-04-10 17:53:07 +03:00 committed by Matt Westcott
parent 869404032f
commit 1599a69af6
5 changed files with 13 additions and 7 deletions

View File

@ -12,7 +12,7 @@ from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from wagtail.wagtailcore.models import Page
from wagtail.wagtaildocs.models import Document
from wagtail.wagtaildocs.models import get_document_model
from wagtail.wagtailimages.models import get_image_model
from .filters import (
@ -282,4 +282,4 @@ class DocumentsAPIEndpoint(BaseAPIEndpoint):
extra_meta_fields = ['tags', ]
default_fields = ['title', 'tags']
name = 'documents'
model = Document
model = get_document_model()

View File

@ -6,7 +6,7 @@ from django.db.models.signals import post_delete, post_save
from wagtail.contrib.wagtailfrontendcache.utils import purge_url_from_cache
from wagtail.wagtailcore.models import get_page_models
from wagtail.wagtailcore.signals import page_published, page_unpublished
from wagtail.wagtaildocs.models import Document
from wagtail.wagtaildocs.models import get_document_model
from wagtail.wagtailimages.models import get_image_model
from .utils import get_base_url
@ -31,6 +31,7 @@ def purge_document_from_cache(instance, **kwargs):
def register_signal_handlers():
Image = get_image_model()
Document = get_document_model()
for model in get_page_models():
page_published.connect(purge_page_from_cache, sender=model)
@ -44,6 +45,7 @@ def register_signal_handlers():
def unregister_signal_handlers():
Image = get_image_model()
Document = get_document_model()
for model in get_page_models():
page_published.disconnect(purge_page_from_cache, sender=model)

View File

@ -12,7 +12,7 @@ from rest_framework.viewsets import GenericViewSet
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.utils import resolve_model_string
from wagtail.wagtaildocs.models import Document
from wagtail.wagtaildocs.models import get_document_model
from wagtail.wagtailimages.models import get_image_model
from .filters import ChildOfFilter, DescendantOfFilter, FieldsFilter, OrderingFilter, SearchFilter
@ -239,4 +239,4 @@ class DocumentsAPIEndpoint(BaseAPIEndpoint):
filter_backends = [FieldsFilter, OrderingFilter, SearchFilter]
extra_api_fields = ['title', 'tags']
name = 'documents'
model = Document
model = get_document_model()

View File

@ -6,7 +6,7 @@ from django.db.models.signals import post_delete, post_save
from wagtail.contrib.wagtailfrontendcache.utils import purge_url_from_cache
from wagtail.wagtailcore.models import get_page_models
from wagtail.wagtailcore.signals import page_published, page_unpublished
from wagtail.wagtaildocs.models import Document
from wagtail.wagtaildocs.models import get_document_model
from wagtail.wagtailimages.models import get_image_model
from .utils import get_base_url
@ -31,6 +31,7 @@ def purge_document_from_cache(instance, **kwargs):
def register_signal_handlers():
Image = get_image_model()
Document = get_document_model()
for model in get_page_models():
page_published.connect(purge_page_from_cache, sender=model)
@ -44,6 +45,7 @@ def register_signal_handlers():
def unregister_signal_handlers():
Image = get_image_model()
Document = get_document_model()
for model in get_page_models():
page_published.disconnect(purge_page_from_cache, sender=model)

View File

@ -2,7 +2,7 @@ from __future__ import absolute_import, unicode_literals
from django_medusa.renderers import StaticSiteRenderer
from wagtail.wagtailcore.models import Site
from wagtail.wagtaildocs.models import Document
from wagtail.wagtaildocs.models import get_document_model
class PageRenderer(StaticSiteRenderer):
@ -19,6 +19,8 @@ class PageRenderer(StaticSiteRenderer):
class DocumentRenderer(StaticSiteRenderer):
def get_paths(self):
Document = get_document_model()
# Return list of paths to documents
return (doc.url for doc in Document.objects.all())