add DocumentChooserBlock

This commit is contained in:
Matt Westcott 2015-02-11 12:20:32 +00:00
parent 628b7947dc
commit 76b0964c94
2 changed files with 24 additions and 2 deletions

View 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 ''

View file

@ -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,