Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix djangoql_syntax_help url in error_message #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions djangoql/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.db import DataError, NotSupportedError
from django.forms import Media
from django.http import HttpResponse
from django.shortcuts import resolve_url
from django.template.loader import render_to_string
from django.views.generic import TemplateView

Expand Down Expand Up @@ -112,6 +113,9 @@ def djangoql_error_message(self, exception):
msg = text_type(exception)
return render_to_string('djangoql/error_message.html', context={
'error_message': msg,
'djangoql_syntax_help_url': resolve_url(
f'{self.admin_site.name}:djangoql_syntax_help'
),
})

@property
Expand Down
2 changes: 1 addition & 1 deletion djangoql/templates/djangoql/error_message.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="clearfix">
{{ error_message }}
<a href="{% url 'admin:djangoql_syntax_help' %}" class="djangoql-help">
<a href="{{ djangoql_syntax_help_url }}" class="djangoql-help">
DjangoQL syntax help
</a>
</div>
19 changes: 11 additions & 8 deletions test_project/core/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ def test_introspection_suggestion_api_url(self):
)

def test_djangoql_syntax_help(self):
url = reverse('admin:djangoql_syntax_help')
# unauthorized request should be redirected
response = self.client.get(url)
self.assertEqual(302, response.status_code)
self.assertTrue(self.client.login(**self.credentials))
# authorized request should be served
response = self.client.get(url)
self.assertEqual(200, response.status_code)
for app in ['admin', 'zaibatsu']:
url = reverse(f'{app}:djangoql_syntax_help')
self.client.logout()
with self.subTest(app=app):
response = self.client.get(url)
# unauthorized request should be redirected
self.assertEqual(302, response.status_code)
self.assertTrue(self.client.login(**self.credentials))
# authorized request should be served
response = self.client.get(url)
self.assertEqual(200, response.status_code)

def test_suggestions(self):
url = reverse('admin:core_book_djangoql_suggestions')
Expand Down