Skip to content

Commit

Permalink
Merge pull request #9704 from archesproject/9648_prevent_prov_edit_er…
Browse files Browse the repository at this point in the history
…rors

Fixes errors when creating provisional edits
  • Loading branch information
chiatt authored Jul 7, 2023
2 parents cbea793 + efe7769 commit 10c40d7
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 167 deletions.
2 changes: 1 addition & 1 deletion arches/app/datatypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def get_tile_data(self, tile):
except:
data = tile["data"]
provisionaledits = tile["provisionaledits"]
if data is not None and len(list(data.keys())) > 0:
if data is not None and any(data.values()):
return data
elif provisionaledits is not None and len(list(provisionaledits.keys())) > 0:
if len(list(provisionaledits.keys())) > 1:
Expand Down
2 changes: 1 addition & 1 deletion arches/app/datatypes/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ def append_to_document(self, document, nodevalue, nodeid, tile, provisional=Fals
for f in tile.data[str(nodeid)]:
val = {"string": f["name"], "nodegroup_id": tile.nodegroup_id, "provisional": provisional}
document["strings"].append(val)
except KeyError as e:
except (KeyError, TypeError) as e:
for k, pe in tile.provisionaledits.items():
for f in pe["value"][nodeid]:
val = {"string": f["name"], "nodegroup_id": tile.nodegroup_id, "provisional": provisional}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("models", "9477_fix_for_spatial_view_dbf_function_edtf_displaying_null"),
]

def forwards_func(apps, schema_editor):
TileModel = apps.get_model("models", "TileModel")
Node = apps.get_model("models", "Node")

for tile in TileModel.objects.filter(data={}, provisionaledits__isnull=False):
for node in Node.objects.filter(nodegroup_id=tile.nodegroup_id):
if not str(node.pk) in tile.data:
tile.data[str(node.pk)] = None
tile.save()

def reverse_func(apps, schema_editor):
TileModel = apps.get_model("models", "TileModel")

for tile in TileModel.objects.filter(provisionaledits__isnull=False):
if bool(tile.provisionaledits and not any(tile.data.values())):
tile.data = {}
tile.save()

operations = [
migrations.RunPython(forwards_func, reverse_func),
]
9 changes: 8 additions & 1 deletion arches/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,15 @@ def __init__(self, *args, **kwargs):
if not self.tileid:
self.tileid = uuid.uuid4()

def is_fully_provisional(self):
return bool(self.provisionaledits and not any(self.data.values()))

def save(self, *args, **kwargs):
if self.sortorder is None or (self.provisionaledits is not None and self.data == {}):
if self.sortorder is None or self.is_fully_provisional():
for node in Node.objects.filter(nodegroup_id=self.nodegroup_id):
if not str(node.pk) in self.data:
self.data[str(node.pk)] = None

sortorder_max = TileModel.objects.filter(
nodegroup_id=self.nodegroup_id, resourceinstance_id=self.resourceinstance_id
).aggregate(Max("sortorder"))["sortorder__max"]
Expand Down
5 changes: 2 additions & 3 deletions arches/app/models/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ def is_provisional(self):
been approved by a user in the resource reviewer group
"""

result = False
if self.provisionaledits is not None and len(self.data) == 0:
if self.provisionaledits is not None and not any(self.data.values()):
result = True

return result
Expand Down Expand Up @@ -566,7 +565,7 @@ def after_update_all(self):

def is_blank(self):
if self.data != {}:
if len([item for item in list(self.data.values()) if item is not None]) > 0:
if any(self.data.values()):
return False

child_tiles_are_blank = True
Expand Down
Loading

0 comments on commit 10c40d7

Please sign in to comment.