mirror of
https://github.com/evennia/evennia.git
synced 2026-04-05 15:37:17 +02:00
Use renderer kwarg for picklefield widget; related to #1843
This commit is contained in:
parent
cdd9ca28f7
commit
f8e5bca820
1 changed files with 14 additions and 5 deletions
|
|
@ -107,8 +107,9 @@ def dbsafe_decode(value, compress_object=False):
|
|||
|
||||
|
||||
class PickledWidget(Textarea):
|
||||
def render(self, name, value, attrs=None):
|
||||
def render(self, name, value, attrs=None, renderer=None):
|
||||
"""Display of the PickledField in django admin"""
|
||||
|
||||
value = repr(value)
|
||||
try:
|
||||
# necessary to convert it back after repr(), otherwise validation errors will mutate it
|
||||
|
|
@ -121,11 +122,18 @@ class PickledWidget(Textarea):
|
|||
attrs["name"] = name
|
||||
else:
|
||||
attrs = {"name": name}
|
||||
attrs['cols'] = 30
|
||||
# adapt rows to width
|
||||
rows = 1
|
||||
if isinstance(value, str) and "\n" in value:
|
||||
rows = max(1, len(value.split('\n')))
|
||||
attrs['rows'] = rows
|
||||
attrs = self.build_attrs(attrs)
|
||||
|
||||
final_attrs = self.build_attrs(attrs)
|
||||
return format_html('<textarea{0}>\r\n{1}</textarea>',
|
||||
flatatt(final_attrs),
|
||||
value)
|
||||
return super().render(name, value, attrs=attrs, renderer=renderer)
|
||||
# return format_html('<textarea{0}>\r\n{1}</textarea>',
|
||||
# flatatt(final_attrs),
|
||||
# value)
|
||||
|
||||
|
||||
class PickledFormField(CharField):
|
||||
|
|
@ -138,6 +146,7 @@ class PickledFormField(CharField):
|
|||
"surrounded by quote marks. We have converted it to a string for your "
|
||||
"convenience. If it is acceptable, please hit save again.")
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# This needs to fall through to literal_eval.
|
||||
kwargs['required'] = False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue