This commit is contained in:
Holger Trampe 2021-10-23 12:50:33 +02:00
parent 5f638c1701
commit 3086a37bf6
2 changed files with 88 additions and 3 deletions

View File

@ -241,6 +241,7 @@
var ncfiledata = [];
//Anlegen der Standarddateien
function rebuildingStandards(id){
/*
ncfiledata.splice(0, ncfiledata.length);
$("#cloud_process_standards").show();
ncfiledata[0] = ['standardid', id];
@ -295,6 +296,42 @@
});
}
});
*/
$.ajax({
url: "{% url 'api:apiswitchstandards' %}",
dataType: 'json',
data: {
'standardid' : id,
},
success: function(data){
if(data['status'] == "OK"){
standardcounter += 1;
if(standardcounter < standards.length){
console.log("STANDARD " + id + " OK");
rebuildingStandards(standards[standardcounter]);
}
else{
console.log("STANDARD " + id + " OK");
$("#migfinished").show();
}
}
else{
standardcounter += 1;
console.log("FEHLER BEI STANDARD " + data['status'] + " ID " + id);
if(standardcounter < standards.length){
rebuildingStandards(standards[standardcounter]);
}
else{
console.log("FEHLER BEI STANDARD " + data['status'] + " ID " + id);
$("#migfinished").show();
}
}
},
error: function(e){
console.log(e);
}
});
}
</script>
</div>

View File

@ -437,12 +437,59 @@ def getFileIdFromXML(xmlresponse):
Pro Datei in addedfiles wird ein neues NCFile-Objekt erstellt und in addedfiles_nc gespeichert. In den Ansichten der Standards werden dann nur noch die addedfiles_nc-Elemente gesehen und verändert.
'''
import re, json
@api_view(['POST'], )
from urllib.parse import unquote
@api_view(['GET'], )
def NCSwitchStandardFiles(request):
if request.method == "POST":
if request.method == "GET":
standard = Standards.objects.get(pk=request.GET.get('standardid'))
response_status = "OK"
# Dateien aus NC laden
# TODO: HIER WIEDER DEN USER EINTRAGEN vhdarootadmin_2cdme7ckw
filesearchdata = '<?xml version="1.0" encoding="UTF-8"?><d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"><d:basicsearch><d:select><d:prop><oc:fileid/></d:prop></d:select><d:from><d:scope><d:href>/files/vhdarootadmin_2cdme7ckw' + '/Agenturdaten_' + str(standard.agency.pk) + '/</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:gt><d:prop><oc:size/></d:prop><d:literal>1</d:literal></d:gt></d:where></d:basicsearch></d:searchrequest>'
#filesearchdata = '<?xml version="1.0" encoding="UTF-8"?><d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"><d:prop><oc:fileid /></d:prop><d:depth>infinity</d:depth></d:propfind>'
r = requests.request("SEARCH", settings.NEXTCLOUD_URL + "remote.php/dav/", data=filesearchdata, headers={'Content-Type' : 'text/xml', 'Authorization' : "Bearer " + request.user.profile.nc_sid})
print(r.text)
# IDs filtern aus XML-Response
#print(r.text)
ncfileids = [str(s) for s in re.findall('<d:response>(.+?)</d:response>', r.text)]
final_nc_files = []
# IDs from the User
for ele in ncfileids:
nc_filename_with_path = [str(s) for s in re.findall('<d:href>(.+?)</d:href>', ele)][0]
nc_filename_with_path = nc_filename_with_path.split("/")
filename = nc_filename_with_path[len(nc_filename_with_path)-1]
nc_file_id = [str(s) for s in re.findall('<oc:fileid>(.+?)</oc:fileid>', ele)][0]
if(len(filename) > 0):
final_nc_files.append([nc_file_id, unquote(filename, errors="strict")])
# Reset der NC-Files
for nc_standard_file in standard.addedfiles_nc.all():
nc_standard_file.delete()
standard.addedfiles_nc.clear()
standard.save()
for f in standard.addedfiles.all():
for nc_file_ele in final_nc_files:
print(f.name + " NAME " + nc_file_ele[1])
if(f.name == nc_file_ele[1]):
ncfile = NCFile.objects.create(agency=standard.agency, nc_id=nc_file_ele[0], file_id=f)
standard.addedfiles_nc.add(ncfile)
response_status += " DATEI " + f.name + " ZU STANDARD " + str(standard.pk) + " zugeordnet. - NC FILE ID " + str(nc_file_ele[0])
print("ZUGEORDNET!")
return JsonResponse({"status" : response_status})
return JsonResponse({"status" : "NO AUTH"})
'''
if request.method == "GET":
#agency = Agency.objects.get(pk=request.GET.get('agencyid'))
jsonresponse = json.dumps(request.POST)
jsonresponse = json.dumps(request.GET)
json_final = json.loads(jsonresponse)
standardid = False
ncfiledata = False
@ -474,6 +521,7 @@ def NCSwitchStandardFiles(request):
return JsonResponse({"status" : response_status})
return JsonResponse({"status" : "NO AUTH"})
'''
@api_view(['GET'], )
def NCGetFilesForStandardSwitch(request):