Standard NC Files added
This commit is contained in:
parent
52d4066f66
commit
f289a24d82
|
|
@ -100,4 +100,4 @@ class Standards(models.Model):
|
||||||
class NCFile(models.Model):
|
class NCFile(models.Model):
|
||||||
agency = models.ForeignKey(Agency, on_delete=models.CASCADE)
|
agency = models.ForeignKey(Agency, on_delete=models.CASCADE)
|
||||||
nc_id = models.IntegerField(default=0)
|
nc_id = models.IntegerField(default=0)
|
||||||
file_id = models.ForeignKey(DataFile, on_delete=models.CASCADE)
|
file_id = models.ForeignKey(DataFile, on_delete=models.CASCADE, null=True, blank=True, default=None)
|
||||||
|
|
|
||||||
|
|
@ -144,27 +144,29 @@
|
||||||
<button type="button" onclick="javascript:clearSearchField('files')" class="btn btn-secondary" ><i class="fas fa-times"></i></button>
|
<button type="button" onclick="javascript:clearSearchField('files')" class="btn btn-secondary" ><i class="fas fa-times"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<datalist id="poss_files">
|
<datalist id="poss_files">
|
||||||
{% for f in files %}
|
{% for f in files %}
|
||||||
<option id="files_{{f.pk}}" value="{{f.name}}">{{f.name}}</option>
|
{% getNCFileInfos request f as filename %}
|
||||||
|
{% if filename != "FAIL_TO_LOAD_NC_FILE_DATA" %}
|
||||||
|
<option id="files_{{f}}" value="{{filename}}">{{filename}}</option>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</datalist>
|
</datalist>
|
||||||
</div>
|
</div>
|
||||||
Verlinkte Dateien:
|
Verlinkte Dateien:
|
||||||
<table id="linked_files" class="table table-hover table-sm">
|
<table id="linked_files" class="table table-hover table-sm">
|
||||||
<!-- TODO: JAVASCRIPT FUNKTIONEN NOCH ANPASSEN -->
|
|
||||||
{% if update == True %}
|
{% if update == True %}
|
||||||
{% for f in standard.addedfiles_nc.all %}
|
{% for f in standard.addedfiles_nc.all %}
|
||||||
<!--<tr id="added_files_{{f.pk}}"><td>{{f.name}}</td><td><button type="button" class="btn btn-danger btn-sm" style="float: right;" onclick="javascript:remEle('files',{{f.pk}}, '{{f.name}}')"><i class="fas fa-trash"></i></button></td></tr>-->
|
|
||||||
{% getNCFileInfos request f.nc_id as filename %}
|
{% getNCFileInfos request f.nc_id as filename %}
|
||||||
<tr id="added_files_{{f.pk}}"><td>{{filename}}</td><td><button type="button" class="btn btn-danger btn-sm" style="float: right;" onclick="javascript:remEle('files',{{f.pk}}, '{{filename}}')"><i class="fas fa-trash"></i></button></td></tr>
|
<tr id="added_files_{{f.nc_id}}"><td>{{filename}}</td><td><button type="button" class="btn btn-danger btn-sm" style="float: right;" onclick="javascript:remEle('files',{{f.nc_id}}, '{{filename}}')"><i class="fas fa-trash"></i></button></td></tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<!-- TODO: Upload ins richtige Verzeichnis-->
|
||||||
<input type="file" id="uploadedfile" name="uploadedfile" style="display:none">
|
<input type="file" id="uploadedfile" name="uploadedfile" style="display:none">
|
||||||
{% if user|usergperm:"filesmanager" %}
|
{% if user|usergperm:"filesmanager" %}
|
||||||
<div class="alert alert-secondary text-center mt-5" id="directdiv" role="alert" style="line-height: 17px; text-align: center;">
|
<div class="alert alert-secondary text-center mt-5" id="directdiv" role="alert" style="line-height: 17px; text-align: center;">
|
||||||
<button type="button" class="btn btn-primary btn-sm" id="uploadButton" onclick="javascript:uploadButtonPush()"><i class="fas fa-plus"></i></button> <small>klicken/hineinziehen<p class="mt-2">Dateien werden im <b>Uploadordner für Standards</b> gespeichert.
|
<button type="button" class="btn btn-primary btn-sm" id="uploadButton" onclick="javascript:uploadButtonPush()"><i class="fas fa-plus"></i></button> <small>klicken/hineinziehen<p class="mt-2">Dateien werden im Verzeichnis <b>Agenturdaten/Standards Uploadbereich </b> gespeichert.
|
||||||
</small></p>
|
</small></p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
@ -720,8 +722,9 @@
|
||||||
var ua = window.navigator.userAgent;
|
var ua = window.navigator.userAgent;
|
||||||
var isIE = /MSIE|Trident/.test(ua);
|
var isIE = /MSIE|Trident/.test(ua);
|
||||||
var isSafari = /Safari/.test(ua);
|
var isSafari = /Safari/.test(ua);
|
||||||
|
var isChrome = /Chrome/.test(ua);
|
||||||
if ( isIE || isSafari) {
|
if ( isIE || (isSafari && !isChrome)) {
|
||||||
|
|
||||||
//IE specific code goes here
|
//IE specific code goes here
|
||||||
setInterval(function()
|
setInterval(function()
|
||||||
{
|
{
|
||||||
|
|
@ -765,7 +768,7 @@ function checkGroupVerant(){
|
||||||
$("#id_group_verant").val(act_verant_group);
|
$("#id_group_verant").val(act_verant_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log($("#id_group_verant").val());
|
//console.log($("#id_group_verant").val());
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeGroupFromVeran(id, name){
|
function removeGroupFromVeran(id, name){
|
||||||
|
|
@ -775,7 +778,7 @@ function removeGroupFromVeran(id, name){
|
||||||
$("#id_group_verant").val(act_verant_group);
|
$("#id_group_verant").val(act_verant_group);
|
||||||
$("#span_btn_verant_group_" + id).remove();
|
$("#span_btn_verant_group_" + id).remove();
|
||||||
|
|
||||||
console.log($("#id_group_verant").val());
|
//console.log($("#id_group_verant").val());
|
||||||
}
|
}
|
||||||
|
|
||||||
//AUSFÜHRENDER
|
//AUSFÜHRENDER
|
||||||
|
|
@ -801,7 +804,7 @@ function checkGroupEx(){
|
||||||
$("#id_group_ex").val(act_ex_group);
|
$("#id_group_ex").val(act_ex_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log($("#id_group_ex").val());
|
//console.log($("#id_group_ex").val());
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeGroupFromEx(id, name){
|
function removeGroupFromEx(id, name){
|
||||||
|
|
@ -811,7 +814,7 @@ function removeGroupFromEx(id, name){
|
||||||
$("#id_group_ex").val(act_ex_group);
|
$("#id_group_ex").val(act_ex_group);
|
||||||
$("#span_btn_ex_group_" + id).remove();
|
$("#span_btn_ex_group_" + id).remove();
|
||||||
|
|
||||||
console.log($("#id_group_ex").val());
|
//console.log($("#id_group_ex").val());
|
||||||
}
|
}
|
||||||
|
|
||||||
//VERTRETER
|
//VERTRETER
|
||||||
|
|
@ -1008,8 +1011,8 @@ actualStandards = [];
|
||||||
actualFiles = [];
|
actualFiles = [];
|
||||||
{% if update == True %}
|
{% if update == True %}
|
||||||
actualFiles = [
|
actualFiles = [
|
||||||
{% for f in standard.addedfiles.all %}
|
{% for f in standard.addedfiles_nc.all %}
|
||||||
'{{f.pk}}',
|
'{{f.nc_id}}',
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
];
|
];
|
||||||
$("#id_added_files").val(actualFiles);
|
$("#id_added_files").val(actualFiles);
|
||||||
|
|
@ -1057,8 +1060,7 @@ function clearSearchField(type){
|
||||||
function updateLinkedElements(type){
|
function updateLinkedElements(type){
|
||||||
var g = $('#searchfield_' + type).val();
|
var g = $('#searchfield_' + type).val();
|
||||||
var id = $('#poss_' + type).find('option[value="' + g + '"]').attr('id');
|
var id = $('#poss_' + type).find('option[value="' + g + '"]').attr('id');
|
||||||
|
if((id != undefined || id != "undefined") && id.length > 0){
|
||||||
if(id != undefined && id.length > 0){
|
|
||||||
clearSearchField(type);
|
clearSearchField(type);
|
||||||
tempid = id.split("_")[1];
|
tempid = id.split("_")[1];
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1120,15 +1120,18 @@ def getAbsenceLastHistory(absence):
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def getNCFileInfos(request, ncid):
|
def getNCFileInfos(request, 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>'
|
try:
|
||||||
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(ncid)
|
||||||
print(str(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>'
|
||||||
print(r.text)
|
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_response = r.text.split("<d:href>")
|
||||||
split_fileele = split_response[1].split("</d:href>")
|
split_fileele = split_response[1].split("</d:href>")
|
||||||
split_filename = split_fileele[0].split("/")
|
split_filename = split_fileele[0].split("/")
|
||||||
split_filenameclear = split_filename[len(split_filename)-1]
|
split_filenameclear = split_filename[len(split_filename)-1]
|
||||||
return urllib.parse.unquote(split_filenameclear)
|
return urllib.parse.unquote(split_filenameclear)
|
||||||
|
except:
|
||||||
|
return "FAIL_TO_LOAD_NC_FILE_DATA"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from django.shortcuts import render, redirect
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.views.generic import CreateView, ListView, UpdateView, DetailView, DeleteView, View
|
from django.views.generic import CreateView, ListView, UpdateView, DetailView, DeleteView, View
|
||||||
from .models import Standards, StandardComments, StandardCommentRate
|
from .models import NCFile, Standards, StandardComments, StandardCommentRate
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.http import HttpResponse, JsonResponse
|
from django.http import HttpResponse, JsonResponse
|
||||||
from .forms import StandardAddStandard, StandardAddStandardEditor, StandardUpdateStandard, StandardUpdateStandardEditor
|
from .forms import StandardAddStandard, StandardAddStandardEditor, StandardUpdateStandard, StandardUpdateStandardEditor
|
||||||
|
|
@ -515,8 +515,6 @@ def StandardAdd(request, id=False):
|
||||||
return redirect('/standards')
|
return redirect('/standards')
|
||||||
# SHOW EXISTING STANDARD
|
# SHOW EXISTING STANDARD
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
|
||||||
# CHECK IF USER HAS RIGHTS TO SEE THIS DIR
|
# CHECK IF USER HAS RIGHTS TO SEE THIS DIR
|
||||||
groupsofstandard = standard
|
groupsofstandard = standard
|
||||||
|
|
||||||
|
|
@ -531,33 +529,54 @@ def StandardAdd(request, id=False):
|
||||||
userisingroup = True
|
userisingroup = True
|
||||||
|
|
||||||
if userisingroup:
|
if userisingroup:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
normalForm = StandardUpdateStandard(instance=standard)
|
normalForm = StandardUpdateStandard(instance=standard)
|
||||||
editorForm = StandardUpdateStandardEditor(instance=standard)
|
editorForm = StandardUpdateStandardEditor(instance=standard)
|
||||||
|
|
||||||
|
# TODO: Hier ändern, dass NC die Dateien anbietet!
|
||||||
# GET ALL DATAS FROM STANDARD
|
# GET ALL DATAS FROM STANDARD
|
||||||
# FILES
|
# FILES
|
||||||
possibleFilesByVisible = []
|
possibleFilesByVisible = []
|
||||||
|
|
||||||
allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
|
#allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
|
||||||
# Get all files by view
|
# Get all files by view
|
||||||
for f in allfiles:
|
#for f in allfiles:
|
||||||
actParent = DataDir.objects.get(pk=f.parent.pk)
|
# actParent = DataDir.objects.get(pk=f.parent.pk)
|
||||||
if actParent.is_root:
|
# if actParent.is_root:
|
||||||
possibleFilesByVisible.append(f)
|
# possibleFilesByVisible.append(f)
|
||||||
else:
|
# else:
|
||||||
if(checkUserDirRights(request, actParent, request.user.pk)):
|
# if(checkUserDirRights(request, actParent, request.user.pk)):
|
||||||
possibleFilesByVisible.append(f)
|
# possibleFilesByVisible.append(f)
|
||||||
|
|
||||||
# Remove files which are in standard
|
# Remove files which are in standard
|
||||||
for f in possibleFilesByVisible:
|
#for f in possibleFilesByVisible:
|
||||||
if f in standard.addedfiles.all():
|
# if f in standard.addedfiles.all():
|
||||||
possibleFilesByVisible.remove(f)
|
# possibleFilesByVisible.remove(f)
|
||||||
|
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><oc:fileid/></d:prop></d:select><d:from><d:scope><d:href>/files/' + request.user.username + '/Agenturdaten/</d:href><d:depth>infinity</d:depth></d:scope></d:from><d:where><d:gt><d:prop><oc:size/></d:prop><d:literal>1</d:literal></d:gt></d:where></d:basicsearch></d:searchrequest>'
|
||||||
|
#filesearchdata = '<?xml version="1.0" encoding="UTF-8"?><d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"><d:prop><oc:fileid /></d:prop><d:depth>infinity</d:depth></d:propfind>'
|
||||||
|
r = requests.request("SEARCH", settings.NEXTCLOUD_URL + "remote.php/dav/", data=filesearchdata, headers={'Content-Type' : 'text/xml', 'Authorization' : "Bearer " + request.user.profile.nc_sid})
|
||||||
|
# IDs filtern aus XML-Response
|
||||||
|
try:
|
||||||
|
split_response = r.text.split("<oc:fileid>")
|
||||||
|
|
||||||
|
# Header des XML-Response entfernen
|
||||||
|
split_response.pop(0)
|
||||||
|
|
||||||
|
# IDs from the User
|
||||||
|
for ele in split_response:
|
||||||
|
new_id = ele.split("</oc:fileid>")[0]
|
||||||
|
|
||||||
|
file_free = True
|
||||||
|
# Prüfen, dass diese IDs nicht im aktuellen Standard sind
|
||||||
|
for sf in standard.addedfiles_nc.all():
|
||||||
|
if str(sf.nc_id) == str(new_id):
|
||||||
|
file_free = False
|
||||||
|
|
||||||
|
if file_free == True:
|
||||||
|
possibleFilesByVisible.append(new_id)
|
||||||
|
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# STANDARDS
|
# STANDARDS
|
||||||
possible_standards = []
|
possible_standards = []
|
||||||
|
|
@ -825,12 +844,10 @@ def CopyStandard(request, pk):
|
||||||
new_standard.save()
|
new_standard.save()
|
||||||
|
|
||||||
datadir_parentid = list(DataDir.objects.filter(is_defaultstandard=True, agency__pk=request.user.profile.agency.pk))[0]
|
datadir_parentid = list(DataDir.objects.filter(is_defaultstandard=True, agency__pk=request.user.profile.agency.pk))[0]
|
||||||
|
for f in sc.addedfiles_nc.all():
|
||||||
for f in sc.addedfiles.all():
|
tempdatafile = NCFile(agency=request.user.profile.agency, nc_id=f.nc_id)
|
||||||
tempdatafile = DataFile(file=f.file, name=f.name, owner=request.user, parent=datadir_parentid, agency=request.user.profile.agency)
|
|
||||||
tempdatafile.save()
|
tempdatafile.save()
|
||||||
new_standard.addedfiles.add(tempdatafile)
|
new_standard.addedfiles_nc.add(tempdatafile)
|
||||||
# TASK: Hier das kopieren der Dateien auf dem Server noch einfügen
|
|
||||||
|
|
||||||
# Sende Info, dass ein Standard übernommen wurde, an die Erstelleragentur
|
# Sende Info, dass ein Standard übernommen wurde, an die Erstelleragentur
|
||||||
usersofagency = User.objects.filter(profile__agency=sc.agency)
|
usersofagency = User.objects.filter(profile__agency=sc.agency)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue