Merge branch 'feature/streamfield' of github.com:torchbox/wagtail into feature/streamfield

This commit is contained in:
Dave Cranwell 2015-02-11 12:52:31 +00:00
commit f06e2450ce
4 changed files with 44 additions and 5 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,

View file

@ -0,0 +1,17 @@
from __future__ import unicode_literals
from django.utils.functional import cached_property
from django.contrib.contenttypes.models import ContentType
from wagtail.wagtailadmin.blocks import ChooserBlock
class SnippetChooserBlock(ChooserBlock):
def __init__(self, target_model, **kwargs):
super(SnippetChooserBlock, self).__init__(**kwargs)
self.target_model = target_model
@cached_property
def widget(self):
from wagtail.wagtailsnippets.widgets import AdminSnippetChooser
content_type = ContentType.objects.get_for_model(self.target_model)
return AdminSnippetChooser(content_type)

View file

@ -22,10 +22,10 @@ class AdminSnippetChooser(AdminChooser):
self.target_content_type = content_type
def render_html(self, name, value, attrs):
original_field_html = super(AdminSnippetChooser, self).render_html(name, value, attrs)
model_class = self.target_content_type.model_class()
instance = self.get_instance(model_class, value)
instance, value = self.get_instance_and_id(model_class, value)
original_field_html = super(AdminSnippetChooser, self).render_html(name, value, attrs)
return render_to_string("wagtailsnippets/widgets/snippet_chooser.html", {
'widget': self,