Merge pull request #995 from taigaio/fixing-ordering-on-archived
Fixing ordering in archived statesremotes/origin/fix-throttling-bug
commit
c48b99be75
|
@ -16,13 +16,11 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db import DatabaseError
|
from django.db import DatabaseError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.shortcuts import _get_queryset
|
from django.shortcuts import _get_queryset
|
||||||
from taiga.celery import app
|
|
||||||
|
|
||||||
from . import functions
|
from . import functions
|
||||||
|
|
||||||
|
@ -124,9 +122,9 @@ def update_in_bulk(instances, list_of_new_values, callback=None, precall=None):
|
||||||
instance.save()
|
instance.save()
|
||||||
callback(instance)
|
callback(instance)
|
||||||
|
|
||||||
@app.task
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def _update_attr_in_bulk_for_ids(values, attr, model):
|
def update_attr_in_bulk_for_ids(values, attr, model):
|
||||||
"""Update a table using a list of ids.
|
"""Update a table using a list of ids.
|
||||||
|
|
||||||
:params values: Dict of new values where the key is the pk of the element to update.
|
:params values: Dict of new values where the key is the pk of the element to update.
|
||||||
|
@ -164,14 +162,6 @@ def _update_attr_in_bulk_for_ids(values, attr, model):
|
||||||
transaction.on_commit(_run_sql)
|
transaction.on_commit(_run_sql)
|
||||||
|
|
||||||
|
|
||||||
@transaction.atomic
|
|
||||||
def update_attr_in_bulk_for_ids(values, attr, model):
|
|
||||||
if settings.CELERY_ENABLED:
|
|
||||||
_update_attr_in_bulk_for_ids.delay(values, attr, model)
|
|
||||||
else:
|
|
||||||
_update_attr_in_bulk_for_ids(values, attr, model)
|
|
||||||
|
|
||||||
|
|
||||||
def to_tsquery(term):
|
def to_tsquery(term):
|
||||||
"""
|
"""
|
||||||
Based on: https://gist.github.com/wolever/1a5ccf6396f00229b2dc
|
Based on: https://gist.github.com/wolever/1a5ccf6396f00229b2dc
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
from django.db.models import Max
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
@ -156,6 +157,10 @@ class UserStoryViewSet(OCCResourceMixin, VotedResourceMixin, HistoryResourceMixi
|
||||||
related_data = getattr(obj, "_related_data", {})
|
related_data = getattr(obj, "_related_data", {})
|
||||||
self._role_points = related_data.pop("role_points", None)
|
self._role_points = related_data.pop("role_points", None)
|
||||||
|
|
||||||
|
if obj.kanban_order == -1:
|
||||||
|
if self._max_order:
|
||||||
|
obj.kanban_order = self._max_order + 1;
|
||||||
|
|
||||||
if not obj.id:
|
if not obj.id:
|
||||||
obj.owner = self.request.user
|
obj.owner = self.request.user
|
||||||
else:
|
else:
|
||||||
|
@ -276,6 +281,12 @@ class UserStoryViewSet(OCCResourceMixin, VotedResourceMixin, HistoryResourceMixi
|
||||||
except Project.DoesNotExist:
|
except Project.DoesNotExist:
|
||||||
return response.BadRequest(_("The project doesn't exist"))
|
return response.BadRequest(_("The project doesn't exist"))
|
||||||
|
|
||||||
|
if self.object and self.object.project_id:
|
||||||
|
self._max_order = models.UserStory.objects.filter(
|
||||||
|
project_id=self.object.project_id,
|
||||||
|
status_id=request.DATA.get('status', None)
|
||||||
|
).aggregate(Max('kanban_order'))['kanban_order__max']
|
||||||
|
|
||||||
return super().update(request, *args, **kwargs)
|
return super().update(request, *args, **kwargs)
|
||||||
|
|
||||||
@list_route(methods=["GET"])
|
@list_route(methods=["GET"])
|
||||||
|
|
Loading…
Reference in New Issue