2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-09 21:30:54 +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:
Oliver
2022-06-11 21:53:26 +10:00
committed by GitHub
parent 63f1e58ca9
commit 090f4f4387
14 changed files with 100 additions and 249 deletions

View File

@@ -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 %}

View File

@@ -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 %}

View File

@@ -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

View File

@@ -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'),
}