Standrad Update Files add and remove

This commit is contained in:
Holger Trampe 2021-09-01 11:04:43 +02:00
parent f289a24d82
commit 12d4de29d3
5 changed files with 22 additions and 8 deletions

View File

@ -1105,6 +1105,7 @@ function remEle(type, id, name){
index_to_rem = actualFiles.indexOf(id); index_to_rem = actualFiles.indexOf(id);
actualFiles.splice(index_to_rem,1); actualFiles.splice(index_to_rem,1);
$("#id_added_" + type).val(actualFiles); $("#id_added_" + type).val(actualFiles);
} }
else if(type == 'quicklinks'){ else if(type == 'quicklinks'){
index_to_rem = actualQuicklinks.indexOf(id); index_to_rem = actualQuicklinks.indexOf(id);

View File

@ -27,7 +27,7 @@
<hr> <hr>
<div class="row col"> <div class="row col">
{% if standard.addedfiles.all|length > 0 or standard.linked_standards.all|length > 0 or standard.authority.count > 0 or standard.executor.count > 0 or standard.representative.count > 0 or standard.addedfiles.all|length > 0 or standard.linked_standards.all|length > 0 or standard.freefield_title|length > 0 or standard.addedcontacts.all|length > 0 or standard.addedpasswords.all|length > 0 or standard.addedquicklinks.all|length > 0 or standard.authority_group.count > 0 or standard.executor_group.count > 0 or standard.representative_group.count > 0 %} {% if standard.addedfiles_nc.all|length > 0 or standard.linked_standards.all|length > 0 or standard.authority.count > 0 or standard.executor.count > 0 or standard.representative.count > 0 or standard.addedfiles_nc.all|length > 0 or standard.linked_standards.all|length > 0 or standard.freefield_title|length > 0 or standard.addedcontacts.all|length > 0 or standard.addedpasswords.all|length > 0 or standard.addedquicklinks.all|length > 0 or standard.authority_group.count > 0 or standard.executor_group.count > 0 or standard.representative_group.count > 0 %}
<div class="card col-9" style="min-height: 500px"> <div class="card col-9" style="min-height: 500px">
{% else %} {% else %}
<div class="card col-12" style="min-height: 500px"> <div class="card col-12" style="min-height: 500px">
@ -42,7 +42,7 @@
</div> </div>
<!-- PERSONEN --> <!-- PERSONEN -->
{% if standard.addedfiles.all|length > 0 or standard.linked_standards.all|length > 0 or standard.authority.count > 0 or standard.executor.count > 0 or standard.representative.count > 0 or standard.addedfiles.all|length > 0 or standard.linked_standards.all|length > 0 or standard.freefield_title|length > 0 or standard.addedcontacts.all|length > 0 or standard.addedpasswords.all|length > 0 or standard.addedquicklinks.all|length > 0 or standard.authority_group.count > 0 or standard.executor_group.count > 0 or standard.representative_group.count > 0 %} {% if standard.addedfiles_nc.all|length > 0 or standard.linked_standards.all|length > 0 or standard.authority.count > 0 or standard.executor.count > 0 or standard.representative.count > 0 or standard.addedfiles_nc.all|length > 0 or standard.linked_standards.all|length > 0 or standard.freefield_title|length > 0 or standard.addedcontacts.all|length > 0 or standard.addedpasswords.all|length > 0 or standard.addedquicklinks.all|length > 0 or standard.authority_group.count > 0 or standard.executor_group.count > 0 or standard.representative_group.count > 0 %}
<div class="col-3"> <div class="col-3">
@ -131,13 +131,14 @@
<!-- FILES --> <!-- FILES -->
{% if standard.addedfiles.all|length > 0 %} {% if standard.addedfiles_nc.all|length > 0 %}
<div class="card col-14 ml-1 mb-2" style="min-width: 110%"> <div class="card col-14 ml-1 mb-2" style="min-width: 110%">
<div class="card-body"> <div class="card-body">
<h5 class="card-title">Dateien</h5> <h5 class="card-title">Dateien</h5>
<p class="card-text"> <p class="card-text">
{% for files in standard.addedfiles.all %} {% for files in standard.addedfiles_nc.all %}
<a href="{% url 'cloud-td' files.pk %}" target="_blank">{{files.name|truncatechars:30}}</a><br /> <!--<a href="{% url 'cloud-td' files.pk %}" target="_blank">{{files.name|truncatechars:30}}</a><br />-->
TODO: HIER DOWNLOAD ERMÖGLICH: {{files.nc_id}}
{% endfor %} {% endfor %}
</p> </p>
</div> </div>

View File

@ -1121,7 +1121,6 @@ import urllib.parse
@register.simple_tag @register.simple_tag
def getNCFileInfos(request, ncid): def getNCFileInfos(request, ncid):
try: try:
print(ncid)
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>' 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}) r = requests.request("SEARCH", settings.NEXTCLOUD_URL + "remote.php/dav/", data=filesearchdata, headers={'Content-Type' : 'text/xml', 'Authorization' : "Bearer " + request.user.profile.nc_sid})

View File

@ -333,7 +333,7 @@ def StandardAdd(request, id=False):
standard.visibleby.clear() standard.visibleby.clear()
standard.linked_standards.clear() standard.linked_standards.clear()
standard.addedfiles.clear() standard.addedfiles_nc.clear()
standard.addedquicklinks.clear() standard.addedquicklinks.clear()
standard.addedpasswords.clear() standard.addedpasswords.clear()
standard.addedcontacts.clear() standard.addedcontacts.clear()
@ -389,10 +389,23 @@ def StandardAdd(request, id=False):
standard.linked_standards.add(Standards.objects.get(pk=s)) standard.linked_standards.add(Standards.objects.get(pk=s))
# ADD FILES # ADD FILES
print("FILES IDS")
print(normalForm.cleaned_data['added_files'])
files = normalForm.cleaned_data['added_files'].split(",") files = normalForm.cleaned_data['added_files'].split(",")
for f in files: for f in files:
print(f)
if(f.isdigit()): if(f.isdigit()):
standard.addedfiles.add(DataFile.objects.get(pk=f)) 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 # ADD QUICKLINKS
quicklinks = normalForm.cleaned_data['added_quicklinks'].split(",") quicklinks = normalForm.cleaned_data['added_quicklinks'].split(",")