mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 09:13:14 +00:00
add DocumentChooserBlock
This commit is contained in:
parent
628b7947dc
commit
76b0964c94
2 changed files with 24 additions and 2 deletions
23
wagtail/wagtaildocs/blocks.py
Normal file
23
wagtail/wagtaildocs/blocks.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.html import format_html
|
||||
|
||||
from wagtail.wagtailadmin.blocks import ChooserBlock
|
||||
|
||||
class DocumentChooserBlock(ChooserBlock):
|
||||
@cached_property
|
||||
def target_model(self):
|
||||
from wagtail.wagtaildocs.models import Document
|
||||
return Document
|
||||
|
||||
@cached_property
|
||||
def widget(self):
|
||||
from wagtail.wagtaildocs.widgets import AdminDocumentChooser
|
||||
return AdminDocumentChooser
|
||||
|
||||
def render_basic(self, value):
|
||||
if value:
|
||||
return format_html('<a href="{0}">{1}</a>', value.url, value.title)
|
||||
else:
|
||||
return ''
|
||||
|
|
@ -14,10 +14,9 @@ class AdminDocumentChooser(AdminChooser):
|
|||
choose_another_text = _('Choose another document')
|
||||
|
||||
def render_html(self, name, value, attrs):
|
||||
instance, value = self.get_instance_and_id(Document, value)
|
||||
original_field_html = super(AdminDocumentChooser, self).render_html(name, value, attrs)
|
||||
|
||||
instance = self.get_instance(Document, value)
|
||||
|
||||
return render_to_string("wagtaildocs/widgets/document_chooser.html", {
|
||||
'widget': self,
|
||||
'original_field_html': original_field_html,
|
||||
|
|
|
|||
Loading…
Reference in a new issue