Skip to content

Commit

Permalink
api: fix min/max columns update in post_save/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Oct 20, 2021
1 parent f4e6848 commit c4fa95f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions mpcontribs-api/mpcontribs/api/contributions/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,20 @@ def update_columns(path, key, value):
return True

# run update_columns over document data
if not document.data:
document.reload("data")

remap(document.data, visit=update_columns, enter=enter)

# get and set min/max for all paths
min_max = get_min_max(sender, min_max_paths, project.name)

for clean_path in min_max_paths:
for k in ["min", "max"]:
path = clean_path.replace("__", delimiter)
path = clean_path.replace(delimiter, "__")
m = min_max.get(f"{path}__{k}")
if m is not None:
setattr(columns[path], k, m)
setattr(columns[clean_path], k, m)

# add/remove columns for other components
for path in COMPONENTS.keys():
Expand Down Expand Up @@ -419,13 +422,13 @@ def post_delete(cls, sender, document, **kwargs):
min_max = get_min_max(sender, min_max_paths, project.name)

for clean_path in min_max_paths:
path = clean_path.replace("__", delimiter)
column = columns[path]
path = clean_path.replace(delimiter, "__")
column = columns[clean_path]

for k in ["min", "max"]:
if min_max.get(f"{path}__{k}") is None:
# just deleted last contribution with this column
columns.pop(path)
columns.pop(clean_path)
break

cls.update_project(sender, project, columns_copy, columns.values())
Expand Down

0 comments on commit c4fa95f

Please sign in to comment.