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

Factor out a helper for calculating next tile sort order #11762

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions arches/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1623,17 +1623,20 @@ def save(self, **kwargs):
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"]
self.sortorder = sortorder_max + 1 if sortorder_max is not None else 0
self.set_next_sort_order()
add_to_update_fields(kwargs, "sortorder")
if not self.tileid:
self.tileid = uuid.uuid4()
add_to_update_fields(kwargs, "tileid")
super(TileModel, self).save(**kwargs) # Call the "real" save() method.

def set_next_sort_order(self):
sortorder_max = self.__class__.objects.filter(
nodegroup_id=self.nodegroup_id,
resourceinstance_id=self.resourceinstance_id,
).aggregate(Max("sortorder"))["sortorder__max"]
self.sortorder = sortorder_max + 1 if sortorder_max is not None else 0

def serialize(self, fields=None, exclude=["nodegroup"], **kwargs):
return JSONSerializer().handle_model(
self, fields=fields, exclude=exclude, **kwargs
Expand Down
7 changes: 3 additions & 4 deletions arches/app/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
from django.utils.translation import gettext as _
from django.utils.translation import get_language
from arches.app.models import models
from arches.app.models.models import EditLog
from arches.app.models.models import TileModel
from arches.app.models.models import EditLog, TileModel
from arches.app.models.utils import add_to_update_fields
from arches.app.models.concept import get_preflabel_from_valueid
from arches.app.models.system_settings import settings
from arches.app.search.search_engine_factory import SearchEngineInstance as se
Expand Down Expand Up @@ -281,8 +281,7 @@ def save(self, **kwargs):

if not self.principaluser_id and user:
self.principaluser_id = user.id
# TODO: this is not updating update_fields in kwargs
# Fix when adding user argument to Resource.save().
add_to_update_fields(kwargs, "principaluser_id")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I no longer plan to suggest the change in that TODO, so just rolling in the fix now.


super(Resource, self).save(**kwargs)

Expand Down