Add CodeTextAreaFieldRenderer
, refactor label profile form to use it
This commit is contained in:
parent
a093b84c98
commit
fdf1419ea2
|
@ -28,7 +28,7 @@ from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from .core import CustomFieldRenderer, DateFieldRenderer
|
from .core import CustomFieldRenderer, DateFieldRenderer
|
||||||
|
|
||||||
from .common import (StrippedTextFieldRenderer, AutocompleteFieldRenderer,
|
from .common import (StrippedTextFieldRenderer, CodeTextAreaFieldRenderer, AutocompleteFieldRenderer,
|
||||||
DecimalFieldRenderer, CurrencyFieldRenderer,
|
DecimalFieldRenderer, CurrencyFieldRenderer,
|
||||||
DateTimeFieldRenderer, DateTimePrettyFieldRenderer, TimeFieldRenderer,
|
DateTimeFieldRenderer, DateTimePrettyFieldRenderer, TimeFieldRenderer,
|
||||||
EnumFieldRenderer, YesNoFieldRenderer)
|
EnumFieldRenderer, YesNoFieldRenderer)
|
||||||
|
|
|
@ -36,6 +36,7 @@ import formalchemy
|
||||||
from formalchemy import helpers
|
from formalchemy import helpers
|
||||||
from formalchemy.fields import FieldRenderer, SelectFieldRenderer, CheckBoxFieldRenderer
|
from formalchemy.fields import FieldRenderer, SelectFieldRenderer, CheckBoxFieldRenderer
|
||||||
from pyramid.renderers import render
|
from pyramid.renderers import render
|
||||||
|
from webhelpers.html import HTML
|
||||||
|
|
||||||
from tailbone.util import pretty_datetime, raw_datetime
|
from tailbone.util import pretty_datetime, raw_datetime
|
||||||
|
|
||||||
|
@ -52,6 +53,19 @@ class StrippedTextFieldRenderer(formalchemy.TextFieldRenderer):
|
||||||
return value.strip()
|
return value.strip()
|
||||||
|
|
||||||
|
|
||||||
|
class CodeTextAreaFieldRenderer(formalchemy.TextAreaFieldRenderer):
|
||||||
|
|
||||||
|
def render_readonly(self, **kwargs):
|
||||||
|
value = self.raw_value
|
||||||
|
if not value:
|
||||||
|
return ''
|
||||||
|
return HTML.tag('pre', c=value)
|
||||||
|
|
||||||
|
def render(self, **kwargs):
|
||||||
|
kwargs.setdefault('size', (80, 8))
|
||||||
|
return super(CodeTextAreaFieldRenderer, self).render(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
class AutocompleteFieldRenderer(FieldRenderer):
|
class AutocompleteFieldRenderer(FieldRenderer):
|
||||||
"""
|
"""
|
||||||
Custom renderer for an autocomplete field.
|
Custom renderer for an autocomplete field.
|
||||||
|
|
|
@ -28,8 +28,6 @@ from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
|
||||||
import formalchemy
|
|
||||||
from webhelpers.html import HTML
|
|
||||||
from pyramid.httpexceptions import HTTPFound
|
from pyramid.httpexceptions import HTTPFound
|
||||||
|
|
||||||
from tailbone import forms
|
from tailbone import forms
|
||||||
|
@ -38,19 +36,6 @@ from tailbone.views import MasterView
|
||||||
from tailbone.views.continuum import VersionView, version_defaults
|
from tailbone.views.continuum import VersionView, version_defaults
|
||||||
|
|
||||||
|
|
||||||
class FormatFieldRenderer(formalchemy.TextAreaFieldRenderer):
|
|
||||||
|
|
||||||
def render_readonly(self, **kwargs):
|
|
||||||
value = self.raw_value
|
|
||||||
if not value:
|
|
||||||
return ''
|
|
||||||
return HTML.tag('pre', c=value)
|
|
||||||
|
|
||||||
def render(self, **kwargs):
|
|
||||||
kwargs.setdefault('size', (80, 8))
|
|
||||||
return super(FormatFieldRenderer, self).render(**kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class ProfilesView(MasterView):
|
class ProfilesView(MasterView):
|
||||||
"""
|
"""
|
||||||
Master view for the LabelProfile model.
|
Master view for the LabelProfile model.
|
||||||
|
@ -73,7 +58,7 @@ class ProfilesView(MasterView):
|
||||||
def configure_fieldset(self, fs):
|
def configure_fieldset(self, fs):
|
||||||
fs.printer_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer)
|
fs.printer_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer)
|
||||||
fs.formatter_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer)
|
fs.formatter_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer)
|
||||||
fs.format.set(renderer=FormatFieldRenderer)
|
fs.format.set(renderer=forms.renderers.CodeTextAreaFieldRenderer)
|
||||||
fs.configure(
|
fs.configure(
|
||||||
include=[
|
include=[
|
||||||
fs.ordinal,
|
fs.ordinal,
|
||||||
|
|
Loading…
Reference in a new issue