part of get data
This commit is contained in:
parent
698f791920
commit
b71ebfc398
|
@ -44,6 +44,21 @@ class PartnerViewSet(viewsets.ModelViewSet):
|
||||||
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
|
|
||||||
|
def get_depth_cat(id):
|
||||||
|
params = {
|
||||||
|
"$format": "json",
|
||||||
|
"$select": ",".join(["Description", "Ref_Key", "Parent_Key"]),
|
||||||
|
"$filter": f"Parent_Key eq guid'{id}'",
|
||||||
|
}
|
||||||
|
remote_url = (
|
||||||
|
"https://1c.svs-tech.pro/UNF/odata/standard.odata/Catalog_КатегорииНоменклатуры?"
|
||||||
|
+ "&".join([f"{p}={params[p]}" for p in params])
|
||||||
|
)
|
||||||
|
data = requests.get(remote_url, headers={"Authorization": settings.ODATA_AUTH})
|
||||||
|
parsed_data = data.json()
|
||||||
|
return parsed_data["value"]
|
||||||
|
|
||||||
|
|
||||||
class ElementViewSet(viewsets.ModelViewSet):
|
class ElementViewSet(viewsets.ModelViewSet):
|
||||||
"""
|
"""
|
||||||
API endpoint that allows elements to be viewed or edited.
|
API endpoint that allows elements to be viewed or edited.
|
||||||
|
@ -55,32 +70,22 @@ class ElementViewSet(viewsets.ModelViewSet):
|
||||||
@action(detail=False, methods=["get"], url_path=r"external_categories")
|
@action(detail=False, methods=["get"], url_path=r"external_categories")
|
||||||
def get_remote_categories(self, request):
|
def get_remote_categories(self, request):
|
||||||
try:
|
try:
|
||||||
params = {
|
all_categories = []
|
||||||
"$format": "json",
|
categories = get_depth_cat("a6aadfe8-7e0f-11ee-ab5a-a47a2bd811cb")
|
||||||
"$select": ",".join(["Description", "Ref_Key", "Parent_Key"]),
|
for category in categories:
|
||||||
"$filter": "Parent_Key eq guid'a6aadfe8-7e0f-11ee-ab5a-a47a2bd811cb'",
|
depth = get_depth_cat(category["Ref_Key"])
|
||||||
}
|
if len(depth):
|
||||||
remote_url = (
|
for cat2 in depth:
|
||||||
"https://1c.svs-tech.pro/UNF/odata/standard.odata/Catalog_КатегорииНоменклатуры?"
|
depth2 = get_depth_cat(cat2["Ref_Key"])
|
||||||
+ "&".join([f"{p}={params[p]}" for p in params])
|
if len(depth2):
|
||||||
)
|
for cat3 in depth2:
|
||||||
data = requests.get(
|
depth3 = get_depth_cat(cat3["Ref_Key"])
|
||||||
remote_url, headers={"Authorization": settings.ODATA_AUTH}
|
all_categories.append(depth3)
|
||||||
)
|
else:
|
||||||
parsed_data = data.json()
|
all_categories.append(depth2)
|
||||||
|
else:
|
||||||
params["$filter"] = " or ".join(
|
all_categories.append(depth)
|
||||||
[f"Parent_Key eq guid'{v['Ref_Key']}'" for v in parsed_data["value"]]
|
return Response(categories)
|
||||||
)
|
|
||||||
remote_url = (
|
|
||||||
"https://1c.svs-tech.pro/UNF/odata/standard.odata/Catalog_КатегорииНоменклатуры?"
|
|
||||||
+ "&".join([f"{p}={params[p]}" for p in params])
|
|
||||||
)
|
|
||||||
data = requests.get(
|
|
||||||
remote_url, headers={"Authorization": settings.ODATA_AUTH}
|
|
||||||
)
|
|
||||||
parsed_data = data.json()
|
|
||||||
return Response(parsed_data["value"])
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
|
|
Loading…
Reference in New Issue