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

Vitor Baptista vitor at vitorbaptista.com
Tue May 28 21:07:52 UTC 2013


Ping.

Any feedback on this?


2013/4/22 Toby Dacre <toby.okfn at gmail.com>

>
>
> On 15 April 2013 22:20, Toby Dacre <toby.okfn at gmail.com> wrote:
>
>>
>>
>> On 15 April 2013 21:36, Vitor Baptista <vitor at vitorbaptista.com> wrote:
>>
>>> 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?
>>>
>>>
>> Just to add that this function is used in an action or auth function so
>> we were given context and data_dict
>>
>>
>
> Some feedback on this issue would be good
>
> @kindly any views?
>
>
>
>> Cheers,
>>> Vítor Baptista.
>>>
>>> _______________________________________________
>>> ckan-dev mailing list
>>> ckan-dev at lists.okfn.org
>>> http://lists.okfn.org/mailman/listinfo/ckan-dev
>>> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>>>
>>>
>>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>
>


-- 

Vítor Baptista

Developer  |  http://vitorbaptista.com |
LinkedIn<http://www.linkedin.com/in/vitorbaptista>|
@vitorbaptista <http://twitter.com/vitorbaptista>

The Open Knowledge Foundation <http://okfn.org>

Empowering through Open Knowledge

http://okfn.org/  |  @okfn <http://twitter.com/okfn>  |  OKF on
Facebook<https://www.facebook.com/OKFNetwork> |
Blog <http://blog.okfn.org/>  |  Newsletter<http://okfn.org/about/newsletter/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130528/986bdf95/attachment.html>


More information about the ckan-dev mailing list