[ckan-dev] Most Recent Dataset

Fabrizio Fornari ckanappoggio at gmail.com
Tue May 6 12:45:54 UTC 2014


Yes, it should be that one the problem but I can't figure out which is the
right structure that I should use...


On Mon, May 5, 2014 at 4:54 PM, Stéphane Guidoin <stephane at opennorth.ca>wrote:

> I might be wrong but the query returns a structure that is more than just
> the packages. The packages is a substructure named "results".
>
> snippets/package_list.html expects to receive only the results, not the
> full result of the query. Passing the invalid structure might trigger the
> error message you received.
>
> Stéphane
>
>
> On Mon, May 5, 2014 at 5:10 AM, Fabrizio Fornari <ckanappoggio at gmail.com>wrote:
>
>> basically, how can I pass argument to package_list.html? It seems that
>> this way doesn't work. In snippets/package_list.html it says  that the
>> format should be:
>>
>> {% snippet 'snippets/package_list.html', packages=c.datasets %}
>>
>> and that "packages is a list of packages to display."
>>
>> It seems to me that I should do something like:
>> plugins.toolkit.render_snippet('snippets/package_list.html',
>> packages=myListOfPackages)
>>
>> but it still gives me Error - <type 'exceptions.ValueError'>: invalid
>> literal for int() with base 10: ''; what should I assign to
>> myListOfPackages?
>>
>>
>>
>> On Sat, May 3, 2014 at 1:50 PM, Fabrizio Fornari <ckanappoggio at gmail.com>wrote:
>>
>>> Hi guys,
>>>
>>> I am running ckan 2.2 and I was trying to display in the home page of
>>> ckan a list of the most recent datasets. I found an example of this at
>>> here<https://github.com/anibalpacheco/ckanext-agesic/blob/9addb1fc964637997f18780a9a6f10db6814f0a2/ckanext/agesic/plugin.py> then
>>> I tried to modify one of my extension to add this feature.
>>> The problem is that I get the error: Error - <type
>>> 'exceptions.ValueError'>: invalid literal for int() with base 10: '' and I
>>> don't know how to solve it.
>>>
>>> I added the following lines to the file plugin.py of my extension:
>>>
>>> from ckan.model import Session, Package
>>>
>>> plugins.implements(plugins.ITemplateHelpers)
>>>
>>> def most_recent(self):
>>>     """
>>>     Most recent datasets, based on the metadata_modified attr.
>>>     Return HTML that can be rendered in the templates calling
>>>     {{ h.most_recent() }}
>>>     """
>>>     packages = []
>>>     for package in Session.query(Package).filter(Package.state ==
>>> 'active',
>>>             Package.private == False).order_by(
>>>             Package.metadata_modified.desc()).limit(4):
>>>         packages.append(package.as_dict())
>>>     data = {'packages': packages, 'list_class': "unstyled
>>> dataset-list",'item_class': "dataset-item module-content", 'truncate': 120,
>>> 'hide_resources': True}
>>>     return plugins.toolkit.render_snippet('snippets/package_list.html',
>>> data)
>>>
>>> def get_helpers(self):
>>>     return {'most_recent': self.most_recent}
>>>
>>> Then in a html file I used {{ h.most_recent() }} to execute the
>>> function. The problem seems to be with the row  "return
>>> plugins.toolkit.render_snippet('snippets/package_list.html', data)" because
>>> I printed the variable "data" and It displays the correct values but it
>>> gives me Error - <type 'exceptions.ValueError'>: invalid literal for int()
>>> with base 10: ''.
>>>
>>> Do you know what may cause this error?
>>>
>>>
>>
>> _______________________________________________
>> ckan-dev mailing list
>> ckan-dev at lists.okfn.org
>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>
>>
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140506/df75316a/attachment-0003.html>


More information about the ckan-dev mailing list