21 lines
624 B
Python
21 lines
624 B
Python
"""Shared ordering operations for task columns and rows."""
|
|
|
|
from tasks.models import Task
|
|
|
|
|
|
def normalize_column_positions(column, row=None) -> None:
|
|
tasks = list(
|
|
column.tasks.filter(row=row)
|
|
.order_by("position", "-created_at", "id")
|
|
.only("id", "position")
|
|
)
|
|
changed_tasks = []
|
|
for index, task in enumerate(tasks):
|
|
position = (index + 1) * 1000
|
|
if task.position == position:
|
|
continue
|
|
task.position = position
|
|
changed_tasks.append(task)
|
|
if changed_tasks:
|
|
Task.objects.bulk_update(changed_tasks, ["position"], batch_size=500)
|