fixed xml-export path construction

This commit is contained in:
dreng
2023-06-04 08:52:17 +02:00
parent 8f520f9a6a
commit 873c757606
3 changed files with 7 additions and 8 deletions
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -81,7 +81,7 @@ const coordSaveCheckbox = document.querySelector('#id_save_coords')
async ([nodeId, nodePosition]) => {
window.nodes.update({id: parseInt(nodeId), physics: false, x: nodePosition.x, y: nodePosition.y});
const res = await fetch(
'/api/plugins/netbox_topology_views/save-coords/save_coords/',
'/' + basePath + 'api/plugins/netbox_topology_views/save-coords/save_coords/',
{
method: 'PATCH',
headers: {
@@ -171,7 +171,7 @@ function performXmlDownload() {
fetch('/api/plugins/netbox_topology_views/xml-export/?' + xml_search_options).then(response => response.text())
fetch('/' + basePath + 'api/plugins/netbox_topology_views/xml-export/?' + xml_search_options).then(response => response.text())
.then(data => {
var blob = new Blob([data ], { type: "text/plain" });
+4 -5
View File
@@ -35,12 +35,11 @@ def image_static_url(path: Path) -> str:
def get_image_from_url(url: str) -> str:
url_path = settings.BASE_PATH + settings.STATIC_URL
if sys.version_info >= (3,9,0):
return url.removeprefix(url_path)
return url.removeprefix(settings.STATIC_URL)
else:
if url.startswith(url_path):
url_new = url[len(url_path):]
if url.startswith(settings.STATIC_URL):
url_new = url[len(settings.STATIC_URL):]
return url_new
else:
return url
@@ -250,7 +249,7 @@ def export_data_to_xml(data: dict):
noPositionX = 0
noPositionY = 1000
for node in data['nodes']:
with open(str(Path(settings.BASE_DIR)) + node['image'], "rb") as img:
with open(settings.STATIC_ROOT + '/' + get_image_from_url(node['image']), "rb") as img:
svg = base64.b64encode(img.read()).decode('utf-8')
mxcell = doc.createElement('mxCell')
mxcell.setAttribute('id', 'node_' + str(node['id']))