74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
#import logging
|
|
#from ckan.controllers.home import HomeController
|
|
from flask import Blueprint, render_template, g
|
|
import ckan.plugins as p
|
|
from ckan.common import _, g
|
|
import ckan.lib.search as search
|
|
import ckan.model as model
|
|
import ckan.logic as logic
|
|
import ckan.lib.helpers as h
|
|
from collections import OrderedDict
|
|
|
|
#blueprint definition
|
|
d4science_home = Blueprint("d4science_home", __name__)
|
|
|
|
#@d4science_home.route("/catalog")
|
|
@d4science_home.route("/")
|
|
def index():
|
|
try:
|
|
# package search
|
|
context = {'model': model, 'session': model.Session,'user': g.user, 'auth_user_obj': g.userobj}
|
|
|
|
facets = OrderedDict()
|
|
|
|
default_facet_titles = {
|
|
'organization': _('Organizations'),
|
|
'groups': _('Groups'),
|
|
'tags': _('Tags'),
|
|
'res_format': _('Formats'),
|
|
'license_id': _('Licenses'),
|
|
}
|
|
|
|
for facet in g.facets:
|
|
if facet in default_facet_titles:
|
|
facets[facet] = default_facet_titles[facet]
|
|
else:
|
|
facets[facet] = facet
|
|
|
|
# gestion filtri/facets
|
|
for plugin in p.PluginImplementations(p.IFacets):
|
|
facets = plugin.dataset_facets(facets, 'dataset')
|
|
|
|
g.facet_titles = facets
|
|
|
|
data_dict = {
|
|
'q': '*:*',
|
|
'facet.field': list(facets.keys()),
|
|
'rows': 4,
|
|
'start': 0,
|
|
'sort': 'views_recent desc',
|
|
'fq': 'capacity:"public"'
|
|
}
|
|
query = logic.get_action('package_search')(context, data_dict)
|
|
g.search_facets = query['search_facets']
|
|
g.package_count = query['count']
|
|
g.datasets = query['results']
|
|
|
|
#print "c.search_facets: "
|
|
#print " ".join(c.search_facets)
|
|
|
|
except search.SearchError:
|
|
g.package_count = 0
|
|
|
|
if g.userobj and not g.userobj.email:
|
|
url = h.url_for('user.edit')
|
|
msg = _('Please <a href="%s">update your profile</a>'
|
|
' and add your email address. ') % url + \
|
|
_('%s uses your email address'
|
|
' if you need to reset your password.') \
|
|
% g.site_title
|
|
h.flash_notice(msg, allow_html=True)
|
|
|
|
return render_template('home/index.html', cache_force=True)
|
|
|