|
@@ -1,7 +1,6 @@
|
|
|
-import json
|
|
|
-
|
|
|
from django.shortcuts import get_object_or_404, render
|
|
|
from django.urls import reverse
|
|
|
+from django.utils.translation import ugettext as _
|
|
|
|
|
|
from wagtail.admin.forms import SearchForm
|
|
|
from wagtail.admin.modal_workflow import render_modal_workflow
|
|
@@ -17,19 +16,28 @@ from wagtail.utils.pagination import paginate
|
|
|
permission_checker = PermissionPolicyChecker(permission_policy)
|
|
|
|
|
|
|
|
|
-def get_document_json(document):
|
|
|
+def get_chooser_context():
|
|
|
+ """construct context variables needed by the chooser JS"""
|
|
|
+ return {
|
|
|
+ 'error_label': _("Server Error"),
|
|
|
+ 'error_message': _("Report this error to your webmaster with the following information:"),
|
|
|
+ 'tag_autocomplete_url': reverse('wagtailadmin_tag_autocomplete'),
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+def get_document_result_data(document):
|
|
|
"""
|
|
|
- helper function: given a document, return the json to pass back to the
|
|
|
+ helper function: given a document, return the json data to pass back to the
|
|
|
chooser panel
|
|
|
"""
|
|
|
|
|
|
- return json.dumps({
|
|
|
+ return {
|
|
|
'id': document.id,
|
|
|
'title': document.title,
|
|
|
'url': document.url,
|
|
|
'filename': document.filename,
|
|
|
'edit_link': reverse('wagtaildocs:edit', args=(document.id,)),
|
|
|
- })
|
|
|
+ }
|
|
|
|
|
|
|
|
|
def chooser(request):
|
|
@@ -88,7 +96,7 @@ def chooser(request):
|
|
|
'searchform': searchform,
|
|
|
'collections': collections,
|
|
|
'is_searching': False,
|
|
|
- })
|
|
|
+ }, json_data=get_chooser_context())
|
|
|
|
|
|
|
|
|
def document_chosen(request, document_id):
|
|
@@ -96,7 +104,7 @@ def document_chosen(request, document_id):
|
|
|
|
|
|
return render_modal_workflow(
|
|
|
request, None, 'wagtaildocs/chooser/document_chosen.js',
|
|
|
- {'document_json': get_document_json(document)}
|
|
|
+ None, json_data={'result': get_document_result_data(document)}
|
|
|
)
|
|
|
|
|
|
|
|
@@ -119,7 +127,7 @@ def chooser_upload(request):
|
|
|
|
|
|
return render_modal_workflow(
|
|
|
request, None, 'wagtaildocs/chooser/document_chosen.js',
|
|
|
- {'document_json': get_document_json(document)}
|
|
|
+ None, json_data={'result': get_document_result_data(document)}
|
|
|
)
|
|
|
else:
|
|
|
form = DocumentForm(user=request.user)
|
|
@@ -128,5 +136,6 @@ def chooser_upload(request):
|
|
|
|
|
|
return render_modal_workflow(
|
|
|
request, 'wagtaildocs/chooser/chooser.html', 'wagtaildocs/chooser/chooser.js',
|
|
|
- {'documents': documents, 'uploadform': form}
|
|
|
+ {'documents': documents, 'uploadform': form},
|
|
|
+ json_data=get_chooser_context()
|
|
|
)
|