Upload von Dateien Done
This commit is contained in:
parent
15363595d8
commit
cfc428e59e
|
|
@ -162,10 +162,9 @@ def adddirbyajax(request, parent):
|
|||
data = {'filename' : fileobj.name, 'linked_standards' : linked_standards_final}
|
||||
# CHECK DOUBLE FILENAME
|
||||
elif(request.GET.get("action") == "check_doublefile"):
|
||||
fileobj = list(DataFile.objects.filter(name__icontains=request.GET.get('name'), agency=request.user.profile.agency))
|
||||
if len(fileobj) > 0:
|
||||
data = {"found" : True}
|
||||
else:
|
||||
#fileobj = list(DataFile.objects.filter(name__icontains=request.GET.get('name'), agency=request.user.profile.agency))
|
||||
#if len(fileobj) > 0:
|
||||
#else:
|
||||
data = {"found" : False}
|
||||
# DELETE FILE
|
||||
elif(request.GET.get("action") == "del_file"):
|
||||
|
|
@ -243,8 +242,6 @@ def adddirbyajax(request, parent):
|
|||
uploadsource = request.POST["uploadsource"]
|
||||
replace = request.POST["replace"]
|
||||
|
||||
print(replace)
|
||||
|
||||
# DECODE
|
||||
request.decoding = 'utf-8'
|
||||
|
||||
|
|
|
|||
|
|
@ -1229,7 +1229,7 @@ function doUploadAction(filetodo, replacestat){
|
|||
|
||||
if(c && filetodo.type.length > 0){
|
||||
$.ajax({
|
||||
url: "{% url 'cloud-adddir' parentid %}",
|
||||
url: "{% url 'standard-uploadfile' %}",
|
||||
headers: {
|
||||
"X-CSRFTOKEN": "{{ csrf_token }}"
|
||||
},
|
||||
|
|
@ -1252,6 +1252,7 @@ function doUploadAction(filetodo, replacestat){
|
|||
return xhr;
|
||||
},
|
||||
success: function(data) {
|
||||
console.log(data);
|
||||
if(data["success"] == true){
|
||||
setTimeout(function(){
|
||||
hideUpload();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ urlpatterns = [
|
|||
path('standardcopy/<int:pk>', views.CopyStandard, name="standard-copyagn"),
|
||||
path('loadaggroupm/', views.LoadAGGroupMembers, name="standard-loadaggroupmembers"),
|
||||
path('standard/update/', views.UpdateStandardBeforeUserDel, name="standard-update-before-user-del"),
|
||||
path('standard/download/<int:nc_id>', views.getFileFromStandard, name="standard-loadfile")
|
||||
path('standard/download/<int:nc_id>', views.getFileFromStandard, name="standard-loadfile"),
|
||||
path('standard/upload/', views.uploadFileFromStandard, name="standard-uploadfile")
|
||||
|
||||
]
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
from os import SEEK_CUR
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.models import User
|
||||
|
|
@ -212,11 +213,24 @@ def StandardAdd(request, id=False):
|
|||
if(s.isdigit()):
|
||||
new_standard.linked_standards.add(Standards.objects.get(pk=s))
|
||||
|
||||
# ADD FILES
|
||||
#files = normalForm.cleaned_data['added_files'].split(",")
|
||||
#for f in files:
|
||||
# if(f.isdigit()):
|
||||
# new_standard.addedfiles.add(DataFile.objects.get(pk=f))
|
||||
|
||||
# ADD FILES
|
||||
files = normalForm.cleaned_data['added_files'].split(",")
|
||||
for f in files:
|
||||
if(f.isdigit()):
|
||||
new_standard.addedfiles.add(DataFile.objects.get(pk=f))
|
||||
ncfile = NCFile.objects.filter(nc_id=f).first()
|
||||
# Wenn die NC-File in Django nicht existiert, dann neu erstellen und hinzufügen. Trifft für Dateien zu, die zwar in den Dateien waren, aber noch nicht in der NC!
|
||||
if(ncfile == None):
|
||||
new_nc_file = NCFile(nc_id=f, agency=new_standard.agency)
|
||||
new_nc_file.save()
|
||||
new_standard.addedfiles_nc.add(new_nc_file)
|
||||
else:
|
||||
new_standard.addedfiles_nc.add(ncfile)
|
||||
|
||||
# ADD QUICKLINKS
|
||||
quicklinks = normalForm.cleaned_data['added_quicklinks'].split(",")
|
||||
|
|
@ -265,15 +279,34 @@ def StandardAdd(request, id=False):
|
|||
r = requests.request("PROPFIND", settings.NEXTCLOUD_URL + "remote.php/dav/files/" + request.user.username + "/Agenturdaten_1/", headers=nc_login_headers, data=data_nc)
|
||||
print(r.text)
|
||||
|
||||
allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
|
||||
#allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
|
||||
|
||||
for f in allfiles:
|
||||
actParent = DataDir.objects.get(pk=f.parent.pk)
|
||||
if actParent.is_root:
|
||||
possibleFilesByVisible.append(f)
|
||||
else:
|
||||
if(checkUserDirRights(request, actParent, request.user.pk)):
|
||||
possibleFilesByVisible.append(f)
|
||||
#for f in allfiles:
|
||||
# actParent = DataDir.objects.get(pk=f.parent.pk)
|
||||
# if actParent.is_root:
|
||||
# possibleFilesByVisible.append(f)
|
||||
# else:
|
||||
# if(checkUserDirRights(request, actParent, request.user.pk)):
|
||||
# possibleFilesByVisible.append(f)
|
||||
possibleFilesByVisible = []
|
||||
|
||||
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/' + request.user.username + '/Agenturdaten/</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
|
||||
try:
|
||||
split_response = r.text.split("<oc:fileid>")
|
||||
|
||||
# Header des XML-Response entfernen
|
||||
split_response.pop(0)
|
||||
|
||||
# IDs from the User
|
||||
for ele in split_response:
|
||||
new_id = ele.split("</oc:fileid>")[0]
|
||||
possibleFilesByVisible.append(new_id)
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
context = {
|
||||
'normalForm' : normalForm,
|
||||
|
|
@ -296,7 +329,6 @@ def StandardAdd(request, id=False):
|
|||
standard = Standards.objects.get(pk=id, agency=request.user.profile.agency)
|
||||
# SAVE UPDATED STANDARD
|
||||
if request.method == 'POST':
|
||||
|
||||
# CHECK IF USER HAS RIGHTS TO SEE THIS DIR
|
||||
groupsofstandard = standard
|
||||
|
||||
|
|
@ -1157,3 +1189,50 @@ def UpdateStandardBeforeUserDel(request):
|
|||
|
||||
return JsonResponse({"success" : success})
|
||||
|
||||
|
||||
'''
|
||||
UPLOADING A FILE
|
||||
|
||||
Replace the function in the App CLOUD
|
||||
'''
|
||||
@login_required
|
||||
def uploadFileFromStandard(request):
|
||||
success = True
|
||||
if request.method == 'POST':
|
||||
|
||||
request.decoding = 'utf-8'
|
||||
|
||||
# VALIDATE FILE-TYPE
|
||||
file_ext_arr = request.FILES['uploadedfile'].name.split(".")
|
||||
file_ext = file_ext_arr[len(file_ext_arr)-1]
|
||||
allowed_types = ["txt", "TXT", "png", "PNG", "jpeg", "JPEG", "jpg", "JPG", "PDF", "pdf", "csv", "CSV", "DOC", "doc", "DOCX", "docx", "ODT", "odt", "PPT", "ppt", "PPTX", "pptx", "XLS", "xls", "XLSX", "xlsx", "xlsm", "XLSM", "mov", "MOV", "SVG", "svg", "ZIP", "zip", "RAR", "rar", "EPS", "eps", "MP3", "mp3", "WAV", "wav", "avi", "AVI", "FLV", "flv", "MP4", "mp4", "PAGES", "pages", "NUMBERS", "numbers", "ics", "ICS"]
|
||||
file_ok = False
|
||||
|
||||
for t in allowed_types:
|
||||
if t == file_ext:
|
||||
file_ok = True
|
||||
|
||||
if(file_ok):
|
||||
final_file_path = settings.NEXTCLOUD_URL + "remote.php/dav/files/admin/Agenturdaten/Standards Uploadbereich/" + request.FILES['uploadedfile'].name
|
||||
|
||||
r = requests.put(final_file_path, data=request.FILES['uploadedfile'], auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API))
|
||||
if(len(r.text) == 0):
|
||||
try:
|
||||
new_file_name = request.FILES['uploadedfile'].name
|
||||
# Upload OK - get File-ID in NC
|
||||
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/' + request.user.username + '</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:like><d:prop><d:displayname/></d:prop><d:literal>' + new_file_name + '</d:literal></d:like></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})
|
||||
#print(r.text)
|
||||
split_response = r.text.split("<oc:fileid>")
|
||||
new_id = split_response[1].split("</oc:fileid>")[0]
|
||||
|
||||
tf = NCFile(agency=request.user.profile.agency, nc_id=new_id)
|
||||
tf.save()
|
||||
return JsonResponse({"success" : success, "data" : {'savedobj_id' : new_id, 'savedobj_name' : new_file_name}})
|
||||
except:
|
||||
success = False
|
||||
return JsonResponse({"success" : success, "data" : "ERROR"})
|
||||
|
||||
return JsonResponse({"success" : success, "data" : "DONE!"})
|
||||
|
||||
return JsonResponse({"success" : success, "data" : "DONE!"})
|
||||
Loading…
Reference in New Issue