Skip to content
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

Fixes errors when creating provisional edits #9704

Merged
merged 11 commits into from
Jul 7, 2023
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:
chrabyrd marked this conversation as resolved.
Show resolved Hide resolved
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,20 @@
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")

for tile in TileModel.objects.all():
tile.save() # should trigger new code in `TileModel.save` method that adds empty key/value pairs to tile data

def reverse_func(apps, schema_editor):
pass

operations = [
migrations.RunPython(forwards_func, reverse_func),
]
chrabyrd marked this conversation as resolved.
Show resolved Hide resolved
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 == {}):
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

if self.sortorder is None or self.is_fully_provisional():
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