[ckan-dev] Most Recent Dataset

Fabrizio Fornari ckanappoggio at gmail.com
Sat May 3 11:50:55 UTC 2014


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/20140503/5d8344b6/attachment-0002.html>


More information about the ckan-dev mailing list