-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Normalising Children and New Nodes #111
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aerial-ace1 Thank you for your contribution :) I think this PR requires a few changes which need to be addressed, after which it can be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor comment, I think I'll add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'd like @alexgarel to review this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @aerial-ace1 great job for you spotted more than the ticket was saying
Still I would like you to make some fix, and we will be good.
backend/editor/entries.py
Outdated
@@ -18,12 +18,16 @@ def create_node(label, entry, main_language_code): | |||
""" | |||
Helper function used for creating a node with given id and label | |||
""" | |||
#Normalising new Node ID | |||
|
|||
normalised_entry = normalizing(entry, main_language_code).split(':', 1)[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not make the split here, should you ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... yup.
backend/editor/entries.py
Outdated
|
||
normalised_new_node_keys["tags_ids_"+keys_language_code] = normalised_value | ||
else: | ||
normalised_new_node_keys[keys] = new_node_keys[keys] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normalised_new_node_keys[keys] = new_node_keys[keys] | |
# no need to normalize | |
normalised_new_node_keys[keys] = new_node_keys[keys] | |
backend/editor/entries.py
Outdated
@@ -173,13 +177,28 @@ def update_nodes(label, entry, new_node_keys): | |||
continue | |||
query.append(f"""\nREMOVE n.{key}\n""") | |||
|
|||
#Normalising Node to be Updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#Normalising Node to be Updated | |
# Adding normalized tags ids corresponding to entry tags | |
@@ -173,13 +177,28 @@ def update_nodes(label, entry, new_node_keys): | |||
continue | |||
query.append(f"""\nREMOVE n.{key}\n""") | |||
|
|||
#Normalising Node to be Updated | |||
normalised_new_node_keys = {} | |||
for keys in new_node_keys.keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should name it key
, not keys
backend/editor/entries.py
Outdated
if keys.startswith("tags") and not keys.endswith("str"): | ||
if "ids" not in keys: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the "_" to make the condition even more specific and explicit
if keys.startswith("tags") and not keys.endswith("str"): | |
if "ids" not in keys: | |
if keys.startswith("tags_") and not keys.endswith("_str"): | |
if "_ids_" not in keys: | |
# generate tags_ids from values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense
backend/editor/entries.py
Outdated
normalised_value.append(normalizing(values, keys_language_code)) | ||
normalised_new_node_keys[keys] = new_node_keys[keys] | ||
|
||
normalised_new_node_keys["tags_ids_"+keys_language_code] = normalised_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a else to make explicit it's intended
normalised_new_node_keys["tags_ids_"+keys_language_code] = normalised_value | |
normalised_new_node_keys["tags_ids_"+keys_language_code] = normalised_value | |
else: | |
pass # we generate tags_ids, and ignore the one sent | |
backend/editor/entries.py
Outdated
@@ -206,7 +225,13 @@ def update_node_children(entry, new_children_ids): | |||
existing_ids = [record['child.id'] for record in get_current_transaction().run(query, ids=list(added_children))] | |||
to_create = added_children - set(existing_ids) | |||
|
|||
for child in to_create: | |||
#Normalising new children node ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pep8 ask for space after the #
#Normalising new children node ID | |
# Normalising new children node ID | |
backend/editor/entries.py
Outdated
normalised_added_children = set() | ||
for child_node in to_create: | ||
child_language_code, new_child_name = child_node.split(":",1) | ||
normalised_added_children.add(normalizing(new_child_name,child_language_code)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to put back language code !
normalised_added_children.add(normalizing(new_child_name,child_language_code)) | |
normalised_added_children.add( | |
f"{child_language_code}:{normalizing(new_child_name, child_language_code)}") | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but see below because I propose you to remove this part.
backend/editor/entries.py
Outdated
#Normalising new children node ID | ||
normalised_added_children = set() | ||
for child_node in to_create: | ||
child_language_code, new_child_name = child_node.split(":",1) | ||
normalised_added_children.add(normalizing(new_child_name,child_language_code)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As create_node is used below and it already normalize id I don't think we need this (and this avoid duplication of code).
Instead I propose to build normalised_added_children while creating nodes (see below)
backend/editor/entries.py
Outdated
for child in normalised_added_children: | ||
main_language_code = child.split(":", 1)[0] | ||
create_node("ENTRY", child, main_language_code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to instead do
for child in normalised_added_children: | |
main_language_code = child.split(":", 1)[0] | |
create_node("ENTRY", child, main_language_code) | |
normalised_added_children = [] | |
for child in to_create: | |
main_language_code = child.split(":", 1)[0] | |
created_node = create_node("ENTRY", child, main_language_code) | |
normalised_added_children.append(created_node.id) |
By the way we can use a shorter name like created_ids instead of normalised_added_children
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @aerial-ace1,
I will just add one comment before merging :-)
Thanks, it's a much appreciated contribution.
@aerial-ace1: a small tip: don't make changes on your fork's main branch, as it will prevent you from cleanly update you fork from upstream project. Create a new branch for each PR. |
Thanks for the contribution @aerial-ace1!🎉 |
Sure will do so from now on @alexgarel. Was fun doing this! |
What
Code added normalises the nodes using the normalising function in the API calls of:
Fixes bug(s)