Skip to content

Commit

Permalink
Merge branch 'dj-4.x' into dj-4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
matmair authored Jan 8, 2024
2 parents d2b2cb5 + e151169 commit 1344103
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 31 deletions.
5 changes: 5 additions & 0 deletions InvenTree/InvenTree/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,3 +840,8 @@ def inheritors(cls):
subcls.add(child)
work.append(child)
return subcls


def is_ajax(request):
"""Check if the current request is an AJAX request."""
return request.headers.get('x-requested-with') == 'XMLHttpRequest'
4 changes: 2 additions & 2 deletions InvenTree/InvenTree/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from users.models import RuleSet, check_user_role

from .forms import EditUserForm, SetPasswordForm
from .helpers import remove_non_printable_characters, strip_html_tags
from .helpers import is_ajax, remove_non_printable_characters, strip_html_tags


def auth_request(request):
Expand Down Expand Up @@ -258,7 +258,7 @@ def renderJsonResponse(self, request, form=None, data=None, context=None):
if not data:
data = {}

if not request.is_ajax():
if not is_ajax(request):
return HttpResponseRedirect('/')

if context is None:
Expand Down
11 changes: 9 additions & 2 deletions InvenTree/build/migrations/0013_auto_20200425_0507.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
from django.db import migrations, models
import django.db.models.deletion
import mptt.fields
from build.models import Build


def update_tree(apps, schema_editor):
# Update the Build MPTT model
Build.objects.rebuild()

Build = apps.get_model('build', 'Build')

try:
print("Rebuilding Build objects")
Build.objects.rebuild()
print("Rebuilding Build objects - done")
except Exception as exc:
print("Error rebuilding Build objects", exc)


class Migration(migrations.Migration):
Expand Down
11 changes: 9 additions & 2 deletions InvenTree/order/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ class Meta:

def save(self, *args, **kwargs):
"""Update the total_price field when saved"""
# Recalculate total_price for this order
self.update_total_price(commit=False)

if hasattr(self, '_SAVING_TOTAL_PRICE') and getattr(self, '_SAVING_TOTAL_PRICE'):
# Avoid recursion on save
return super().save(*args, **kwargs)
self._SAVING_TOTAL_PRICE = True

# Save the object as we can not access foreign/m2m fields before saving
super().save(*args, **kwargs)
# Recalculate total_price for this order
self.update_total_price(commit=True)

