def post(self, *args, **kwargs):

        widget = self.object

        ordering = self.kwargs.get('ordering')

        if int(ordering) == 0:

            widget.ordering = 0
            widget.save()

            widgets = getattr(widget.parent.content, widget.region)
            widgets = [w for w in widgets if w.id != widget.id]

            for i, _widget in enumerate(widgets):
                _widget.ordering = i + 1
                _widget.save()

        elif int(ordering) == -1:
            next_ordering = 1 - widget.ordering
            widgets = getattr(widget.parent.content, widget.region)
            for w in widgets:
                if w.ordering == next_ordering:
                    w.ordering = widget.ordering
                    w.save()
                    widget.ordering = next_ordering
                    widget.save()
        elif int(ordering) == 1:

            next_ordering = widget.ordering + 1
            widgets = getattr(widget.parent.content, widget.region)
            for w in widgets:
                if w.ordering == next_ordering:
                    w.ordering = widget.ordering
                    w.save()
                    widget.ordering = next_ordering
                    widget.save()

        else:
            widget.ordering = widget.next_ordering
            widget.save()
            widgets = getattr(widget.parent.content, widget.region)
            widgets = [w for w in widgets if w.id != widget.id]
            widgets.sort(key=lambda w: w.ordering)

            for i, _widget in enumerate(widgets):
                _widget.ordering = i
                _widget.save()

        messages.success(self.request, _('Widget was successfully moved.'))

        success_url = self.get_success_url()
        response = HttpResponseRedirect(success_url)
        response['X-Horizon-Location'] = success_url
        return response
dataset/ETHPy150Open django-leonardo/django-leonardo/leonardo/module/web/widgets/views.py/WidgetReorderView.post/swapped operands of `-`