[ckan-dev] package_dictize() vs pkg.as_dict()
Sean Hammond
sean.hammond at okfn.org
Wed Apr 25 16:54:03 UTC 2012
> I notice that we have two methods for converting a package to a dict.
>
> model.Package has a as_dict() method that returns a dict
>
> package_dictize(pkg) also converts a package to a dict
>
> The main differences seem to be that as_dict() just returns limited (name
> only for groups/tags) groups/tags/extras where as package_dictize returns
> the fuller data. I think the resources are the same but that needs
> confirming.
>
> renamed fields
> --------------------
> licence -> license_title
>
> in pkg.as_dict only
> -------------------------
> 'ckan_url'
> 'notes_rendered'
> 'ratings_average'
> 'ratings_count'
> 'relationships':
>
> in package_dictize only
> -------------------------
> 'relationships_as_object'
> 'relationships_as_subject'
> 'revision_timestamp'
>
> Also as_dict returns keys as strings model_dictize uses unicode keys
>
> I'm not a fan of code duplication so it'd be nice if we could merge these
> together maybe by adding some extra keywords/context options if needed.
>
> What do people think about this?
I think that as_dict() methods are the old way and are deprecated now in
favor of model_dictize. Maybe the as_dict methods can be deleted (and
any code using them updated) rather than merging?
I think I recall using table_dictize when I wanted to get more limited
data (e.g. not recursing into lists of resources etc.)
More information about the ckan-dev
mailing list