make document title / edit_url available through get_value_data

pull/6680/head
Matt Westcott 2021-01-05 19:38:00 +00:00 zatwierdzone przez Matt Westcott
rodzic 1606d4d09e
commit a0cb7a9c81
1 zmienionych plików z 20 dodań i 11 usunięć

Wyświetl plik

@ -19,25 +19,34 @@ class AdminDocumentChooser(AdminChooser):
super().__init__(**kwargs)
self.document_model = get_document_model()
def render_html(self, name, value, attrs):
document, value = self.get_instance_and_id(self.document_model, value)
original_field_html = super().render_html(name, value, attrs)
def get_value_data(self, value):
if value is None:
return None
elif isinstance(value, self.document_model):
doc = value
else: # assume document ID
doc = self.document_model.objects.get(pk=value)
# # Must import here because doing so at the top of the file is too early in the bootstrap.
# from wagtail.documents.permissions import permission_policy
# if not permission_policy.user_has_permission_for_instance(user, 'change', instance):
# self.show_edit_link = False
return {
'id': doc.pk,
'title': doc.title,
'edit_url': reverse('wagtaildocs:edit', args=[doc.id]),
}
def render_html(self, name, value_data, attrs):
value_data = value_data or {}
original_field_html = super().render_html(name, value_data.get('id'), attrs)
return render_to_string("wagtaildocs/widgets/document_chooser.html", {
'widget': self,
'original_field_html': original_field_html,
'attrs': attrs,
'value': value,
'display_title': document.title if document else '',
'edit_url': reverse('wagtaildocs:edit', args=[document.id]) if document else '',
'value': bool(value_data), # only used by chooser.html to identify blank values
'display_title': value_data.get('title', ''),
'edit_url': value_data.get('edit_url', ''),
})
def render_js_init(self, id_, name, value):
def render_js_init(self, id_, name, value_data):
return "createDocumentChooser({0});".format(json.dumps(id_))
@property