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 .common import (StrippedTextFieldRenderer, AutocompleteFieldRenderer,
|
||||
from .common import (StrippedTextFieldRenderer, CodeTextAreaFieldRenderer, AutocompleteFieldRenderer,
|
||||
DecimalFieldRenderer, CurrencyFieldRenderer,
|
||||
DateTimeFieldRenderer, DateTimePrettyFieldRenderer, TimeFieldRenderer,
|
||||
EnumFieldRenderer, YesNoFieldRenderer)
|
||||
|
|
|
@ -36,6 +36,7 @@ import formalchemy
|
|||
from formalchemy import helpers
|
||||
from formalchemy.fields import FieldRenderer, SelectFieldRenderer, CheckBoxFieldRenderer
|
||||
from pyramid.renderers import render
|
||||
from webhelpers.html import HTML
|
||||
|
||||
from tailbone.util import pretty_datetime, raw_datetime
|
||||
|
||||
|
@ -52,6 +53,19 @@ class StrippedTextFieldRenderer(formalchemy.TextFieldRenderer):
|
|||
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):
|
||||
"""
|
||||
Custom renderer for an autocomplete field.
|
||||
|
|
|
@ -28,8 +28,6 @@ from __future__ import unicode_literals, absolute_import
|
|||
|
||||
from rattail.db import model
|
||||
|
||||
import formalchemy
|
||||
from webhelpers.html import HTML
|
||||
from pyramid.httpexceptions import HTTPFound
|
||||
|
||||
from tailbone import forms
|
||||
|
@ -38,19 +36,6 @@ from tailbone.views import MasterView
|
|||
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):
|
||||
"""
|
||||
Master view for the LabelProfile model.
|
||||
|
@ -73,7 +58,7 @@ class ProfilesView(MasterView):
|
|||
def configure_fieldset(self, fs):
|
||||
fs.printer_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(
|
||||
include=[
|
||||
fs.ordinal,
|
||||
|
|
Loading…
Reference in a new issue