Link Standard

This commit is contained in:
Holger Trampe 2021-10-12 09:40:09 +02:00
parent bfda7ec12f
commit 8511b59d2a
3 changed files with 34 additions and 3 deletions

View File

@ -139,8 +139,12 @@
{% for file in standard.addedfiles_nc.all %}
{% getNCFileInfos request file.nc_id as filename %}
{% getNCFileInfosURL request file.nc_id as filelink %}
{% getNCDirInfosURL request file.nc_id as dirlink %}
{% getNextcloudURL as nc_url %}
<a href="{{nc_url}}{{filelink}}" target="_blank">{{filename|truncatechars:30}}</a><br />
{{dirlink}}
<!--<a href="{{nc_url}}{{filelink}}" target="_blank">{{filename|truncatechars:30}}</a>-->
<a href="{{nc_url}}apps/files/?dir={{dirlink}}&openfile={{file.nc_id}}" target="_blank">{{filename|truncatechars:30}}</a>
<br />
{% endfor %}
</p>
</div>

View File

@ -1149,4 +1149,31 @@ def getNCFileInfosURL(request, ncid):
except:
return ""
@register.simple_tag
def getNCDirInfosURL(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})
split_response = r.text.split("<d:href>")
split_fileele = split_response[1].split("</d:href>")
# Generating Dir-Link
finaldirlink = ""
counter = 0
dirpre = split_fileele[0].split("/")
dirpre.pop(0)
dirpre.pop(0)
dirpre.pop(0)
dirpre.pop(0)
dirpre.pop(0)
for ele in dirpre:
if counter < len(dirpre) - 1:
finaldirlink += ele + "/"
counter += 1
# Return file-link except first slash in string
return finaldirlink[:-1]
#return urllib.parse.unquote(split_filenameclear)
except:
return ""