Standard Migration stabilder

Standard aufgeteilt
This commit is contained in:
Holger Trampe 2021-09-01 09:41:33 +02:00
parent d3e6f136ac
commit 52d4066f66
5 changed files with 54 additions and 28 deletions

View File

@ -13,7 +13,7 @@
<h5 id="cloud_process" style="display: none;">Es werden {{files|length}} Dateien und {{dirs|length}} Ordner angelegt und mit Zugriffsrechten gesetzt.</h5> <h5 id="cloud_process" style="display: none;">Es werden {{files|length}} Dateien und {{dirs|length}} Ordner angelegt und mit Zugriffsrechten gesetzt.</h5>
<div id="cloud_process_main" style="display: none;">Gruppenordner wird angelegt</div> <div id="cloud_process_main" style="display: none;">Gruppenordner wird angelegt</div>
<div id="cloud_process_cloud" style="display: none;"></div> <div id="cloud_process_cloud" style="display: none;"></div>
<div id="cloud_process_standards" style="display: none;">Standarddateien werden neu zugewiesen...</div> <div id="cloud_process_standards" style="display: none;">Standarddateien von {{standard_pk|length}} Standards werden neu zugewiesen...</div>
<div id="cloud_process_standards_error" style="display: none;">Standarddateien konnten nicht zugewiesen werden. Bitte manuell prüfen.</div> <div id="cloud_process_standards_error" style="display: none;">Standarddateien konnten nicht zugewiesen werden. Bitte manuell prüfen.</div>
</div> </div>
<h5 id="migfinished" style="display: none;">Migration vollständig. Bitte diese Seite ausdrucken oder Speichern. Ein erneuter Import ist nicht möglich!</h5> <h5 id="migfinished" style="display: none;">Migration vollständig. Bitte diese Seite ausdrucken oder Speichern. Ein erneuter Import ist nicht möglich!</h5>
@ -22,15 +22,16 @@
var groupids = [{% for g in groups %} "{{g.name}}" {% if forloop.counter < groups|length %}, {% endif %} {% endfor %}]; var groupids = [{% for g in groups %} "{{g.name}}" {% if forloop.counter < groups|length %}, {% endif %} {% endfor %}];
var files = [{% for f in files %} "{{f.pk}}" {% if forloop.counter < files|length %}, {% endif %} {% endfor %}]; var files = [{% for f in files %} "{{f.pk}}" {% if forloop.counter < files|length %}, {% endif %} {% endfor %}];
var standard_files = [{% for f in standard_files %} "{{f.pk}}" {% if forloop.counter < files|length %}, {% endif %} {% endfor %}]; var standard_files = [{% for f in standard_files %} "{{f.pk}}" {% if forloop.counter < standard_files|length %}, {% endif %} {% endfor %}];
var standards = [{% for s in standard_pk %} "{{s}}" {% if forloop.counter < standard_pk|length %}, {% endif %} {% endfor %}];
var dirids = [{% for d in dirs %} "{{d.pk}}" {% if forloop.counter < dirs|length %}, {% endif %} {% endfor %}]; var dirids = [{% for d in dirs %} "{{d.pk}}" {% if forloop.counter < dirs|length %}, {% endif %} {% endfor %}];
$(document).ready(function(){ $(document).ready(function(){
// FIRST CALL GROUPS, When Groups finished User will call by Groups // FIRST CALL GROUPS, When Groups finished User will call by Groups
//createAgencyGroups(groupids[0]); createAgencyGroups(groupids[0]);
//DEV //DEV
rebuildingStandards(); //rebuildingStandards(standards[0]);
//addGroupFolder(); //addGroupFolder();
//addDirs(dirids[0]); //addDirs(dirids[0]);
}) })
@ -204,8 +205,12 @@
addDirs(dirids[dircounter]); addDirs(dirids[dircounter]);
} }
else { else {
rebuildingStandards(); if(standards[0] != undefined){
rebuildingStandards(standards[0]);
}
else{
$("#migfinished").show();
}
} }
} }
}, },
@ -214,23 +219,38 @@
} }
}); });
} }
standardcounter = 0;
//Anlegen der Standarddateien //Anlegen der Standarddateien
function rebuildingStandards(){ function rebuildingStandards(id){
$("#cloud_process_standards").show(); $("#cloud_process_standards").show();
$.ajax({ $.ajax({
url: "{% url 'api:apiswitchstandards' %}", url: "{% url 'api:apiswitchstandards' %}",
dataType: 'json', dataType: 'json',
data: { data: {
'agencyid' : {{agency.pk}}, 'standardid' : id,
}, },
success: function(data){ success: function(data){
if(data['status'] == "OK"){ if(data['status'] == "OK"){
$("#migfinished").show(); standardcounter += 1;
if(standardcounter < standards.length){
console.log("STANDARD " + id + " OK");
rebuildingStandards(standards[standardcounter]);
}
else{
console.log("STANDARD " + id + " OK");
$("#migfinished").show();
}
} }
else{ else{
$("#cloud_process_standards_error").show(); standardcounter += 1;
$("#cloud_process_standards_error").html("FEHLER BEI STANDARD " + data['status']); 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){ error: function(e){

View File

@ -737,10 +737,15 @@ class AdmImportFlow(TemplateView):
for f in s.addedfiles.all(): for f in s.addedfiles.all():
if(f.parent.name == "Standards Uploadbereich"): if(f.parent.name == "Standards Uploadbereich"):
standard_files.append(f) standard_files.append(f)
context.update({'standard_files' : standard_files}) context.update({'standard_files' : standard_files})
# Loading Standard-PKs
standard_pk = []
for s in standards:
standard_pk.append(str(s.pk))
context.update({'standard_pk' : standard_pk})
# LINK TO THE NC-INSTANCE # LINK TO THE NC-INSTANCE
context.update({'nclink' : settings.NEXTCLOUD_URL}) context.update({'nclink' : settings.NEXTCLOUD_URL})
context.update({'ncid' : self.request.user.profile.nc_sid}) context.update({'ncid' : self.request.user.profile.nc_sid})

View File

@ -421,23 +421,22 @@ def getFileIdFromXML(xmlresponse):
''' '''
Standardateien neu zuweisen Standardateien neu zuweisen
Alle Standards werden nacheinander durchgegangen. 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. 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.
''' '''
@api_view(['GET'], ) @api_view(['GET'], )
def NCSwitchStandardFiles(request): def NCSwitchStandardFiles(request):
if request.method == "GET": if request.method == "GET":
agency = Agency.objects.get(pk=request.GET.get('agencyid')) #agency = Agency.objects.get(pk=request.GET.get('agencyid'))
standards = Standards.objects.filter(agency=agency) standard = Standards.objects.get(pk=request.GET.get('standardid'))
response_status = "OK" response_status = "OK"
for s in standards: for f in standard.addedfiles.all():
for f in s.addedfiles.all(): 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:displayname/></d:prop></d:select><d:from><d:scope><d:href>/files/' + settings.NEXTCLOUD_USER_API + '/Agenturdaten_' + str(standard.agency.pk) + '</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:like><d:prop><d:displayname/></d:prop><d:literal>' + f.name + '</d:literal></d:like></d:where></d:basicsearch></d:searchrequest>'
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:displayname/></d:prop></d:select><d:from><d:scope><d:href>/files/' + settings.NEXTCLOUD_USER_API + '/Agenturdaten_' + str(agency.pk) + '</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:like><d:prop><d:displayname/></d:prop><d:literal>' + f.name + '</d:literal></d:like></d:where></d:basicsearch></d:searchrequest>' r = requests.request("SEARCH", settings.NEXTCLOUD_URL + "remote.php/dav", data=filesearchdata, auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API), headers={'Content-Type' : 'text/xml'})
r = requests.request("SEARCH", settings.NEXTCLOUD_URL + "remote.php/dav", data=filesearchdata, auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API), headers={'Content-Type' : 'text/xml'}) fileid = getFileIdFromXML(r.text)
fileid = getFileIdFromXML(r.text) if(fileid == None):
if(fileid == None): response_status += " FEHLER BEI STANDARD " + str(standard.pk) + " "
response_status += " FEHLER BEI STANDARD " + str(s.id) + " " else:
else: ncfile = NCFile.objects.create(agency=standard.agency, nc_id=fileid, file_id=f)
ncfile = NCFile.objects.create(agency=s.agency, nc_id=fileid, file_id=f) standard.addedfiles_nc.add(ncfile)
s.addedfiles_nc.add(ncfile)
return JsonResponse({"status" : response_status}) return JsonResponse({"status" : response_status})
return JsonResponse({"status" : "NO AUTH"}) return JsonResponse({"status" : "NO AUTH"})

View File

@ -1122,7 +1122,9 @@ import urllib.parse
def getNCFileInfos(request, ncid): def getNCFileInfos(request, ncid):
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><d:displayname/></d:prop></d:select><d:from><d:scope><d:href>/files/' + request.user.username + '</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:eq><d:prop><oc:fileid/></d:prop><d:literal>' + str(ncid) + '</d:literal></d:eq></d:where></d:basicsearch></d:searchrequest>' 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><d:displayname/></d:prop></d:select><d:from><d:scope><d:href>/files/' + request.user.username + '</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:eq><d:prop><oc:fileid/></d:prop><d:literal>' + str(ncid) + '</d:literal></d:eq></d:where></d:basicsearch></d:searchrequest>'
r = requests.request("SEARCH", settings.NEXTCLOUD_URL + "remote.php/dav/", data=filesearchdata, headers={'Content-Type' : 'text/xml', 'Authorization' : "Bearer " + request.user.profile.nc_sid}) 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(str(ncid))
print(r.text)
split_response = r.text.split("<d:href>") split_response = r.text.split("<d:href>")
split_fileele = split_response[1].split("</d:href>") split_fileele = split_response[1].split("</d:href>")
split_filename = split_fileele[0].split("/") split_filename = split_fileele[0].split("/")