Skip to content

Commit

Permalink
Nicer way to register template_debug views
Browse files Browse the repository at this point in the history
  • Loading branch information
chosak committed Apr 14, 2020
1 parent 45988fb commit 1104725
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
24 changes: 24 additions & 0 deletions cfgov/v1/template_debug/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from wagtail.core import hooks

from v1.views.template_debug import TemplateDebugView


try:
from django.urls import re_path
except ImportError: # pragma: nocover
from django.conf.urls import url as re_path


def register_template_debug(app_name, url_path, template_name, test_cases):
@hooks.register('register_admin_urls')
def register_template_debug_url():
return [
re_path(
rf'^template_debug/{app_name}/{url_path}/',
TemplateDebugView.as_view(
debug_template_name=template_name,
debug_test_cases=test_cases
),
name=f'template_debug_{app_name}_{url_path}'
),
]
File renamed without changes.
37 changes: 10 additions & 27 deletions cfgov/v1/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

from django.conf import settings
from django.conf.urls import include
from django.contrib import admin
from django.contrib.auth.models import Permission
from django.core.exceptions import PermissionDenied
Expand All @@ -19,14 +18,13 @@
from scripts import export_enforcement_actions

from ask_cfpb.models.snippets import GlossaryTerm
from v1 import template_debug
from v1.admin_views import ExportFeedbackView, manage_cdn
from v1.models.banners import Banner
from v1.models.portal_topics import PortalCategory, PortalTopic
from v1.models.resources import Resource
from v1.models.snippets import Contact, RelatedResource, ReusableText
from v1.template_debug import register_template_debug, test_cases
from v1.util import util
from v1.views.template_debug import TemplateDebugView


try:
Expand Down Expand Up @@ -58,9 +56,9 @@ def register_export_menu_item():
@hooks.register('register_admin_urls')
def register_export_url():
return [re_path(
'export-enforcement-actions',
export_data,
name='export-enforcement-actions')]
'export-enforcement-actions',
export_data,
name='export-enforcement-actions')]


@hooks.register('before_delete_page')
Expand Down Expand Up @@ -409,24 +407,9 @@ def add_export_feedback_permission_to_wagtail_admin_group_view():
)


@hooks.register('register_admin_urls')
def register_template_debug_urls():
urls = [
re_path(
rf'^template_debug/v1/{template_name}/',
TemplateDebugView.as_view(
debug_template_name=(
f'_includes/molecules/{template_name}.html'
),
debug_test_cases=getattr(
template_debug,
f'{template_name}_test_cases'
)
),
name=f'template_debug_{template_name}'
) for template_name in (
'notification',
)
]

return [re_path('', include(urls, namespace='v1'))]
register_template_debug(
'v1',
'notification',
'_includes/molecules/notification.html',
test_cases.notification_test_cases
)

0 comments on commit 1104725

Please sign in to comment.