Fehler abfangen
This commit is contained in:
parent
b5c9d05de3
commit
b0525d99d3
Binary file not shown.
|
|
@ -1181,40 +1181,46 @@ def getNCDirInfosURL(request, ncid):
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def getAGGroupQuotaData(request):
|
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})
|
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})
|
||||||
|
try:
|
||||||
# IN USE
|
# IN USE
|
||||||
split_response = r.text.split("<d:quota-used-bytes>")
|
split_response = r.text.split("<d:quota-used-bytes>")
|
||||||
inuse = split_response[1].split("</d:quota-used-bytes>")[0]
|
inuse = split_response[1].split("</d:quota-used-bytes>")[0]
|
||||||
|
|
||||||
# QUOTA
|
# QUOTA
|
||||||
split_response = r.text.split("<d:quota-available-bytes>")
|
split_response = r.text.split("<d:quota-available-bytes>")
|
||||||
quota = split_response[1].split("</d:quota-available-bytes>")[0]
|
quota = split_response[1].split("</d:quota-available-bytes>")[0]
|
||||||
|
|
||||||
# PERCENT VALUE
|
# PERCENT VALUE
|
||||||
percent = (100 / int(quota))*int(inuse)
|
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
|
# User QUOTA
|
||||||
import re, math
|
import re, math
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def getUserQuotaData(userdata):
|
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"})
|
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('<quota>(.+?)</quota>', r.text)]
|
||||||
|
inuse = [int(s) for s in re.findall('<used>(.+?)</used>', 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('<quota>(.+?)</quota>', r.text)]
|
# PERCENT
|
||||||
inuse = [int(s) for s in re.findall('<used>(.+?)</used>', r.text)]
|
percent = (100 / int(quotadata[0]))*int(inuse[0])
|
||||||
|
|
||||||
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
|
return [quotadata[0], inuse[0], str(round(percent, 0)).replace(",", "."), str(valuequota_MB).split(".")[0]]
|
||||||
percent = (100 / int(quotadata[0]))*int(inuse[0])
|
except:
|
||||||
|
return [0, 0, 0, 0]
|
||||||
return [quotadata[0], inuse[0], str(round(percent, 0)).replace(",", "."), str(valuequota_MB).split(".")[0]]
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue