[ckan-dev] model VS context['model']

Vitor Baptista vitor at vitorbaptista.com
Mon Apr 15 20:36:45 UTC 2013


Hi,

Toby was reviewing a pull request I sent (
https://github.com/okfn/ckan/pull/754/files#r3791087) and an interesting
question came up. We thought that it would be better to start talking here
instead of in the PR. The code is:

def model_name_to_class(model_name):
>     try:
>         model_class_name = model_name.title()
>         return getattr(model, model_class_name)
>     except AttributeError:
>         raise ValidationError(_("%s isn't a valid model" % model_class_name))


Basically, this method turns a string into a class. For example, if you
call model_name_to_class('user'), you'd get ckan.model.User.

Toby suggested that instead of using model (from "import ckan.model as
model"), I should use context['model'], as they might be different somehow.

Does someone understand when it might happen, and why?

Cheers,
Vítor Baptista.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130415/513ae3f6/attachment.html>


More information about the ckan-dev mailing list