|Reported by:||Owned by:||Adrian Holovaty|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Hugo recommended something similar but on a "per form" level. However, I would like to see a StaticField form field. The field would simply return the data when rendered. Here is a use case.
I work for Bertelsmann and run a program that creates replacements for Books On Tape and Random House audio for their product line that is sold to libraries. Audio books have several components. The schema has a parent table called "product" with a child table "component." The components are designated, component #1, component #2.... componentnum is set to editable=false in the model. This causes a problem when using manipulators in that the editable field does not come through as it is not editable and is therefore not in the 'form' context variable. I need this field to properly label the rows when editing and need them in the proper context of the form as they are labels. I have added a StaticField in formfields.py for my own use and it works fine subclassing the manipulators to add it. What I am requesting is:
#1 a StaticField
class StaticField(FormField): def __init__(self, field_name): self.field_name = field_name def render(self, data): if data is None: data = '' if isinstance(data, unicode): data = data.encode('utf-8') return data def html2python(data): return data html2python = staticmethod(html2python)
#2 Have manipulators return editable=false fields as StaticFields. I haven't implemented this yet but am planning on doing it soon and currently have just changed those editable=false fields that I need to editable but change their field to StaticFields.
If this ticket is rejected, I will implement it for myself; however, if there is a way to implement this and I have overlooked it, I would be appreciative for some direction on how to do it.