Ticket #2409 (closed enhancement: fixed)

Opened 10 months ago

Last modified 7 months ago

Bring Back Generic Function JSON, Optionally

Reported by: cleverdevil Assigned to: jorge.vargas
Priority: normal Milestone: 2.1b1
Component: TurboGears Version: trunk
Severity: normal Keywords: json
Cc:

Description

Attached is a very simple patch which brings back the ability to define JSON rules externally using generic functions. Rather than being based upon PEAK-Rules, this code is based upon the much more documented and easy_installable simplegeneric, which at one point was considered for inclusion in the standard library. Unlike PEAK-Rules, simplegeneric only allows you to define very simple rules based upon types, rather than arbitrary rules with multiple conditions.

As you'll notice, the patch doesn't force people to install simplegeneric or use generic functions if they do not want to. The code falls back to the old behavior based upon the presence of simplegeneric.

Attachments

generic.diff (0.7 kB) - added by cleverdevil on 11/18/09 08:36:37.
test_jsonify_generic.py (2.2 kB) - added by cleverdevil on 11/20/09 09:08:44.

Change History

11/18/09 08:36:37 changed by cleverdevil

  • attachment generic.diff added.

11/19/09 20:32:58 changed by mramm

Looks reasonable to me. +1

Would be +10 if it came with tests that proved that it worked. ;)

11/20/09 09:08:18 changed by cleverdevil

I have attached some unit tests to make Mark approximately +9 happier :)

11/20/09 09:08:44 changed by cleverdevil

  • attachment test_jsonify_generic.py added.

11/29/09 14:49:03 changed by percious

im -1 on this.

I think we should add a new renderer that supports this, like 'json_generic' or something.

11/29/09 15:39:39 changed by cleverdevil

Any particular reason for you to be -1? Unless you have a patch which provides the same functionality in a demonstrably better way, I say its time to put this in. The code is simple, short, is totally optional, and brings back a capability that some people (including myself) relied upon in TG 1.x without introducing a whole new package or additional complexity. I've not heard a single good argument against it.

11/30/09 10:33:37 changed by mramm

I remain +10 on this. The feature is actually used not just by jonathan, and I think that the optional nature of simplegeneric extensibility makes this a no brainer in terms of backwards compatibility, and it provides an easy way to gather your rules on how to jsonify objects in a particular place.

11/30/09 10:52:21 changed by percious

What I don't like about it is the solution. I don't really like using import to determine functionality. I did this with tgext.admin and dojo and had to go back and re-engineer around it because it was too inflexible. I _like_ the idea of adding this functionality, but not in this way. This is why I suggested adding a new renderer called json_generic that would provide this functionality without stomping existing functionality, or using a conditional import. I'd hate to have to tell people to "uninstall" generics because there is no easy_uninstall.

12/01/09 21:27:58 changed by jorge.vargas

Sorry for being so late to this party. I have been to busy to take a good look at this.

I agree with mramm and cleverdevil that this patch is good enough. However I do agree with percious that "if it's installed use it" is not the best way to have an optional dependency.

That said the only other way I see we could implement this is with a flag in app_cfg to turn on generic functions for json, which I know percious dislikes even more. Therefore unless there is a concrete objection (with an alternative patch) I'm going to apply this next time I work on TG code.

12/01/09 21:28:06 changed by jorge.vargas

  • owner set to jorge.vargas.

01/26/10 20:26:50 changed by percious

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

01/26/10 20:27:08 changed by percious

  • milestone changed from 2.1b2 to 2.1b1.