mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Put all wagtailsnippets URLs into a namespace
This commit is contained in:
parent
2931cb2e02
commit
b383ee4bcc
@ -32,7 +32,7 @@ def register_snippet(model):
|
||||
|
||||
def get_snippet_usage_url(self):
|
||||
content_type = ContentType.objects.get_for_model(self)
|
||||
return reverse('wagtailsnippets_usage',
|
||||
return reverse('wagtailsnippets:usage',
|
||||
args=(content_type.app_label,
|
||||
content_type.model,
|
||||
self.id,))
|
||||
|
@ -6,7 +6,7 @@
|
||||
{% if items %}
|
||||
{% include "wagtailsnippets/chooser/list.html" with choosing=1 %}
|
||||
{% else %}
|
||||
{% url 'wagtailsnippets_create' content_type.app_label content_type.model as wagtailsnippets_create_snippet_url %}
|
||||
{% url 'wagtailsnippets:create' content_type.app_label content_type.model as wagtailsnippets_create_snippet_url %}
|
||||
<p>{% blocktrans %}You haven't created any {{ snippet_type_name }} snippets. Why not <a href="{{ wagtailsnippets_create_snippet_url }}" target="_blank">create one now{% endblocktrans %}</p>
|
||||
{% endif %}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{% load i18n %}
|
||||
|
||||
{% url "wagtailsnippets_choose" content_type.app_label content_type.model as linkurl %}
|
||||
{% url "wagtailsnippets:choose" content_type.app_label content_type.model as linkurl %}
|
||||
|
||||
<table class="listing" id="snippet-chooser-list" data-url="{{ linkurl }}">
|
||||
<col />
|
||||
@ -16,9 +16,9 @@
|
||||
<tr>
|
||||
<td class="title">
|
||||
{% if choosing %}
|
||||
<h2><a class="snippet-choice" href="{% url 'wagtailsnippets_chosen' content_type.app_label content_type.model snippet.id %}">{{ snippet }}</a></h2>
|
||||
<h2><a class="snippet-choice" href="{% url 'wagtailsnippets:chosen' content_type.app_label content_type.model snippet.id %}">{{ snippet }}</a></h2>
|
||||
{% else %}
|
||||
<h2><a href="{% url 'wagtailsnippets_edit' content_type.app_label content_type.model snippet.id %}">{{ snippet }}</a></h2>
|
||||
<h2><a href="{% url 'wagtailsnippets:edit' content_type.app_label content_type.model snippet.id %}">{{ snippet }}</a></h2>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
<div class="nice-padding">
|
||||
<p>{% blocktrans %}Are you sure you want to delete this {{ snippet_type_name }}?{% endblocktrans %}</p>
|
||||
<form action="{% url 'wagtailsnippets_delete' content_type.app_label content_type.model instance.id %}" method="POST">
|
||||
<form action="{% url 'wagtailsnippets:delete' content_type.app_label content_type.model instance.id %}" method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="{% trans 'Yes, delete' %}" class="serious" />
|
||||
</form>
|
||||
|
@ -6,7 +6,7 @@
|
||||
{% trans "New" as new_str %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=new_str subtitle=snippet_type_name icon="snippet" %}
|
||||
|
||||
<form action="{% url 'wagtailsnippets_create' content_type.app_label content_type.model %}" method="POST">
|
||||
<form action="{% url 'wagtailsnippets:create' content_type.app_label content_type.model %}" method="POST">
|
||||
{% csrf_token %}
|
||||
{{ edit_handler.render_form_content }}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
{% trans "Editing" as editing_str %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=editing_str subtitle=instance icon="snippet" usage_object=instance %}
|
||||
|
||||
<form action="{% url 'wagtailsnippets_edit' content_type.app_label content_type.model instance.id %}" method="POST">
|
||||
<form action="{% url 'wagtailsnippets:edit' content_type.app_label content_type.model instance.id %}" method="POST">
|
||||
{% csrf_token %}
|
||||
{{ edit_handler.render_form_content }}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
<input type="submit" value="{% trans 'Save' %}" class="button" />
|
||||
<div class="dropdown-toggle icon icon-arrow-up"></div>
|
||||
<ul role="menu">
|
||||
<li><a href="{% url 'wagtailsnippets_delete' content_type.app_label content_type.model instance.id %}" class="shortcut">{% trans "Delete" %}</a></li>
|
||||
<li><a href="{% url 'wagtailsnippets:delete' content_type.app_label content_type.model instance.id %}" class="shortcut">{% trans "Delete" %}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<li>
|
||||
<div class="row row-flush title">
|
||||
<h2>
|
||||
<a href="{% url 'wagtailsnippets_list' content_type.app_label content_type.model %}" class="col6">
|
||||
<a href="{% url 'wagtailsnippets:list' content_type.app_label content_type.model %}" class="col6">
|
||||
{{ name|capfirst }}
|
||||
</a>
|
||||
</h2>
|
||||
|
@ -13,9 +13,9 @@
|
||||
<tr>
|
||||
<td class="title">
|
||||
{% if choosing %}
|
||||
<h2><a class="snippet-choice" href="{% url 'wagtailsnippets_chosen' content_type.app_label content_type.model snippet.id %}">{{ snippet }}</a></h2>
|
||||
<h2><a class="snippet-choice" href="{% url 'wagtailsnippets:chosen' content_type.app_label content_type.model snippet.id %}">{{ snippet }}</a></h2>
|
||||
{% else %}
|
||||
<h2><a href="{% url 'wagtailsnippets_edit' content_type.app_label content_type.model snippet.id %}">{{ snippet }}</a></h2>
|
||||
<h2><a href="{% url 'wagtailsnippets:edit' content_type.app_label content_type.model snippet.id %}">{{ snippet }}</a></h2>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -10,7 +10,7 @@
|
||||
<h1 class="icon icon-snippet">{% blocktrans with snippet_type_name_plural=snippet_type_name_plural|capfirst %}Snippets <span>{{ snippet_type_name_plural }}</span>{% endblocktrans %}</h1>
|
||||
</div>
|
||||
<div class="right col3">
|
||||
<a href="{% url 'wagtailsnippets_create' content_type.app_label content_type.model %}" class="button bicolor icon icon-plus">{% blocktrans %}Add {{ snippet_type_name }}{% endblocktrans %}</a>
|
||||
<a href="{% url 'wagtailsnippets:create' content_type.app_label content_type.model %}" class="button bicolor icon icon-plus">{% blocktrans %}Add {{ snippet_type_name }}{% endblocktrans %}</a>
|
||||
{# TODO: figure out a way of saying "Add a/an [foo]" #}
|
||||
</div>
|
||||
</div>
|
||||
@ -19,7 +19,7 @@
|
||||
{% if items %}
|
||||
{% include "wagtailsnippets/snippets/list.html" %}
|
||||
{% else %}
|
||||
{% url 'wagtailsnippets_create' content_type.app_label content_type.model as wagtailsnippets_create_url %}
|
||||
{% url 'wagtailsnippets:create' content_type.app_label content_type.model as wagtailsnippets_create_url %}
|
||||
<p class="no-results-message">{% blocktrans %}No {{ snippet_type_name_plural }} have been created. Why not <a href="{{ wagtailsnippets_create_url }}">add one</a>?{% endblocktrans %}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
@ -6,4 +6,4 @@
|
||||
<span class="title">{{ item }}</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block edit_chosen_item_url %}{% if item %}{% url 'wagtailsnippets_edit' widget.target_content_type.app_label widget.target_content_type.model item.id %}{% endif %}{% endblock %}
|
||||
{% block edit_chosen_item_url %}{% if item %}{% url 'wagtailsnippets:edit' widget.target_content_type.app_label widget.target_content_type.model item.id %}{% endif %}{% endblock %}
|
||||
|
@ -18,7 +18,7 @@ class TestSnippetIndexView(TestCase, WagtailTestUtils):
|
||||
self.login()
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get(reverse('wagtailsnippets_index'), params)
|
||||
return self.client.get(reverse('wagtailsnippets:index'), params)
|
||||
|
||||
def test_simple(self):
|
||||
response = self.get()
|
||||
@ -34,7 +34,7 @@ class TestSnippetListView(TestCase, WagtailTestUtils):
|
||||
self.login()
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get(reverse('wagtailsnippets_list',
|
||||
return self.client.get(reverse('wagtailsnippets:list',
|
||||
args=('tests', 'advert')),
|
||||
params)
|
||||
|
||||
@ -60,12 +60,12 @@ class TestSnippetCreateView(TestCase, WagtailTestUtils):
|
||||
self.login()
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get(reverse('wagtailsnippets_create',
|
||||
return self.client.get(reverse('wagtailsnippets:create',
|
||||
args=('tests', 'advert')),
|
||||
params)
|
||||
|
||||
def post(self, post_data={}):
|
||||
return self.client.post(reverse('wagtailsnippets_create',
|
||||
return self.client.post(reverse('wagtailsnippets:create',
|
||||
args=('tests', 'advert')),
|
||||
post_data)
|
||||
|
||||
@ -82,7 +82,7 @@ class TestSnippetCreateView(TestCase, WagtailTestUtils):
|
||||
def test_create(self):
|
||||
response = self.post(post_data={'text': 'test_advert',
|
||||
'url': 'http://www.example.com/'})
|
||||
self.assertRedirects(response, reverse('wagtailsnippets_list', args=('tests', 'advert')))
|
||||
self.assertRedirects(response, reverse('wagtailsnippets:list', args=('tests', 'advert')))
|
||||
|
||||
snippets = Advert.objects.filter(text='test_advert')
|
||||
self.assertEqual(snippets.count(), 1)
|
||||
@ -97,12 +97,12 @@ class TestSnippetEditView(TestCase, WagtailTestUtils):
|
||||
self.login()
|
||||
|
||||
def get(self, params={}):
|
||||
return self.client.get(reverse('wagtailsnippets_edit',
|
||||
return self.client.get(reverse('wagtailsnippets:edit',
|
||||
args=('tests', 'advert', self.test_snippet.id)),
|
||||
params)
|
||||
|
||||
def post(self, post_data={}):
|
||||
return self.client.post(reverse('wagtailsnippets_edit',
|
||||
return self.client.post(reverse('wagtailsnippets:edit',
|
||||
args=('tests', 'advert', self.test_snippet.id)),
|
||||
post_data)
|
||||
|
||||
@ -112,11 +112,11 @@ class TestSnippetEditView(TestCase, WagtailTestUtils):
|
||||
self.assertTemplateUsed(response, 'wagtailsnippets/snippets/edit.html')
|
||||
|
||||
def test_non_existant_model(self):
|
||||
response = self.client.get(reverse('wagtailsnippets_edit', args=('tests', 'foo', self.test_snippet.id)))
|
||||
response = self.client.get(reverse('wagtailsnippets:edit', args=('tests', 'foo', self.test_snippet.id)))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_nonexistant_id(self):
|
||||
response = self.client.get(reverse('wagtailsnippets_edit', args=('tests', 'advert', 999999)))
|
||||
response = self.client.get(reverse('wagtailsnippets:edit', args=('tests', 'advert', 999999)))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_edit_invalid(self):
|
||||
@ -127,7 +127,7 @@ class TestSnippetEditView(TestCase, WagtailTestUtils):
|
||||
def test_edit(self):
|
||||
response = self.post(post_data={'text': 'edited_test_advert',
|
||||
'url': 'http://www.example.com/edited'})
|
||||
self.assertRedirects(response, reverse('wagtailsnippets_list', args=('tests', 'advert')))
|
||||
self.assertRedirects(response, reverse('wagtailsnippets:list', args=('tests', 'advert')))
|
||||
|
||||
snippets = Advert.objects.filter(text='edited_test_advert')
|
||||
self.assertEqual(snippets.count(), 1)
|
||||
@ -142,15 +142,15 @@ class TestSnippetDelete(TestCase, WagtailTestUtils):
|
||||
self.login()
|
||||
|
||||
def test_delete_get(self):
|
||||
response = self.client.get(reverse('wagtailsnippets_delete', args=('tests', 'advert', self.test_snippet.id, )))
|
||||
response = self.client.get(reverse('wagtailsnippets:delete', args=('tests', 'advert', self.test_snippet.id, )))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_delete_post(self):
|
||||
post_data = {'foo': 'bar'} # For some reason, this test doesn't work without a bit of POST data
|
||||
response = self.client.post(reverse('wagtailsnippets_delete', args=('tests', 'advert', self.test_snippet.id, )), post_data)
|
||||
response = self.client.post(reverse('wagtailsnippets:delete', args=('tests', 'advert', self.test_snippet.id, )), post_data)
|
||||
|
||||
# Should be redirected to explorer page
|
||||
self.assertRedirects(response, reverse('wagtailsnippets_list', args=('tests', 'advert')))
|
||||
self.assertRedirects(response, reverse('wagtailsnippets:list', args=('tests', 'advert')))
|
||||
|
||||
# Check that the page is gone
|
||||
self.assertEqual(Advert.objects.filter(text='test_advert').count(), 0)
|
||||
@ -234,7 +234,7 @@ class TestSnippetChoose(TestCase, WagtailTestUtils):
|
||||
self.login()
|
||||
|
||||
def get(self, params=None):
|
||||
return self.client.get(reverse('wagtailsnippets_choose',
|
||||
return self.client.get(reverse('wagtailsnippets:choose',
|
||||
args=('tests', 'advert')),
|
||||
params or {})
|
||||
|
||||
@ -258,7 +258,7 @@ class TestSnippetChosen(TestCase, WagtailTestUtils):
|
||||
self.login()
|
||||
|
||||
def get(self, pk, params=None):
|
||||
return self.client.get(reverse('wagtailsnippets_chosen',
|
||||
return self.client.get(reverse('wagtailsnippets:chosen',
|
||||
args=('tests', 'advert', pk)),
|
||||
params or {})
|
||||
|
||||
|
@ -3,15 +3,15 @@ from wagtail.wagtailsnippets.views import chooser, snippets
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', snippets.index, name='wagtailsnippets_index'),
|
||||
url(r'^$', snippets.index, name='index'),
|
||||
|
||||
url(r'^choose/$', chooser.choose, name='wagtailsnippets_choose_generic'),
|
||||
url(r'^choose/(\w+)/(\w+)/$', chooser.choose, name='wagtailsnippets_choose'),
|
||||
url(r'^choose/(\w+)/(\w+)/(\d+)/$', chooser.chosen, name='wagtailsnippets_chosen'),
|
||||
url(r'^choose/$', chooser.choose, name='choose_generic'),
|
||||
url(r'^choose/(\w+)/(\w+)/$', chooser.choose, name='choose'),
|
||||
url(r'^choose/(\w+)/(\w+)/(\d+)/$', chooser.chosen, name='chosen'),
|
||||
|
||||
url(r'^(\w+)/(\w+)/$', snippets.list, name='wagtailsnippets_list'),
|
||||
url(r'^(\w+)/(\w+)/new/$', snippets.create, name='wagtailsnippets_create'),
|
||||
url(r'^(\w+)/(\w+)/(\d+)/$', snippets.edit, name='wagtailsnippets_edit'),
|
||||
url(r'^(\w+)/(\w+)/(\d+)/delete/$', snippets.delete, name='wagtailsnippets_delete'),
|
||||
url(r'^(\w+)/(\w+)/(\d+)/usage/$', snippets.usage, name='wagtailsnippets_usage'),
|
||||
url(r'^(\w+)/(\w+)/$', snippets.list, name='list'),
|
||||
url(r'^(\w+)/(\w+)/new/$', snippets.create, name='create'),
|
||||
url(r'^(\w+)/(\w+)/(\d+)/$', snippets.edit, name='edit'),
|
||||
url(r'^(\w+)/(\w+)/(\d+)/delete/$', snippets.delete, name='delete'),
|
||||
url(r'^(\w+)/(\w+)/(\d+)/usage/$', snippets.usage, name='usage'),
|
||||
]
|
||||
|
@ -46,7 +46,7 @@ def chosen(request, content_type_app_name, content_type_model_name, id):
|
||||
snippet_json = json.dumps({
|
||||
'id': item.id,
|
||||
'string': text_type(item),
|
||||
'edit_link': reverse('wagtailsnippets_edit', args=(content_type_app_name, content_type_model_name, item.id,))
|
||||
'edit_link': reverse('wagtailsnippets:edit', args=(content_type_app_name, content_type_model_name, item.id,))
|
||||
})
|
||||
|
||||
return render_modal_workflow(
|
||||
|
@ -138,10 +138,10 @@ def create(request, content_type_app_name, content_type_model_name):
|
||||
instance=instance
|
||||
),
|
||||
buttons=[
|
||||
messages.button(reverse('wagtailsnippets_edit', args=(content_type_app_name, content_type_model_name, instance.id)), _('Edit'))
|
||||
messages.button(reverse('wagtailsnippets:edit', args=(content_type_app_name, content_type_model_name, instance.id)), _('Edit'))
|
||||
]
|
||||
)
|
||||
return redirect('wagtailsnippets_list', content_type.app_label, content_type.model)
|
||||
return redirect('wagtailsnippets:list', content_type.app_label, content_type.model)
|
||||
else:
|
||||
messages.error(request, _("The snippet could not be created due to errors."))
|
||||
edit_handler = edit_handler_class(instance=instance, form=form)
|
||||
@ -181,10 +181,10 @@ def edit(request, content_type_app_name, content_type_model_name, id):
|
||||
instance=instance
|
||||
),
|
||||
buttons=[
|
||||
messages.button(reverse('wagtailsnippets_edit', args=(content_type_app_name, content_type_model_name, instance.id)), _('Edit'))
|
||||
messages.button(reverse('wagtailsnippets:edit', args=(content_type_app_name, content_type_model_name, instance.id)), _('Edit'))
|
||||
]
|
||||
)
|
||||
return redirect('wagtailsnippets_list', content_type.app_label, content_type.model)
|
||||
return redirect('wagtailsnippets:list', content_type.app_label, content_type.model)
|
||||
else:
|
||||
messages.error(request, _("The snippet could not be saved due to errors."))
|
||||
edit_handler = edit_handler_class(instance=instance, form=form)
|
||||
@ -219,7 +219,7 @@ def delete(request, content_type_app_name, content_type_model_name, id):
|
||||
instance=instance
|
||||
)
|
||||
)
|
||||
return redirect('wagtailsnippets_list', content_type.app_label, content_type.model)
|
||||
return redirect('wagtailsnippets:list', content_type.app_label, content_type.model)
|
||||
|
||||
return render(request, 'wagtailsnippets/snippets/confirm_delete.html', {
|
||||
'content_type': content_type,
|
||||
|
@ -16,7 +16,7 @@ from wagtail.wagtailsnippets.models import get_snippet_content_types
|
||||
@hooks.register('register_admin_urls')
|
||||
def register_admin_urls():
|
||||
return [
|
||||
url(r'^snippets/', include(urls)),
|
||||
url(r'^snippets/', include(urls, namespace='wagtailsnippets')),
|
||||
]
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ class SnippetsMenuItem(MenuItem):
|
||||
|
||||
@hooks.register('register_admin_menu_item')
|
||||
def register_snippets_menu_item():
|
||||
return SnippetsMenuItem(_('Snippets'), urlresolvers.reverse('wagtailsnippets_index'), classnames='icon icon-snippet', order=500)
|
||||
return SnippetsMenuItem(_('Snippets'), urlresolvers.reverse('wagtailsnippets:index'), classnames='icon icon-snippet', order=500)
|
||||
|
||||
|
||||
@hooks.register('insert_editor_js')
|
||||
@ -37,7 +37,7 @@ def editor_js():
|
||||
""",
|
||||
settings.STATIC_URL,
|
||||
'wagtailsnippets/js/snippet-chooser.js',
|
||||
urlresolvers.reverse('wagtailsnippets_choose_generic')
|
||||
urlresolvers.reverse('wagtailsnippets:choose_generic')
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user