define HeadingBlock to demonstrate the principle of providing renderings for non-smart values

This commit is contained in:
Matt Westcott 2015-01-20 00:32:24 +00:00
parent 5698a0368a
commit f6d504032b

View file

@ -11,7 +11,7 @@ from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.deconstruct import deconstructible
from django.utils.functional import cached_property
from django.template.loader import render_to_string
from django.forms import Media
from django.forms import Media, CharField
from django.forms.utils import ErrorList
import six
@ -270,6 +270,14 @@ class FieldBlock(Block):
def clean(self, value):
return self.field.clean(value)
class HeadingBlock(FieldBlock):
def __init__(self, tag_name='h1', **kwargs):
self.tag_name = tag_name
super(HeadingBlock, self).__init__(CharField(), **kwargs)
def render(self, value):
return format_html("<{tag}>{value}</{tag}>", tag=self.tag_name, value=value)
# =======
# Chooser
# =======