inventree-import-plugin 0.2.13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- inventree_import_plugin-0.2.13/PKG-INFO +12 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/__init__.py +6 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/api/__init__.py +3 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/api/views.py +155 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/base.py +693 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/compat.py +30 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/core.py +318 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/lcsc_plugin.py +120 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/models.py +41 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/mouser_plugin.py +109 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/providers/__init__.py +9 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/providers/aliexpress.py +68 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/providers/base.py +25 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/providers/lcsc.py +65 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/providers/mouser.py +49 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/providers/registry.py +24 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/services/__init__.py +15 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/services/enrich.py +945 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/.vite/manifest.json +14 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/Settings-BcwGle0E.js +2 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/Settings-BcwGle0E.js.map +1 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/Settings.js +2 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/Settings.js.map +1 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/bulk/StandaloneBulkPage-v3.js +50 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/bulk/StandaloneBulkPage-v3.js.map +1 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/enrich-panel-v15-tujaXfLg.js +2 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/enrich-panel-v15-tujaXfLg.js.map +1 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/enrich-panel-v15.js +2 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/static/enrich-panel-v15.js.map +1 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/suppliers/__init__.py +6 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/suppliers/aliexpress.py +213 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/suppliers/lcsc.py +216 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/suppliers/mouser.py +192 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin/templates/inventree_import_plugin/bulk_page.html +13 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin.egg-info/PKG-INFO +12 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin.egg-info/SOURCES.txt +47 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin.egg-info/dependency_links.txt +1 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin.egg-info/entry_points.txt +2 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin.egg-info/requires.txt +7 -0
- inventree_import_plugin-0.2.13/inventree_import_plugin.egg-info/top_level.txt +1 -0
- inventree_import_plugin-0.2.13/pyproject.toml +42 -0
- inventree_import_plugin-0.2.13/setup.cfg +4 -0
- inventree_import_plugin-0.2.13/tests/test_aliexpress.py +523 -0
- inventree_import_plugin-0.2.13/tests/test_core_plugin.py +252 -0
- inventree_import_plugin-0.2.13/tests/test_enrich.py +1766 -0
- inventree_import_plugin-0.2.13/tests/test_lcsc.py +263 -0
- inventree_import_plugin-0.2.13/tests/test_lcsc_plugin.py +400 -0
- inventree_import_plugin-0.2.13/tests/test_models.py +62 -0
- inventree_import_plugin-0.2.13/tests/test_mouser.py +365 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: inventree-import-plugin
|
|
3
|
+
Version: 0.2.13
|
|
4
|
+
Summary: Combined InvenTree supplier import and enrich plugin for Mouser and LCSC
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: requests>=2.28
|
|
8
|
+
Provides-Extra: dev
|
|
9
|
+
Requires-Dist: pytest; extra == "dev"
|
|
10
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
11
|
+
Requires-Dist: ruff; extra == "dev"
|
|
12
|
+
Requires-Dist: mypy; extra == "dev"
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import pathlib
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from inventree_import_plugin.services import (
|
|
8
|
+
bulk_enrich,
|
|
9
|
+
enrich_part_for_provider,
|
|
10
|
+
get_provider_state,
|
|
11
|
+
parse_bulk_operations,
|
|
12
|
+
parse_bulk_payload,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def build_urlpatterns(plugin: Any) -> list[Any]:
|
|
17
|
+
from django.middleware.csrf import get_token
|
|
18
|
+
from django.shortcuts import render
|
|
19
|
+
from django.urls import path
|
|
20
|
+
from InvenTree.permissions import RolePermission
|
|
21
|
+
from rest_framework.response import Response
|
|
22
|
+
from rest_framework.views import APIView
|
|
23
|
+
|
|
24
|
+
class _BaseRoleView(APIView): # type: ignore[misc]
|
|
25
|
+
permission_classes = [RolePermission]
|
|
26
|
+
role_required = "part.change"
|
|
27
|
+
|
|
28
|
+
class _ProviderStateView(_BaseRoleView):
|
|
29
|
+
def get(inner_self, request: Any, part_id: int) -> Any: # noqa: N805
|
|
30
|
+
return Response(get_provider_state(plugin, part_id))
|
|
31
|
+
|
|
32
|
+
class _PreviewView(_BaseRoleView):
|
|
33
|
+
def get(inner_self, request: Any, part_id: int, provider_slug: str) -> Any: # noqa: N805
|
|
34
|
+
return Response(
|
|
35
|
+
enrich_part_for_provider(
|
|
36
|
+
plugin,
|
|
37
|
+
provider_slug,
|
|
38
|
+
part_id,
|
|
39
|
+
dry_run=True,
|
|
40
|
+
user=getattr(request, "user", None),
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
class _ApplyView(_BaseRoleView):
|
|
45
|
+
def post(inner_self, request: Any, part_id: int, provider_slug: str) -> Any: # noqa: N805
|
|
46
|
+
selected_keys = request.data.get("selected_keys")
|
|
47
|
+
if selected_keys is not None:
|
|
48
|
+
selected_keys = set(selected_keys)
|
|
49
|
+
return Response(
|
|
50
|
+
enrich_part_for_provider(
|
|
51
|
+
plugin,
|
|
52
|
+
provider_slug,
|
|
53
|
+
part_id,
|
|
54
|
+
dry_run=False,
|
|
55
|
+
selected_keys=selected_keys,
|
|
56
|
+
user=getattr(request, "user", None),
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
class _BulkPreviewView(_BaseRoleView):
|
|
61
|
+
def post(inner_self, request: Any) -> Any: # noqa: N805
|
|
62
|
+
try:
|
|
63
|
+
part_ids, provider_slugs = parse_bulk_payload(plugin, request)
|
|
64
|
+
except ValueError as exc:
|
|
65
|
+
return Response({"detail": str(exc)}, status=400)
|
|
66
|
+
return Response(
|
|
67
|
+
bulk_enrich(
|
|
68
|
+
plugin,
|
|
69
|
+
part_ids,
|
|
70
|
+
provider_slugs,
|
|
71
|
+
dry_run=True,
|
|
72
|
+
user=getattr(request, "user", None),
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
class _BulkApplyView(_BaseRoleView):
|
|
77
|
+
def post(inner_self, request: Any) -> Any: # noqa: N805
|
|
78
|
+
try:
|
|
79
|
+
if "operations" in request.data:
|
|
80
|
+
operations = parse_bulk_operations(plugin, request)
|
|
81
|
+
return Response(
|
|
82
|
+
bulk_enrich(
|
|
83
|
+
plugin,
|
|
84
|
+
dry_run=False,
|
|
85
|
+
operations=operations,
|
|
86
|
+
user=getattr(request, "user", None),
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
part_ids, provider_slugs = parse_bulk_payload(plugin, request)
|
|
90
|
+
return Response(
|
|
91
|
+
bulk_enrich(
|
|
92
|
+
plugin,
|
|
93
|
+
part_ids,
|
|
94
|
+
provider_slugs,
|
|
95
|
+
dry_run=False,
|
|
96
|
+
user=getattr(request, "user", None),
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
except ValueError as exc:
|
|
100
|
+
return Response({"detail": str(exc)}, status=400)
|
|
101
|
+
|
|
102
|
+
class _BulkPageView(_BaseRoleView):
|
|
103
|
+
_bundle_path = (
|
|
104
|
+
pathlib.Path(__file__).resolve().parent.parent
|
|
105
|
+
/ "static"
|
|
106
|
+
/ "bulk"
|
|
107
|
+
/ "StandaloneBulkPage-v3.js"
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
def get(inner_self, request: Any) -> Any: # noqa: N805
|
|
111
|
+
active_providers = [
|
|
112
|
+
{
|
|
113
|
+
"slug": adapter.definition.slug,
|
|
114
|
+
"name": adapter.definition.name,
|
|
115
|
+
}
|
|
116
|
+
for adapter in plugin._get_active_provider_adapters(require_complete_config=True)
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
bundle_js = ""
|
|
120
|
+
if inner_self._bundle_path.exists():
|
|
121
|
+
bundle_js = inner_self._bundle_path.read_text(encoding="utf-8")
|
|
122
|
+
|
|
123
|
+
context = {
|
|
124
|
+
"bundle_js": bundle_js,
|
|
125
|
+
"mount_context_json": json.dumps(
|
|
126
|
+
{
|
|
127
|
+
"pluginSlug": plugin.SLUG,
|
|
128
|
+
"previewUrl": f"/plugin/{plugin.SLUG}/api/bulk/preview/",
|
|
129
|
+
"applyUrl": f"/plugin/{plugin.SLUG}/api/bulk/apply/",
|
|
130
|
+
"csrfToken": get_token(request),
|
|
131
|
+
"providers": active_providers,
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
}
|
|
135
|
+
return render(request, "inventree_import_plugin/bulk_page.html", context)
|
|
136
|
+
|
|
137
|
+
return [
|
|
138
|
+
path(
|
|
139
|
+
"api/part/<int:part_id>/providers/", _ProviderStateView.as_view(), name="provider-state"
|
|
140
|
+
),
|
|
141
|
+
path(
|
|
142
|
+
"api/part/<int:part_id>/preview/<str:provider_slug>/",
|
|
143
|
+
_PreviewView.as_view(),
|
|
144
|
+
name="preview-enrich",
|
|
145
|
+
),
|
|
146
|
+
path(
|
|
147
|
+
"api/part/<int:part_id>/apply/<str:provider_slug>/",
|
|
148
|
+
_ApplyView.as_view(),
|
|
149
|
+
name="apply-enrich",
|
|
150
|
+
),
|
|
151
|
+
path("api/bulk/preview/", _BulkPreviewView.as_view(), name="bulk-preview"),
|
|
152
|
+
path("api/bulk/apply/", _BulkApplyView.as_view(), name="bulk-apply"),
|
|
153
|
+
path("bulk/", _BulkPageView.as_view(), name="bulk-page"),
|
|
154
|
+
path("bulk-v2/", _BulkPageView.as_view(), name="bulk-page-v2"),
|
|
155
|
+
]
|