StreamFieldPanel('body'), ImageChooserPanel('homepage_image'), InlinePanel('screenshots', label="Screenshots"), FieldPanel('visit_the_site'), ] promote_panels = [ MultiFieldPanel(Page.promote_panels, "Common page configuration"), ImageChooserPanel('feed_image'), FieldPanel('listing_summary'), FieldPanel('related_services', widget=forms.CheckboxSelectMultiple), ] # Work index page @method_decorator(get_default_cache_control_decorator(), name='serve') class WorkIndexPage(HeadlessPreviewMixin, Page): intro = RichTextField(blank=True) hide_popular_tags = models.BooleanField(default=False) def get_popular_tags(self): # Get a ValuesQuerySet of tags ordered by most popular popular_tags = WorkPageTagSelect.objects.all().values('tag').annotate(item_count=models.Count('tag')).order_by('-item_count') # Return first 10 popular tags as tag objects # Getting them individually to preserve the order return [Tag.objects.get(id=tag['tag']) for tag in popular_tags[:10]] @property def works(self):
# Add views for testing 404 and 500 templates urlpatterns += [ url(r'^test404/$', TemplateView.as_view(template_name='404.html')), url(r'^test500/$', TemplateView.as_view(template_name='500.html')), ] urlpatterns += [ url(r'^review/', include(wagtailreview_urls)), url(r'', include(torchbox_urls)), ] handler404 = 'tbx.core.views.error404' # Set public URLs to use public cache. urlpatterns = decorate_urlpatterns(urlpatterns, get_default_cache_control_decorator()) # Set vary header to instruct cache to serve different version on different # cookies, different request method (e.g. AJAX) and different protocol # (http vs https). urlpatterns = decorate_urlpatterns( urlpatterns, vary_on_headers('Cookie', 'X-Requested-With', 'X-Forwarded-Proto', 'Accept-Encoding')) Page.serve = get_default_cache_control_decorator()(Page.serve) # Join private and public URLs. urlpatterns = private_urlpatterns + urlpatterns + [ # Add Wagtail URLs at the end. # Wagtail cache-control is set on the page models's serve methods.
] # Style guide if getattr(settings, "PATTERN_LIBRARY_ENABLED", False) and apps.is_installed( "pattern_library" ): from tbx.project_styleguide.views import example_form private_urlpatterns += [ path("pattern-library/example-form/", example_form), path("pattern-library/", include("pattern_library.urls")), ] # Set public URLs to use public cache. urlpatterns = decorate_urlpatterns(urlpatterns, get_default_cache_control_decorator()) # Set vary header to instruct cache to serve different version on different # cookies, different request method (e.g. AJAX) and different protocol # (http vs https). urlpatterns = decorate_urlpatterns( urlpatterns, vary_on_headers( "Cookie", "X-Requested-With", "X-Forwarded-Proto", "Accept-Encoding" ), ) Page.serve = get_default_cache_control_decorator()(Page.serve) # Join private and public URLs. urlpatterns = (
from wagtail.core.fields import StreamField from wagtail.core.models import Orderable, Page from wagtail.images.edit_handlers import ImageChooserPanel from wagtail.search import index from wagtail.snippets.edit_handlers import SnippetChooserPanel from tbx.core.blocks import StoryBlock from tbx.core.models import RelatedLink, Tag from tbx.core.utils.cache import get_default_cache_control_decorator class BlogIndexPageRelatedLink(Orderable, RelatedLink): page = ParentalKey('blog.BlogIndexPage', related_name='related_links') @method_decorator(get_default_cache_control_decorator(), name='serve') class BlogIndexPage(Page): intro = models.TextField(blank=True) search_fields = Page.search_fields + [ index.SearchField('intro'), ] def get_popular_tags(self): # Get a ValuesQuerySet of tags ordered by most popular (exclude 'planet-drupal' as this is effectively # the same as Drupal and only needed for the rss feed) popular_tags = BlogPageTagSelect.objects.all().exclude( tag__name='planet-drupal').values('tag').annotate( item_count=models.Count('tag')).order_by('-item_count') # Return first 10 popular tags as tag objects
path('test404/', TemplateView.as_view(template_name='404.html')), path('test500/', TemplateView.as_view(template_name='500.html')), ] urlpatterns += [ path('review', include(wagtailreview_urls)), path('', include(torchbox_urls)), path('graphql/', csrf_exempt(GraphQLView.as_view(graphiql=True))), path('', lambda request: HttpResponseNotFound(), name='home'), ] # Set public URLs to use public cache. urlpatterns = decorate_urlpatterns(urlpatterns, get_default_cache_control_decorator()) # Set vary header to instruct cache to serve different version on different # cookies, different request method (e.g. AJAX) and different protocol # (http vs https). urlpatterns = decorate_urlpatterns( urlpatterns, vary_on_headers('Cookie', 'X-Requested-With', 'X-Forwarded-Proto', 'Accept-Encoding') ) Page.serve = get_default_cache_control_decorator()(Page.serve) # Join private and public URLs. urlpatterns = private_urlpatterns + urlpatterns + decorate_urlpatterns([ # Wagtail paths have to be enabled for the administration interface to work