diff --git a/adm/templates/adm/adm_import_flow.html b/adm/templates/adm/adm_import_flow.html index 81369c5..6859577 100644 --- a/adm/templates/adm/adm_import_flow.html +++ b/adm/templates/adm/adm_import_flow.html @@ -238,9 +238,72 @@ }); } standardcounter = 0; + var ncfiledata = [false]; //Anlegen der Standarddateien function rebuildingStandards(id){ $("#cloud_process_standards").show(); + if(ncfiledata[0] == false) + { + + ncfiledata[0] = ['standardid', id]; + console.log("LOADING NC FILES"); + $.ajax({ + url: "{% url 'api:apiswitchstandardsprepare' %}", + dataType: 'json', + data: { + 'standardid' : id, + }, + success: function(data) + { + ncfiledata.push(data); + console.log(ncfiledata); + rebuildingStandards(id); + } + }); + } + else + { + console.log("NC FILES LOADED, STARTING REBUILDING STANDARDS"); + $.ajax({ + url: "{% url 'api:apiswitchstandards' %}", + dataType: 'json', + data: JSON.stringify(ncfiledata), + 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); + } + }); + } + + + + + + + /* $.ajax({ url: "{% url 'api:apiswitchstandards' %}", dataType: 'json', @@ -275,6 +338,7 @@ console.log(e); } }); + */ } diff --git a/api/urls.py b/api/urls.py index 6c7d644..e6e8595 100644 --- a/api/urls.py +++ b/api/urls.py @@ -21,6 +21,7 @@ urlpatterns = [ path('addstandardfile/', views.NCAddStandardFiles, name="apiaddstandardfile"), path('adddir/', views.NCAddDirs, name="apiadddir"), path('addswitchstandards/', views.NCSwitchStandardFiles, name="apiswitchstandards"), + path('prepareswitchstandards/', views.NCGetFilesForStandardSwitch, name="apiswitchstandardsprepare"), path('setlog/', views.SetUserData, name="apisetlog"), # EXTERNAL FROM NC diff --git a/api/views.py b/api/views.py index fa4768a..ca34ca3 100644 --- a/api/views.py +++ b/api/views.py @@ -436,31 +436,76 @@ 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(['GET'], ) def NCSwitchStandardFiles(request): if request.method == "GET": + #agency = Agency.objects.get(pk=request.GET.get('agencyid')) - standard = Standards.objects.get(pk=request.GET.get('standardid')) - response_status = "OK" - for f in standard.addedfiles.all(): + jsonresponse = json.dumps(request.GET) + json_final = json.loads(jsonresponse) + standardid = False + ncfiledata = False + elejson = "" + + for ele in json_final: + elejson = json.loads(ele) + standardid = elejson[0][1] - filesearchdata = '/files/' + settings.NEXTCLOUD_USER_API + '/Agenturdaten_' + str(standard.agency.pk) + 'infinity' + f.name + '' - try: - 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) - except: - response_status += " FEHLER BEI STANDARD " + str(standard.pk) + " " - return JsonResponse({"status" : response_status}) - if(fileid == None): - response_status += " DATEI NICHT GEFUNDEN BEI STANDARD " + str(standard.pk) + " " - else: - ncfile = NCFile.objects.create(agency=standard.agency, nc_id=fileid, file_id=f) + ncfiledata = elejson[1]['ncfiledata'] + + response_status = "OK" + standard = Standards.objects.get(pk=standardid) + + # 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 ncfiledata: + 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) - return JsonResponse({"status" : response_status}) - + response_status += " DATEI " + f.name + " ZU STANDARD " + str(standard.pk) + " zugeordnet. - NC FILE ID " + str(nc_file_ele[0]) + return JsonResponse({"status" : response_status}) return JsonResponse({"status" : "NO AUTH"}) +@api_view(['GET'], ) +def NCGetFilesForStandardSwitch(request): + if request.method == "GET": + #agency = Agency.objects.get(pk=request.GET.get('agencyid')) + standard = Standards.objects.get(pk=request.GET.get('standardid')) + + # Dateien aus NC laden + filesearchdata = '/files/vhdadjangoapi_8fjz47epc6' + '/Agenturdaten_' + str(standard.agency.pk) + '/infinity1' + + #filesearchdata = 'infinity' + r = requests.request("SEARCH", settings.NEXTCLOUD_URL + "remote.php/dav/", data=filesearchdata, headers={'Content-Type' : 'text/xml', 'Authorization' : "Bearer " + request.user.profile.nc_sid}) + # IDs filtern aus XML-Response + #print(r.text) + ncfileids = [str(s) for s in re.findall('(.+?)', r.text)] + final_nc_files = [] + # IDs from the User + for ele in ncfileids: + nc_filename_with_path = [str(s) for s in re.findall('(.+?)', 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('(.+?)', ele)][0] + + if(len(filename) > 0): + final_nc_files.append([nc_file_id, filename]) + + return JsonResponse({"ncfiledata" : final_nc_files}) + + + @api_view(['GET'], ) def deleteNCFile(request, fid, secretkey): if request.method == "GET": diff --git a/standards/views.py b/standards/views.py index dadc060..8dd7100 100644 --- a/standards/views.py +++ b/standards/views.py @@ -500,16 +500,17 @@ def StandardAdd(request, id=False): users_of_other_ag = User.objects.filter(profile__agency=agn_admin) for u in users_of_other_ag: if u.has_perm('users.standardmanager') and u.has_perm('users.agencynetwork'): - if u.usernotifications.agn_standard_created_mail: - notificationtext = "im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name - sendMailNoti(notificationtext, u) + pass + #if u.usernotifications.agn_standard_created_mail: + # notificationtext = "im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name + #sendMailNoti(notificationtext, u) - if u.usernotifications.agn_standard_created_push: - newnotification = UserNotification(touser=u, notificationtext="im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name, notificationtype="") - newnotification.save() + #if u.usernotifications.agn_standard_created_push: + # newnotification = UserNotification(touser=u, notificationtext="im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name, notificationtype="") + # newnotification.save() - channel_layer = channels.layers.get_channel_layer() - async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Agenturverbund | Im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name}) + # channel_layer = channels.layers.get_channel_layer() + # async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Agenturverbund | Im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name}) for agn_admin in agencynetwork_single.members.all(): if(agn_admin not in agency_send): agency_send.append(agn_admin) @@ -517,16 +518,17 @@ def StandardAdd(request, id=False): users_of_other_ag = User.objects.filter(profile__agency=agn_admin) for u in users_of_other_ag: if u.has_perm('users.standardmanager') and u.has_perm('users.agencynetwork'): - if u.usernotifications.agn_standard_created_mail: - notificationtext = "im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name - sendMailNoti(notificationtext, u) + pass + #if u.usernotifications.agn_standard_created_mail: + #notificationtext = "im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name + #sendMailNoti(notificationtext, u) - if u.usernotifications.agn_standard_created_push: - newnotification = UserNotification(touser=u, notificationtext="im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name, notificationtype="") - newnotification.save() + #if u.usernotifications.agn_standard_created_push: + #newnotification = UserNotification(touser=u, notificationtext="im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name, notificationtype="") + #newnotification.save() - channel_layer = channels.layers.get_channel_layer() - async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Agenturverbund | Im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name}) + #channel_layer = channels.layers.get_channel_layer() + #async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Agenturverbund | Im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name}) for agn_admin in agencynetwork_single.sharemembers.all(): if(agn_admin not in agency_send): agency_send.append(agn_admin) @@ -534,16 +536,17 @@ def StandardAdd(request, id=False): users_of_other_ag = User.objects.filter(profile__agency=agn_admin) for u in users_of_other_ag: if u.has_perm('users.standardmanager') and u.has_perm('users.agencynetwork'): - if u.usernotifications.agn_standard_created_mail: - notificationtext = "im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name - sendMailNoti(notificationtext, u) + pass + #if u.usernotifications.agn_standard_created_mail: + # notificationtext = "im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name + # sendMailNoti(notificationtext, u) - if u.usernotifications.agn_standard_created_push: - newnotification = UserNotification(touser=u, notificationtext="im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name, notificationtype="") - newnotification.save() + #if u.usernotifications.agn_standard_created_push: + # newnotification = UserNotification(touser=u, notificationtext="im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name, notificationtype="") + # newnotification.save() - channel_layer = channels.layers.get_channel_layer() - async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Agenturverbund | Im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name}) + # channel_layer = channels.layers.get_channel_layer() + # async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Agenturverbund | Im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name}) # Clear sended Agencys for multiple Networks agency_send = []