mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	Converting more forms to the API (#3181)
* Delete category via the API * Delete StockLocation via the API * Delete StockItem via the API - Removes the final instance of AjaxDelete * Remove URL path * Add missing code
This commit is contained in:
		@@ -347,23 +347,18 @@
 | 
			
		||||
 | 
			
		||||
    {% if category %}
 | 
			
		||||
    $("#cat-edit").click(function () {
 | 
			
		||||
 | 
			
		||||
        editCategory({{ category.pk }});
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    {% if category.parent %}
 | 
			
		||||
    var redirect = "{% url 'category-detail' category.parent.id %}";
 | 
			
		||||
    {% else %}
 | 
			
		||||
    var redirect = "{% url 'part-index' %}";
 | 
			
		||||
    {% endif %}
 | 
			
		||||
 | 
			
		||||
    $('#cat-delete').click(function() {
 | 
			
		||||
        launchModalForm(
 | 
			
		||||
            "{% url 'category-delete' category.id %}",
 | 
			
		||||
            {
 | 
			
		||||
                redirect: redirect
 | 
			
		||||
            }
 | 
			
		||||
        );
 | 
			
		||||
        deletePartCategory({{ category.pk }}, {
 | 
			
		||||
            {% if category.parent %}
 | 
			
		||||
            redirect: "{% url 'category-detail' category.parent.id %}",
 | 
			
		||||
            {% else %}
 | 
			
		||||
            redirect: "{% url 'part-index' %}",
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    {% endif %}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,32 +0,0 @@
 | 
			
		||||
{% extends "modal_delete_form.html" %}
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
 | 
			
		||||
{% block pre_form_content %}
 | 
			
		||||
 | 
			
		||||
<div class='alert alert-block alert-danger'>
 | 
			
		||||
    {% trans "Are you sure you want to delete this part category?" %}
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
{% if category.children.all|length > 0 %}
 | 
			
		||||
<div class='alert alert-block alert-warning'>
 | 
			
		||||
    {% blocktrans with n=category.children.all|length %}This category contains {{ n }} child categories{% endblocktrans %}.<br>
 | 
			
		||||
    {% if category.parent %}
 | 
			
		||||
    {% blocktrans with category=category.parent.name %}If this category is deleted, these child categories will be moved to {{ category }}{% endblocktrans %}.
 | 
			
		||||
    {% else %}
 | 
			
		||||
    {% trans "If this category is deleted, these child categories will be moved to the top level part category" %}.
 | 
			
		||||
    {% endif %}
 | 
			
		||||
</div>
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
{% if category.parts.all|length > 0 %}
 | 
			
		||||
<div class='alert alert-block alert-warning'>
 | 
			
		||||
    {% blocktrans with n=category.parts.all|length %}This category contains {{ n }} parts{% endblocktrans %}.<br>
 | 
			
		||||
    {% if category.parent %}
 | 
			
		||||
    {% blocktrans with category=category.parent.name %}If this category is deleted, these parts will be moved to {{ category }}{% endblocktrans %}.
 | 
			
		||||
    {% else %}
 | 
			
		||||
    {% trans "If this category is deleted, these parts will be moved to the top level part category" %}.
 | 
			
		||||
    {% endif %}
 | 
			
		||||
</div>
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -33,11 +33,7 @@ category_urls = [
 | 
			
		||||
    re_path(r'^subcategory/', views.PartIndex.as_view(template_name='part/subcategory.html'), name='category-index-subcategory'),
 | 
			
		||||
 | 
			
		||||
    # Category detail views
 | 
			
		||||
    re_path(r'(?P<pk>\d+)/', include([
 | 
			
		||||
        re_path(r'^delete/', views.CategoryDelete.as_view(), name='category-delete'),
 | 
			
		||||
        # Anything else
 | 
			
		||||
        re_path(r'^.*$', views.CategoryDetail.as_view(), name='category-detail'),
 | 
			
		||||
    ]))
 | 
			
		||||
    re_path(r'(?P<pk>\d+)/', views.CategoryDetail.as_view(), name='category-detail'),
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
# URL list for part web interface
 | 
			
		||||
 
 | 
			
		||||
@@ -24,8 +24,8 @@ from common.models import InvenTreeSetting
 | 
			
		||||
from common.views import FileManagementAjaxView, FileManagementFormView
 | 
			
		||||
from company.models import SupplierPart
 | 
			
		||||
from InvenTree.helpers import str2bool
 | 
			
		||||
from InvenTree.views import (AjaxDeleteView, AjaxUpdateView, AjaxView,
 | 
			
		||||
                             InvenTreeRoleMixin, QRCodeView)
 | 
			
		||||
from InvenTree.views import (AjaxUpdateView, AjaxView, InvenTreeRoleMixin,
 | 
			
		||||
                             QRCodeView)
 | 
			
		||||
from order.models import PurchaseOrderLineItem
 | 
			
		||||
from plugin.views import InvenTreePluginViewMixin
 | 
			
		||||
from stock.models import StockItem, StockLocation
 | 
			
		||||
@@ -875,18 +875,3 @@ class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
 | 
			
		||||
                context['starred'] = category.is_starred_by(self.request.user)
 | 
			
		||||
 | 
			
		||||
        return context
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CategoryDelete(AjaxDeleteView):
 | 
			
		||||
    """Delete view to delete a PartCategory."""
 | 
			
		||||
    model = PartCategory
 | 
			
		||||
    ajax_template_name = 'part/category_delete.html'
 | 
			
		||||
    ajax_form_title = _('Delete Part Category')
 | 
			
		||||
    context_object_name = 'category'
 | 
			
		||||
    success_url = '/part/'
 | 
			
		||||
 | 
			
		||||
    def get_data(self):
 | 
			
		||||
        """Return custom context data when the category is deleted"""
 | 
			
		||||
        return {
 | 
			
		||||
            'danger': _('Part category was deleted'),
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user