ckanext-scheming icon indicating copy to clipboard operation
ckanext-scheming copied to clipboard

How to add group as a field in my schema?

Open MandanaMoshref opened this issue 5 years ago • 1 comments

Hi all,

I need your help. I need to have group as a field in my schema. It means that the dataset creator should attach the group while creating the dataset. I assume there are some difficulties such as auth for group and so on. Lets for now assume that sysadmin is inserting all datasets. I assume its should work like organisation.

My case is that the user should obligatory attache 2 group values to a dataset. So it should happen during the creation otherwise the dataset shouldn't be created when the groups are not attached.

How does that work in scheming? is there any function that I can use for calling the list of groups? And if yes then how assignment of the groups should work?

I am sorry but I am not very good at programming and have little knowledge about CKAN. I do appreciate your help.

Best regards Mani

MandanaMoshref avatar Aug 20 '19 19:08 MandanaMoshref

So I tried to do some manipulation of the code. not successful of course. But have some question:

Is it at all possible to attach the group to the dataset (or package) when the dataset is not yet in the db?

I create group.html and placed it in the form_snippets folder. I also added the field to my schema.json sth like this:

{ "field_name": "group", "label": "Groups", "form_snippet": "group.html" },

It fetches the group values and then adds it as an additional field.

I played a bit with code change the name to "groups" which turned to the error [Wed Aug 21 17:51:59.034430 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] Error - <type 'exceptions.AttributeError'>: 'unicode' object has no attribute 'get' [Wed Aug 21 17:51:59.035003 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] URL: http://10.162.246.199/dataset_extension/new [Wed Aug 21 17:51:59.035012 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/weberror/errormiddleware.py', line 171 in __call__ [Wed Aug 21 17:51:59.035015 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] app_iter = self.application(environ, sr_checker) [Wed Aug 21 17:51:59.035017 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/webob/dec.py', line 147 in __call__ [Wed Aug 21 17:51:59.035019 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] resp = self.call_func(req, *args, **self.kwargs) [Wed Aug 21 17:51:59.035021 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/webob/dec.py', line 208 in call_func [Wed Aug 21 17:51:59.035023 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return self.func(req, *args, **kwargs) [Wed Aug 21 17:51:59.035025 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/fanstatic/publisher.py', line 234 in __call__ [Wed Aug 21 17:51:59.035027 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return request.get_response(self.app) [Wed Aug 21 17:51:59.035030 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/webob/request.py', line 1053 in get_response [Wed Aug 21 17:51:59.035032 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] application, catch_exc_info=False) [Wed Aug 21 17:51:59.035034 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/webob/request.py', line 1022 in call_application [Wed Aug 21 17:51:59.035036 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] app_iter = application(self.environ, start_response) [Wed Aug 21 17:51:59.035038 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/webob/dec.py', line 147 in __call__ [Wed Aug 21 17:51:59.035040 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] resp = self.call_func(req, *args, **self.kwargs) [Wed Aug 21 17:51:59.035052 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/webob/dec.py', line 208 in call_func [Wed Aug 21 17:51:59.035054 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return self.func(req, *args, **kwargs) [Wed Aug 21 17:51:59.035056 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/fanstatic/injector.py', line 54 in __call__ [Wed Aug 21 17:51:59.035058 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] response = request.get_response(self.app) [Wed Aug 21 17:51:59.035061 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/webob/request.py', line 1053 in get_response [Wed Aug 21 17:51:59.035063 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] application, catch_exc_info=False) [Wed Aug 21 17:51:59.035065 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/webob/request.py', line 1022 in call_application [Wed Aug 21 17:51:59.035067 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] app_iter = application(self.environ, start_response) [Wed Aug 21 17:51:59.035069 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/config/middleware/pylons_app.py', line 265 in inner [Wed Aug 21 17:51:59.035071 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] result = application(environ, start_response) [Wed Aug 21 17:51:59.035073 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/beaker/middleware.py', line 73 in __call__ [Wed Aug 21 17:51:59.035075 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return self.app(environ, start_response) [Wed Aug 21 17:51:59.035077 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/beaker/middleware.py', line 156 in __call__ [Wed Aug 21 17:51:59.035080 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return self.wrap_app(environ, session_start_response) [Wed Aug 21 17:51:59.035082 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/routes/middleware.py', line 131 in __call__ [Wed Aug 21 17:51:59.035084 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] response = self.app(environ, start_response) [Wed Aug 21 17:51:59.035086 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/config/middleware/common_middleware.py', line 30 in __call__ [Wed Aug 21 17:51:59.035088 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return self.app(environ, start_response) [Wed Aug 21 17:51:59.035090 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/config/middleware/common_middleware.py', line 56 in __call__ [Wed Aug 21 17:51:59.035092 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return self.app(environ, start_response) [Wed Aug 21 17:51:59.035094 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/wsgiapp.py', line 125 in __call__ [Wed Aug 21 17:51:59.035097 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] response = self.dispatch(controller, environ, start_response) [Wed Aug 21 17:51:59.035099 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/wsgiapp.py', line 324 in dispatch [Wed Aug 21 17:51:59.035103 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return controller(environ, start_response) [Wed Aug 21 17:51:59.035106 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/lib/base.py', line 240 in __call__ [Wed Aug 21 17:51:59.035108 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] res = WSGIController.__call__(self, environ, start_response) [Wed Aug 21 17:51:59.035110 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/controllers/core.py', line 221 in __call__ [Wed Aug 21 17:51:59.035112 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] response = self._dispatch_call() [Wed Aug 21 17:51:59.035114 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/controllers/core.py', line 172 in _dispatch_call [Wed Aug 21 17:51:59.035116 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] response = self._inspect_call(func) [Wed Aug 21 17:51:59.035118 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/controllers/core.py', line 107 in _inspect_call [Wed Aug 21 17:51:59.035120 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] result = self._perform_call(func, args) [Wed Aug 21 17:51:59.035122 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/lib/python2.7/site-packages/pylons/controllers/core.py', line 60 in _perform_call [Wed Aug 21 17:51:59.035125 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return func(**args) [Wed Aug 21 17:51:59.035127 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/controllers/package.py', line 525 in new [Wed Aug 21 17:51:59.035129 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] return self._save_new(context, package_type=package_type) [Wed Aug 21 17:51:59.035131 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/controllers/package.py', line 928 in _save_new [Wed Aug 21 17:51:59.035133 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] pkg_dict = get_action('package_create')(context, data_dict) [Wed Aug 21 17:51:59.035135 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/logic/__init__.py', line 464 in wrapped [Wed Aug 21 17:51:59.035137 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] result = _action(context, data_dict, **kw) [Wed Aug 21 17:51:59.035139 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/logic/action/create.py', line 191 in package_create [Wed Aug 21 17:51:59.035141 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] pkg = model_save.package_dict_save(data, context) [Wed Aug 21 17:51:59.035144 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/lib/dictization/model_save.py', line 291 in package_dict_save [Wed Aug 21 17:51:59.035146 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] package_membership_list_save(pkg_dict.get("groups"), pkg, context) [Wed Aug 21 17:51:59.035148 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] File '/usr/lib/ckan/default/src/ckan/ckan/lib/dictization/model_save.py', line 200 in package_membership_list_save [Wed Aug 21 17:51:59.035150 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] id = group_dict.get("id") [Wed Aug 21 17:51:59.035155 2019] [wsgi:error] [pid 26879:tid 140719262422784] [remote 127.0.0.1:25549] AttributeError: 'unicode' object has no attribute 'get'

I thought it is because the dataset is not yet created, so just to check whether it works I move the field to the resource part which works again as additional info (as expected).

So, now I am wondering whether it is possible at all to have the group in the first step and if not, is there any possibility that I add the 3rd step to creating the dataset after adding resources and then attache the obligatory groups? Could you please advice me on this?

Thanks Mani

(the group.html is very much copy and paste from organization however removing the owner_org and replacing organization with group)

MandanaMoshref avatar Aug 21 '19 16:08 MandanaMoshref