Skip to content
Snippets Groups Projects
Commit 897bc6ed authored by chbaeh's avatar chbaeh
Browse files

ODPSH-281: extend search for orgs

parent f22be2fd
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ import decorator ...@@ -4,7 +4,7 @@ import decorator
from ckan.controllers.home import HomeController from ckan.controllers.home import HomeController
from ckan.controllers.user import UserController from ckan.controllers.user import UserController
from ckan.controllers.api import ApiController from ckan.controllers.api import ApiController
from ckan.controllers.group import GroupController from ckan.controllers.organization import OrganizationController
from ckanext.harvest.controllers.view import ViewController as HarvestController from ckanext.harvest.controllers.view import ViewController as HarvestController
from ckan.controllers.feed import FeedController from ckan.controllers.feed import FeedController
from ckan.controllers.package import PackageController from ckan.controllers.package import PackageController
...@@ -98,79 +98,24 @@ class OdshPackageController(PackageController): ...@@ -98,79 +98,24 @@ class OdshPackageController(PackageController):
return super(OdshPackageController, self).edit_view(id, resource_id, view_id) return super(OdshPackageController, self).edit_view(id, resource_id, view_id)
class OdshGroupController(GroupController): class OdshGroupController(OrganizationController):
def index(self):
group_type = self._guess_group_type()
page = h.get_page_number(request.params) or 1
items_per_page = 21
context = {'model': model, 'session': model.Session, def _action(self, name):
'user': c.user, 'for_view': True,
'with_private': False}
query = c.q = request.params.get('q', '')
sort_by = c.sort_by_selected = request.params.get('sort')
try:
self._check_access('site_read', context)
self._check_access('group_list', context)
except NotAuthorized:
abort(403, _('Not authorized to see this page'))
# pass user info to context as needed to view private datasets of action = super(OdshGroupController, self)._action(name)
# orgs correctly
if c.userobj:
context['user_id'] = c.userobj.id
context['user_is_admin'] = c.userobj.sysadmin
def custom_org_list(context, data_dict):
query = data_dict['q']
result = action(context, data_dict)
for q in query.split(' '): for q in query.split(' '):
try: data_dict['q'] = q
data_dict_global_results = { result += action(context, data_dict)
'all_fields': False, return result
'q': q,
'sort': sort_by,
'type': group_type or 'group',
}
print("QUERY")
print(group_type)
print(q)
global_results = self._action('group_list')(
context, data_dict_global_results)
except ValidationError as e:
if e.error_dict and e.error_dict.get('message'):
msg = e.error_dict['message']
else:
msg = str(e)
h.flash_error(msg)
c.page = h.Page([], 0)
return render(self._index_template(group_type),
extra_vars={'group_type': group_type})
data_dict_page_results = {
'all_fields': True,
'q': q,
'sort': sort_by,
'type': group_type or 'group',
'limit': items_per_page,
'offset': items_per_page * (page - 1),
'include_extras': True
}
page_results = self._action('group_list')(context,
data_dict_page_results)
print("GROUPS")
print(global_results)
c.page = h.Page(
collection=global_results,
page=page,
url=h.pager_url,
items_per_page=items_per_page,
)
c.page.items = page_results
return render(self._index_template(group_type),
extra_vars={'group_type': group_type})
if name is 'group_list':
return custom_org_list
else:
return super(OdshGroupController, self)._action(name)
class OdshApiController(ApiController): class OdshApiController(ApiController):
def action(self, logic_function, ver=None): def action(self, logic_function, ver=None):
...@@ -287,16 +232,17 @@ def only_admin(func, *args, **kwargs): ...@@ -287,16 +232,17 @@ def only_admin(func, *args, **kwargs):
abort(404) abort(404)
return func(*args, **kwargs) return func(*args, **kwargs)
class MetaClass(type): class MetaClass(type):
def __new__(meta, classname, bases, classDict): def __new__(meta, classname, bases, classDict):
newClassDict = {} newClassDict = {}
wdec = decorator.decorator(only_admin) wdec = decorator.decorator(only_admin)
for attributeName, attribute in bases[0].__dict__.items(): for attributeName, attribute in bases[0].__dict__.items():
if isinstance(attribute, FunctionType) and not attributeName.startswith('_'): if isinstance(attribute, FunctionType) and not attributeName.startswith('_'):
print(attribute)
attribute = wdec(attribute) attribute = wdec(attribute)
newClassDict[attributeName] = attribute newClassDict[attributeName] = attribute
return type.__new__(meta, classname, bases, newClassDict) return type.__new__(meta, classname, bases, newClassDict)
class OdshHarvestController(HarvestController): class OdshHarvestController(HarvestController):
__metaclass__ = MetaClass # wrap all the methods __metaclass__ = MetaClass # wrap all the methods
...@@ -206,14 +206,11 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -206,14 +206,11 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
with SubMapper(map, controller='ckanext.odsh.controller:OdshFeedController') as m: with SubMapper(map, controller='ckanext.odsh.controller:OdshFeedController') as m:
m.connect('/feeds/custom.atom', action='custom') m.connect('/feeds/custom.atom', action='custom')
# with SubMapper(map, controller='ckanext.odsh.controller:OdshHarvestController') as m:
# m.connect('/harvest', action='index')
with SubMapper(map, controller='ckanext.odsh.controller:OdshPackageController') as m: with SubMapper(map, controller='ckanext.odsh.controller:OdshPackageController') as m:
m.connect('new_view', '/dataset/{id}/resource/{resource_id}/new_view', action='edit_view', ckan_icon='pencil-square-o') m.connect('new_view', '/dataset/{id}/resource/{resource_id}/new_view', action='edit_view', ckan_icon='pencil-square-o')
# with SubMapper(map, controller='ckanext.odsh.controller:OdshGroupController') as m: with SubMapper(map, controller='ckanext.odsh.controller:OdshGroupController') as m:
# m.connect('organizations_index', '/organization', action='index') m.connect('organizations_index', '/organization', action='index')
# redirect all user routes to custom controller # redirect all user routes to custom controller
with SubMapper(map, controller='ckanext.odsh.controller:OdshUserController') as m: with SubMapper(map, controller='ckanext.odsh.controller:OdshUserController') as m:
......
...@@ -104,7 +104,6 @@ def validate_licenseAttributionByText(key, data, errors,context): ...@@ -104,7 +104,6 @@ def validate_licenseAttributionByText(key, data, errors,context):
isByLicense = True isByLicense = True
break break
hasAttribution=False hasAttribution=False
print(Missing)
for k in data: for k in data:
if data[k] == 'licenseAttributionByText': if data[k] == 'licenseAttributionByText':
if isinstance(data[(k[0], k[1], 'value')], Missing) or (k[0], k[1], 'value') not in data: if isinstance(data[(k[0], k[1], 'value')], Missing) or (k[0], k[1], 'value') not in data:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment