[ckan-dev] Most Recent Dataset

Fabrizio Fornari ckanappoggio at gmail.com
Wed May 7 14:16:14 UTC 2014


Thank you for showing me an alternative!


On Tue, May 6, 2014 at 4:24 PM, Stéphane Guidoin <stephane at opennorth.ca>wrote:

> I guess you could pass myListOfPackages.results to the snippet. If it
> does not work, you could start by trying a more simple case and build on
> its. Here is a simple case where the package search is called directly in
> the template without any snippet. From there you can build on and add
> snippets and more this outside of the templates.
>
>
> https://github.com/CityofSurrey/ckanext-surrey/blob/master/ckanext/surrey/templates/home/snippets/featured_popular.html
>
>
> On Tue, May 6, 2014 at 8:45 AM, Fabrizio Fornari <ckanappoggio at gmail.com>wrote:
>
>> 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
>>>
>>>
>>
>> _______________________________________________
>> 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
>>
>>
>
>
> --
> Stéphane Guidoin
> Director, Transportation
> Open North
> 514-862-0084
> http://opennorth.ca
> Twitter: @opennorth / @hoedic
>
> _______________________________________________
> 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/20140507/88f68508/attachment-0003.html>


More information about the ckan-dev mailing list