Opened 19 years ago

Closed 19 years ago

#549 closed enhancement (wontfix)

StaticField formfield

Reported by: pspierce@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (3)

comment:1 by robert@…, 19 years ago

Why not just shove manipulator.original_object.componentnum into your Context?

Or if using generic views, just use {{ object.componentnum }} . ( this is set in the generic update form )

Although it could be annoying in the admin that non editable fields are totally invisible.... ( as their value may still have some meaning to the user.)

comment:2 by pspierce@…, 19 years ago

Because I am looping through a formfieldcollection and need to insure that I am referencing the same dict as the row within the form. Yes, I could still do it this way w/ a templatetag or via context but it would be a pain to do and error prone due to complexity.

comment:3 by Adrian Holovaty, 19 years ago

Resolution: wontfix
Status: newclosed

I don't see a need for this; having a formfield that doesn't actually render a form element seems beyond the scope of the formfields library.

Note: See TracTickets for help on using tickets.
Back to Top