Closed gannebamm closed 2 years ago
Adding the missing hierarchical keywords is actually quite easy. You could just add all ancestors in e.g. the ResourceBase save() function like:
geonode/base/models.py:923
elif self.pk:
# Resource Updated
_notification_sent = False
# add hierarchical keyword ancestors to build the full tree
for hkeyword in self.keywords.all():
ancestors = hkeyword.get_ancestors()
self.keywords.add(*ancestors)
This will add all keywords since they are idempotent and adding them again wont change the result.
But for some reason the hierarchy rendering often fails. Something is not working with the code at geonode/base/models.py:391
if (not parent and depth == 1) or \
(parent and depth == parent.depth):
ret.append(newobj)
else:
parentobj = pyobj.get_parent()
parentser = lnk[parentobj.pk] #throws exception...
if 'nodes' not in parentser:
parentser['nodes'] = []
parentser['nodes'].append(newobj)
lnk[pyobj.pk] = newobj
except Exception:
pass
return ret
The exception will result in an emtpy ret
and a broken keywords search field.
@mtnorthcott Hi, do you think the above is something you could use in the Catalyst Academy? The candidate has to debug the if/else except statement to figure out what exactly breaks the rendering and method. I was not yet able to understand what is wrong there.
@gannebamm Happy New Year and thanks for your suggestion. I think we could definitely look into debugging that block if time permits. If not, I would be happy to continue wherever the Academy finishes off :)
Expected Behavior
If I use a hierarchical keyword like:
_AAA_hierarchytest
I would expect tagging a dataset with
_AAA_hierarchytest_A_cat_option1
should apply all parent keywords, too.Actual Behavior
It will only get the child keyword. Therefore you will not be able to search for it in the search window, since no parent keywords are present. If parent keywords are present everything is fine.
By this, the administrators are unable to set hierarchical trees as keywords beforehand but have to rely on an already present set of keyworded datasets to build the tree.
Steps to Reproduce the Problem
It will fail if no other dataset with parent keywords is present.
Example dataset with only the child: https://master.demo.geonode.org/layers/geonode:someHydroData0
Example dataset with the whole hierarchy of keywords: https://master.demo.geonode.org/layers/geonode_data:geonode:test_2_10_2
Use your own user on https://master.demo.geonode.org and:
Specifications