total_price = InvenTreeModelMoneyField(
null=True, blank=True,
Expand Down
8 changes: 4 additions & 4 deletions InvenTree/part/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from InvenTree.filters import (ORDER_FILTER, SEARCH_ORDER_FILTER,
SEARCH_ORDER_FILTER_ALIAS, InvenTreeDateFilter,
InvenTreeSearchFilter)
from InvenTree.helpers import (DownloadFile, increment_serial_number, isNull,
str2bool, str2int)
from InvenTree.helpers import (DownloadFile, increment_serial_number, is_ajax,
isNull, str2bool, str2int)
from InvenTree.mixins import (CreateAPI, CustomRetrieveUpdateDestroyAPI,
ListAPI, ListCreateAPI, RetrieveAPI,
RetrieveUpdateAPI, RetrieveUpdateDestroyAPI,
Expand Down Expand Up @@ -1069,7 +1069,7 @@ def list(self, request, *args, **kwargs):
"""
if page is not None:
return self.get_paginated_response(data)
elif request.is_ajax():
elif is_ajax(request):
return JsonResponse(data, safe=False)
return Response(data)

Expand Down Expand Up @@ -1740,7 +1740,7 @@ def list(self, request, *args, **kwargs):
"""
if page is not None:
return self.get_paginated_response(data)
elif request.is_ajax():
elif is_ajax(request):
return JsonResponse(data, safe=False)
return Response(data)

Expand Down
10 changes: 7 additions & 3 deletions InvenTree/part/migrations/0020_auto_20190908_0404.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Generated by Django 2.2.5 on 2019-09-08 04:04

from django.db import migrations
from part import models


def update_tree(apps, schema_editor):
# Update the PartCategory MPTT model

models.PartCategory.objects.rebuild()
PartCategory = apps.get_model('part', 'PartCategory')
try:
print("Rebuilding PartCategory objects")
PartCategory.objects.rebuild()
print("Rebuilding PartCategory objects - done")
except Exception as exc:
print("Error rebuilding PartCategory objects", exc)


class Migration(migrations.Migration):
Expand Down
11 changes: 8 additions & 3 deletions InvenTree/part/migrations/0039_auto_20200515_1127.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

from django.db import migrations, models

from part.models import Part


def update_tree(apps, schema_editor):
# Update the MPTT for Part model
Part.objects.rebuild()

Part = apps.get_model('part', 'Part')
try:
print("Rebuilding Part objects")
Part.objects.rebuild()
print("Rebuilding Part objects - done")
except Exception as exc:
print("Error rebuilding Part objects", exc)


class Migration(migrations.Migration):
Expand Down
3 changes: 1 addition & 2 deletions InvenTree/plugin/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class NameInvenTreePlugin(InvenTreePlugin):
LICENSE = 'MIT'

cls.plugin_name = NameInvenTreePlugin()
cls.plugin_sample = SampleIntegrationPlugin()

class VersionInvenTreePlugin(InvenTreePlugin):
NAME = 'Version'
Expand Down Expand Up @@ -135,7 +134,7 @@ def test_action_name(self):

# is_sample
self.assertEqual(self.plugin.is_sample, False)
self.assertEqual(self.plugin_sample.is_sample, True)
self.assertEqual(SampleIntegrationPlugin().is_sample, True)

# slug
self.assertEqual(self.plugin.slug, '')
Expand Down
8 changes: 4 additions & 4 deletions InvenTree/stock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
ListCreateDestroyAPIView, MetadataView)
from InvenTree.filters import (ORDER_FILTER, SEARCH_ORDER_FILTER,
SEARCH_ORDER_FILTER_ALIAS, InvenTreeDateFilter)
from InvenTree.helpers import (DownloadFile, extract_serial_numbers, isNull,
str2bool, str2int)
from InvenTree.helpers import (DownloadFile, extract_serial_numbers, is_ajax,
isNull, str2bool, str2int)
from InvenTree.mixins import (CreateAPI, CustomRetrieveUpdateDestroyAPI,
ListAPI, ListCreateAPI, RetrieveAPI,
RetrieveUpdateDestroyAPI)
Expand Down Expand Up @@ -963,7 +963,7 @@ def list(self, request, *args, **kwargs):

if page is not None:
return self.get_paginated_response(data)
elif request.is_ajax():
elif is_ajax(request):
return JsonResponse(data, safe=False)
return Response(data)

Expand Down Expand Up @@ -1346,7 +1346,7 @@ def list(self, request, *args, **kwargs):

if page is not None:
return self.get_paginated_response(data)
if request.is_ajax():
if is_ajax(request):
return JsonResponse(data, safe=False)
return Response(data)

Expand Down
10 changes: 7 additions & 3 deletions InvenTree/stock/migrations/0012_auto_20190908_0405.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

from django.db import migrations

from stock import models


def update_tree(apps, schema_editor):
# Update the StockLocation MPTT model

models.StockLocation.objects.rebuild()
StockLocation = apps.get_model('stock', 'StockLocation')
try:
print("Rebuilding StockLocation objects")
StockLocation.objects.rebuild()
print("Rebuilding StockLocation objects - done")
except Exception as exc:
print("Error rebuilding StockLocation objects", exc)


class Migration(migrations.Migration):
Expand Down
9 changes: 7 additions & 2 deletions InvenTree/stock/migrations/0022_auto_20200217_1109.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Generated by Django 2.2.9 on 2020-02-17 11:09

from django.db import migrations
from stock import models


def update_stock_item_tree(apps, schema_editor):
# Update the StockItem MPTT model

models.StockItem.objects.rebuild()
StockItem = apps.get_model('stock', 'StockItem')
try:
print("Rebuilding StockItem objects")
StockItem.objects.rebuild()
print("Rebuilding StockItem objects - done")
except Exception as exc:
print("Error rebuilding StockItem objects", exc)


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ virtualenv==20.25.0
# via pre-commit
wheel==0.42.0
# via pip-tools
zipp==3.16.0
zipp==3.16.2
# via
# -c requirements.txt
# importlib-metadata
Expand Down
4 changes: 3 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ django-filter # Extended filtering options
django-flags # Feature flags
django-formtools # Form wizard tools
django-ical # iCal export for calendar views
django-import-export>=3.3.1 # Data import / export for admin interface
django-import-export # Data import / export for admin interface
django-maintenance-mode # Shut down application while reloading etc.
django-markdownify # Markdown rendering
django-mptt # Modified Preorder Tree Traversal
django-markdownify # Markdown rendering
django-money>=3.0.0,<3.3.0 # Django app for currency management # FIXED 2023-10-31 3.3.0 breaks due to https://github.com/django-money/django-money/issues/731
django-mptt # Modified Preorder Tree Traversal
django-redis>=5.0.0 # Redis integration
Expand Down
8 changes: 6 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ attrs==23.2.0
babel==2.14.0
# via py-moneyed
bleach[css]==6.1.0
# via django-markdownify
# via
# bleach
# django-markdownify
brotli==1.1.0
# via fonttools
certifi==2023.11.17
Expand Down Expand Up @@ -222,6 +224,7 @@ pyjwt[crypto]==2.8.0
# via
# django-allauth
# djangorestframework-simplejwt
# pyjwt
pyphen==0.14.0
# via weasyprint
pypng==0.20220715.0
Expand Down Expand Up @@ -300,6 +303,7 @@ tinycss2==1.2.1
typing-extensions==4.9.0
# via
# asgiref
# drf-spectacular
# py-moneyed
# qrcode
uritemplate==4.1.1
Expand All @@ -325,7 +329,7 @@ xlrd==2.0.1
# via tablib
xlwt==1.3.0
# via tablib
zipp==3.16.0
zipp==3.16.2
# via importlib-metadata
zopfli==0.2.3
# via fonttools
Expand Down

0 comments on commit 1344103

Please sign in to comment.