From e870dae2610f9c0931a0db100ba837c7c9c3b4f4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 14 Mar 2023 23:10:02 +1100 Subject: [PATCH] URL cleanup - Use instead of complex regex --- InvenTree/build/api.py | 8 ++++---- InvenTree/build/urls.py | 4 ++-- InvenTree/common/api.py | 6 +++--- InvenTree/company/api.py | 6 +++--- InvenTree/company/urls.py | 8 ++++---- InvenTree/label/api.py | 8 ++++---- InvenTree/part/urls.py | 4 ++-- InvenTree/plugin/api.py | 4 ++-- InvenTree/stock/urls.py | 4 ++-- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py index dd52145ad0..15427a94b9 100644 --- a/InvenTree/build/api.py +++ b/InvenTree/build/api.py @@ -1,6 +1,6 @@ """JSON API for the Build app.""" -from django.urls import include, re_path +from django.urls import include, path, re_path from django.utils.translation import gettext_lazy as _ from django.contrib.auth.models import User @@ -487,18 +487,18 @@ build_api_urls = [ # Attachments re_path(r'^attachment/', include([ - re_path(r'^(?P\d+)/', BuildAttachmentDetail.as_view(), name='api-build-attachment-detail'), + path(r'/', BuildAttachmentDetail.as_view(), name='api-build-attachment-detail'), re_path(r'^.*$', BuildAttachmentList.as_view(), name='api-build-attachment-list'), ])), # Build Items re_path(r'^item/', include([ - re_path(r'^(?P\d+)/', BuildItemDetail.as_view(), name='api-build-item-detail'), + path(r'/', BuildItemDetail.as_view(), name='api-build-item-detail'), re_path(r'^.*$', BuildItemList.as_view(), name='api-build-item-list'), ])), # Build Detail - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path(r'^allocate/', BuildAllocate.as_view(), name='api-build-allocate'), re_path(r'^auto-allocate/', BuildAutoAllocate.as_view(), name='api-build-auto-allocate'), re_path(r'^complete/', BuildOutputComplete.as_view(), name='api-build-output-complete'), diff --git a/InvenTree/build/urls.py b/InvenTree/build/urls.py index 0b33c7d78e..6dab501239 100644 --- a/InvenTree/build/urls.py +++ b/InvenTree/build/urls.py @@ -1,13 +1,13 @@ """URL lookup for Build app.""" -from django.urls import include, re_path +from django.urls import include, path, re_path from . import views build_urls = [ - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path(r'^.*$', views.BuildDetail.as_view(), name='build-detail'), ])), diff --git a/InvenTree/common/api.py b/InvenTree/common/api.py index 208ca12d26..382197308b 100644 --- a/InvenTree/common/api.py +++ b/InvenTree/common/api.py @@ -457,7 +457,7 @@ settings_api_urls = [ # Notification settings re_path(r'^notification/', include([ # Notification Settings Detail - re_path(r'^(?P\d+)/', NotificationUserSettingsDetail.as_view(), name='api-notification-setting-detail'), + path(r'/', NotificationUserSettingsDetail.as_view(), name='api-notification-setting-detail'), # Notification Settings List re_path(r'^.*$', NotificationUserSettingsList.as_view(), name='api-notifcation-setting-list'), @@ -486,7 +486,7 @@ common_api_urls = [ # Notifications re_path(r'^notifications/', include([ # Individual purchase order detail URLs - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path(r'.*$', NotificationDetail.as_view(), name='api-notifications-detail'), ])), # Read all @@ -498,7 +498,7 @@ common_api_urls = [ # News re_path(r'^news/', include([ - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path(r'.*$', NewsFeedEntryDetail.as_view(), name='api-news-detail'), ])), re_path(r'^.*$', NewsFeedEntryList.as_view(), name='api-news-list'), diff --git a/InvenTree/company/api.py b/InvenTree/company/api.py index 5566e15cec..07adc33c03 100644 --- a/InvenTree/company/api.py +++ b/InvenTree/company/api.py @@ -535,12 +535,12 @@ manufacturer_part_api_urls = [ # Base URL for ManufacturerPartAttachment API endpoints re_path(r'^attachment/', include([ - re_path(r'^(?P\d+)/', ManufacturerPartAttachmentDetail.as_view(), name='api-manufacturer-part-attachment-detail'), + path(r'/', ManufacturerPartAttachmentDetail.as_view(), name='api-manufacturer-part-attachment-detail'), re_path(r'^$', ManufacturerPartAttachmentList.as_view(), name='api-manufacturer-part-attachment-list'), ])), re_path(r'^parameter/', include([ - re_path(r'^(?P\d+)/', ManufacturerPartParameterDetail.as_view(), name='api-manufacturer-part-parameter-detail'), + path(r'/', ManufacturerPartParameterDetail.as_view(), name='api-manufacturer-part-parameter-detail'), # Catch anything else re_path(r'^.*$', ManufacturerPartParameterList.as_view(), name='api-manufacturer-part-parameter-list'), @@ -580,7 +580,7 @@ company_api_urls = [ ])), re_path(r'^attachment/', include([ - re_path(r'^(?P\d+)/', CompanyAttachmentDetail.as_view(), name='api-company-attachment-detail'), + path(r'/', CompanyAttachmentDetail.as_view(), name='api-company-attachment-detail'), re_path(r'^$', CompanyAttachmentList.as_view(), name='api-company-attachment-list'), ])), diff --git a/InvenTree/company/urls.py b/InvenTree/company/urls.py index 8ab73ba2b2..71985964fb 100644 --- a/InvenTree/company/urls.py +++ b/InvenTree/company/urls.py @@ -1,13 +1,13 @@ """URL lookup for Company app.""" -from django.urls import include, re_path +from django.urls import include, path, re_path from . import views company_urls = [ # Detail URLs for a specific Company instance - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path(r'^.*$', views.CompanyDetail.as_view(), name='company-detail'), ])), @@ -21,11 +21,11 @@ company_urls = [ manufacturer_part_urls = [ - re_path(r'^(?P\d+)/', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part.html'), name='manufacturer-part-detail'), + path(r'/', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part.html'), name='manufacturer-part-detail'), ] supplier_part_urls = [ - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path('^.*$', views.SupplierPartDetail.as_view(template_name='company/supplier_part.html'), name='supplier-part-detail'), ])) diff --git a/InvenTree/label/api.py b/InvenTree/label/api.py index 9d8092f551..2126d0e8f1 100644 --- a/InvenTree/label/api.py +++ b/InvenTree/label/api.py @@ -3,7 +3,7 @@ from django.conf import settings from django.core.exceptions import FieldError, ValidationError from django.http import HttpResponse, JsonResponse -from django.urls import include, re_path +from django.urls import include, path, re_path from django_filters.rest_framework import DjangoFilterBackend from rest_framework import filters @@ -370,7 +370,7 @@ label_api_urls = [ # Stock item labels re_path(r'stock/', include([ # Detail views - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path(r'print/?', StockItemLabelPrint.as_view(), name='api-stockitem-label-print'), re_path(r'^.*$', StockItemLabelDetail.as_view(), name='api-stockitem-label-detail'), ])), @@ -382,7 +382,7 @@ label_api_urls = [ # Stock location labels re_path(r'location/', include([ # Detail views - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path(r'print/?', StockLocationLabelPrint.as_view(), name='api-stocklocation-label-print'), re_path(r'^.*$', StockLocationLabelDetail.as_view(), name='api-stocklocation-label-detail'), ])), @@ -394,7 +394,7 @@ label_api_urls = [ # Part labels re_path(r'^part/', include([ # Detail views - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path(r'^print/', PartLabelPrint.as_view(), name='api-part-label-print'), re_path(r'^.*$', PartLabelDetail.as_view(), name='api-part-label-detail'), ])), diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index 9cd5cafbec..6654c3a9ea 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -6,7 +6,7 @@ - Display / Create / Edit / Delete SupplierPart """ -from django.urls import include, re_path +from django.urls import include, path, re_path from . import views @@ -35,7 +35,7 @@ part_urls = [ re_path(r'^import-api/', views.PartImportAjax.as_view(), name='api-part-import'), # Individual part using pk - re_path(r'^(?P\d+)/', include(part_detail_urls)), + path(r'/', include(part_detail_urls)), # Part category re_path(r'^category/', include(category_urls)), diff --git a/InvenTree/plugin/api.py b/InvenTree/plugin/api.py index 029cf2b20e..aedc2195cc 100644 --- a/InvenTree/plugin/api.py +++ b/InvenTree/plugin/api.py @@ -1,6 +1,6 @@ """API for the plugin app.""" -from django.urls import include, re_path +from django.urls import include, path, re_path from django_filters.rest_framework import DjangoFilterBackend from rest_framework import filters, permissions, status @@ -255,7 +255,7 @@ plugin_api_urls = [ ])), # Detail views for a single PluginConfig item - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ re_path(r'^settings/(?P\w+)/', PluginSettingDetail.as_view(), name='api-plugin-setting-detail-pk'), re_path(r'^activate/', PluginActivate.as_view(), name='api-plugin-detail-activate'), re_path(r'^.*$', PluginDetail.as_view(), name='api-plugin-detail'), diff --git a/InvenTree/stock/urls.py b/InvenTree/stock/urls.py index b8912b3ca2..37ea1ce6d9 100644 --- a/InvenTree/stock/urls.py +++ b/InvenTree/stock/urls.py @@ -1,12 +1,12 @@ """URL lookup for Stock app.""" -from django.urls import include, re_path +from django.urls import include, path, re_path from stock import views location_urls = [ - re_path(r'^(?P\d+)/', include([ + path(r'/', include([ # Anything else - direct to the location detail view re_path('^.*$', views.StockLocationDetail.as_view(), name='stock-location-detail'), ])),