Django

Code

Ticket #1049 (closed: fixed)

Opened 3 years ago

Last modified 1 year ago

custom manipulators don't work with generic views due to lack of flatten_data

Reported by: wojtek@brandlay.com Assigned to: adrian
Milestone: Component: Documentation
Version: Keywords: MESSAGE
Cc: london Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Custom manipulators don't have the flatten_data method which is used in generic views - should it be in the formfields.Manipulator object or how to define it (or is it not needed?)

Attachments

Change History

02/26/07 16:21:56 changed by Gary Wilson <gary.wilson@gmail.com>

  • status changed from new to closed.
  • resolution set to wontfix.

newforms obsoletes manipulators, so this is probably not going to be worth fixing.

03/05/07 09:18:50 changed by Gary Wilson <gary.wilson@gmail.com>

  • status changed from closed to reopened.
  • resolution deleted.
  • stage changed from Unreviewed to Accepted.

Actually, I'm going to re-open this in case someone would like to fix it since I believe it is a bug. It can be closed once newforms is actually getting used for the generic views. It seems possible that a flatten_data() could be added to the Manipulator class, but it could not just be the version from the AutomaticManipulator class since that accesses attributes only available for AutomaticManipulator instances. Perhaps it just needs to call flatten_data on each field.

If you would like to see this, then please submit a patch and tests.

I have added this as a Manipulator ticket to track on the FeatureGrouping page.

(follow-up: ↓ 4 ) 03/05/07 13:52:14 changed by Michael Radziej <mir@noris.de>

  • component changed from Metasystem to Documentation.

I don't see the issue. You simply define your flatten_data method for your custom manipulator. Perhaps this should be documented (but it's a bit late). Here's a simple example:

    def flatten_data(self):
        obj = self.original_object
        return dict(
            name = obj.name,
            hardware_id = obj.hardware_id,
            ip = obj.ip and obj.ip.ipaddr_display(),
            ...
            )

(in reply to: ↑ 3 ) 03/11/07 17:57:53 changed by Gary Wilson <gary.wilson@gmail.com>

Replying to Michael Radziej <mir@noris.de>:

You simply define your flatten_data method for your custom manipulator.

Yes, you could do that too, but it could also be done more generally. Something like calling field.flatten_data() for each field in the manipulator maybe.

03/12/07 07:38:56 changed by mtredinnick

We should not be adding any more code to manipulators at this point in time. I will commit a docs patch describing how to do write a flatten_data function as Michael describes.

03/12/07 07:40:03 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [4711]) Fixed #1049 -- Documented the need to implement flatten_data() in some cases for custom ChangeManipulator? replacements. Thanks, Michael Radziej.

03/12/07 07:42:46 changed by mtredinnick

Aah .. only after the fact do I realise that Gary's comment #4 could be interpreted not as a code change but an alternative, also valid, approach to the problem.

Not to worry too much, since this is advanced and not overly common usage (if you're using custom manipulators in conjunction with generic views, you presumably have enough programming experience to realise there are alternatives) for a feature with limited life expectancy. What we've got now should work.

09/17/07 06:53:09 changed by hiutopor

  • cc set to london.
  • keywords set to MESSAGE.

Hi all! Very interesting information! Thanks! G'night


Add/Change #1049 (custom manipulators don't work with generic views due to lack of flatten_data)




Change Properties
Action