[ckan-dev] Most Recent Dataset
Fabrizio Fornari
ckanappoggio at gmail.com
Mon May 5 09:10:20 UTC 2014
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?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140505/af5a4a88/attachment-0003.html>
More information about the ckan-dev
mailing list