Vorbereitet für Standards mit Umlauten Test fuer Mueske

This commit is contained in:
Holger Trampe 2021-10-23 11:35:37 +02:00
parent fb388a2ec5
commit b8c7f27dd3
4 changed files with 153 additions and 40 deletions

View File

@ -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);
}
});
*/
}
</script>
</div>

View File

@ -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

View File

@ -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 = '<?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>'
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 = '<?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/vhdadjangoapi_8fjz47epc6' + '/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})
# 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, filename])
return JsonResponse({"ncfiledata" : final_nc_files})
@api_view(['GET'], )
def deleteNCFile(request, fid, secretkey):
if request.method == "GET":

View File

@ -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 = []