From b0525d99d35ad44fa167884bcaff3f850baf6d8c Mon Sep 17 00:00:00 2001 From: Holger Trampe Date: Fri, 22 Oct 2021 22:19:48 +0200 Subject: [PATCH] Fehler abfangen --- .../__pycache__/counter_tag.cpython-38.pyc | Bin 28692 -> 28766 bytes standards/templatetags/counter_tag.py | 58 ++++++++++-------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/standards/templatetags/__pycache__/counter_tag.cpython-38.pyc b/standards/templatetags/__pycache__/counter_tag.cpython-38.pyc index d6343e1d996871978f4bb0644f26b8cbe6b6441a..52cfaf308d87e045c53816e4fd1ec405562f9c07 100644 GIT binary patch delta 230 zcmbR8fbre~M&3|fUM>b8xGz(jICCR!YbxWO$&*t}nX2+8pGeJ;31XxtS$Pfsua;3j;&39N2yxMkdC|hS?%4Wb8ILKX`Xtj~IHI;GRxPgU%p;!WJt`3s~qXZKNBMT4;Fmf<*F>x`=Fm3M7KE=W+ IC;$`$0Bo@;6951J diff --git a/standards/templatetags/counter_tag.py b/standards/templatetags/counter_tag.py index 1500a18..d704275 100644 --- a/standards/templatetags/counter_tag.py +++ b/standards/templatetags/counter_tag.py @@ -1181,40 +1181,46 @@ def getNCDirInfosURL(request, ncid): @register.simple_tag def getAGGroupQuotaData(request): r = requests.request("PROPFIND", settings.NEXTCLOUD_URL + "remote.php/dav/files/" + request.user.username + "/Agenturdaten", headers={'Content-Type' : 'text/xml', 'Authorization' : "Bearer " + request.user.profile.nc_sid}) - - # IN USE - split_response = r.text.split("") - inuse = split_response[1].split("")[0] - - # QUOTA - split_response = r.text.split("") - quota = split_response[1].split("")[0] + try: + # IN USE + split_response = r.text.split("") + inuse = split_response[1].split("")[0] + + # QUOTA + split_response = r.text.split("") + quota = split_response[1].split("")[0] - # PERCENT VALUE - percent = (100 / int(quota))*int(inuse) + # PERCENT VALUE + percent = (100 / int(quota))*int(inuse) + return [quota, inuse, str(round(percent, 0)).replace(",", ".")] + except: + return [0, 0, 0] - return [quota, inuse, str(round(percent, 0)).replace(",", ".")] + + # User QUOTA import re, math @register.simple_tag def getUserQuotaData(userdata): r = requests.request("GET", settings.NEXTCLOUD_URL + "/ocs/v1.php/cloud/users/" + userdata.username, auth=(settings.NEXTCLOUD_USER_API, settings.NEXTCLOUD_PW_API), headers={'Content-Type' : 'text/xml', 'OCS-APIRequest': "true"}) + try: + quotadata = [int(s) for s in re.findall('(.+?)', r.text)] + inuse = [int(s) for s in re.findall('(.+?)', r.text)] + + quotadata_value = quotadata[0] + valuequota_MB = 0 + counter = 0 + while(quotadata_value > 9999 or counter > 3): + quotadata_value = quotadata_value / 1024 + counter += 1 + + valuequota_MB = round(quotadata_value, 0) - quotadata = [int(s) for s in re.findall('(.+?)', r.text)] - inuse = [int(s) for s in re.findall('(.+?)', r.text)] - - quotadata_value = quotadata[0] - valuequota_MB = 0 - counter = 0 - while(quotadata_value > 9999 or counter > 3): - quotadata_value = quotadata_value / 1024 - counter += 1 - - valuequota_MB = round(quotadata_value, 0) + # PERCENT + percent = (100 / int(quotadata[0]))*int(inuse[0]) - # PERCENT - percent = (100 / int(quotadata[0]))*int(inuse[0]) - - return [quotadata[0], inuse[0], str(round(percent, 0)).replace(",", "."), str(valuequota_MB).split(".")[0]] + return [quotadata[0], inuse[0], str(round(percent, 0)).replace(",", "."), str(valuequota_MB).split(".")[0]] + except: + return [0, 0, 0, 0]