Skip to main content

API and directive converting object to ``dict``.

Project description

https://travis-ci.org/rebeccaframework/rebecca.todict.png?branch=master

rebecca.todict

rebecca.todict is API and directive converting object to dict.

INSTALL

Install using pip or easy_install.:

$ pip install rebecca.todict
$ easy_install rebecca.todict

USAGE

rebecca.todict privides includeme hook that will set up set_todict directive.:

config.include('rebecca.todict')

using with paste deploy:

pyramid.includes = rebecca.todict

register todict adapter

by directive

To register todict adapter, you can use set_todict directive.:

config.set_todict(Person, person_to_dict)

That register todict adapter converging Person object to dict.

You can register named adapter too:

config.set_todict(Person, person_to_dict_short, name="short")

by todict_decorator

todict_decorator register todict Adapter casually.:

@todict_config(Person)
def person_to_dict(request, person):
    return dict(....)

using todict API

Registered adapters are used by todict API:

from rebecca.todict import todict

d = todict(request, person)
d = todict(request, person, name="short")

JSON Renderer using todict API

rebecca.todict.renderers.json_renderer_factory is factory of renderer using todict API.

to use this renderer, register renderer factory:

config.add_renderer('.json', 'rebecca.todict.renderers.json_renderer_factory')

specify “.json” renderer on view_config or add_view:

@view_config(renderer="short.json")
def person_list(request):
    return dict(people=[Person(), Person()])

the renderer use todict Adapters named “short”.

Contributors

  • Atsushi Odagiri, Original Author

Changelog

0.4 (2013-08-31)

  • fix conflict multi todict registration for the same name and different type

0.3 (2013-08-31)

  • fix conflict multi todict registration

0.2 (2013-03-02)

  • add json renderer using todict API

  • todict_config decorator

0.1 (2013-02-16)

first commit

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rebecca.todict-0.4.zip (8.1 kB view details)

Uploaded Source

File details

Details for the file rebecca.todict-0.4.zip.

File metadata

  • Download URL: rebecca.todict-0.4.zip
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rebecca.todict-0.4.zip
Algorithm Hash digest
SHA256 12223046614af19fd64db7baf190ecf6930f638228e57566683c5a0fefd8172b
MD5 4a488f9f874a841b0ce76657c637048a
BLAKE2b-256 9b5d8bee71d570ab5b448a6f9c8b8d874d7d2945b4803341cf7f73eb02019ef4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page