mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 09:13:14 +00:00
Merge branch 'feature/streamfield' of github.com:torchbox/wagtail into feature/streamfield
This commit is contained in:
commit
f06e2450ce
4 changed files with 44 additions and 5 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,
|
||||
|
|
|
|||
17
wagtail/wagtailsnippets/blocks.py
Normal file
17
wagtail/wagtailsnippets/blocks.py
Normal 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)
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue