Standard File Download rdy

This commit is contained in:
Holger Trampe 2021-09-01 11:28:02 +02:00
parent 12d4de29d3
commit fc35ce24ac
6 changed files with 35 additions and 13 deletions

View File

@ -136,15 +136,19 @@
<div class="card-body">
<h5 class="card-title">Dateien</h5>
<p class="card-text">
{% for files in standard.addedfiles_nc.all %}
<!--<a href="{% url 'cloud-td' files.pk %}" target="_blank">{{files.name|truncatechars:30}}</a><br />-->
TODO: HIER DOWNLOAD ERMÖGLICH: {{files.nc_id}}
{% for file in standard.addedfiles_nc.all %}
{% getNCFileInfos request file.nc_id as filename %}
{% getNCFileInfosURL request file.nc_id as filelink %}
{% getNextcloudURL as nc_url %}
<a href="{{nc_url}}{{filelink}}" target="_blank">{{filename|truncatechars:30}}</a><br />
{% endfor %}
</p>
</div>
</div>
{% endif %}
<!-- Quicklinks -->
{% if standard.addedquicklinks.all|length > 0 %}
<div class="card col-14 ml-1 mb-2" style="min-width: 110%">

View File

@ -72,13 +72,14 @@
<!-- FILES -->
{% if standard.addedfiles.all|length > 0 %}
{% if standard.addedfiles_nc.all|length > 0 %}
<div class="card col-14 ml-1 mb-2" style="">
<div class="card-body">
<h5 class="card-title">Dateien</h5>
<p class="card-text">
{% for files in standard.addedfiles.all %}
{{files.name|truncatechars:30}}<br />
{% for files in standard.addedfiles_nc.all %}
{% getNCFileInfos request files.nc_id as filename %}
{{filename|truncatechars:30}}<br />
{% endfor %}
</p>
</div>

View File

@ -1132,5 +1132,22 @@ def getNCFileInfos(request, ncid):
except:
return "FAIL_TO_LOAD_NC_FILE_DATA"
@register.simple_tag
def getNextcloudURL():
return settings.NEXTCLOUD_URL
@register.simple_tag
def getNCFileInfosURL(request, ncid):
try:
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})
print(r.text)
split_response = r.text.split("<d:href>")
split_fileele = split_response[1].split("</d:href>")
# Return file-link except first slash in string
return split_fileele[0][1:]
#return urllib.parse.unquote(split_filenameclear)
except:
return ""

View File

@ -26,6 +26,7 @@ urlpatterns = [
path('standardsagn/<int:pk>', views.StandardFromAgn, name="standard-agn"),
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/update/', views.UpdateStandardBeforeUserDel, name="standard-update-before-user-del"),
path('standard/download/<int:nc_id>', views.getFileFromStandard, name="standard-loadfile")
]

View File

@ -77,6 +77,11 @@ class StandardsManagement(LoginRequiredMixin, ListView):
return context
@login_required
def getFileFromStandard(request, nc_id):
print(nc_id)
return JsonResponse({})
@login_required
def checkUserDirRights(request, startdir, userid):
@ -389,22 +394,16 @@ def StandardAdd(request, id=False):
standard.linked_standards.add(Standards.objects.get(pk=s))
# ADD FILES
print("FILES IDS")
print(normalForm.cleaned_data['added_files'])
files = normalForm.cleaned_data['added_files'].split(",")
for f in files:
print(f)
if(f.isdigit()):
print("PRÜFUNG")
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):
print("NICHT GEFUNDEN - HINZUFÜGEN")
new_nc_file = NCFile(nc_id=f, agency=standard.agency)
new_nc_file.save()
standard.addedfiles_nc.add(new_nc_file)
else:
print("GEFUNDEN - HINZU")
standard.addedfiles_nc.add(ncfile)
# ADD QUICKLINKS