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):
|
||||
agency = models.ForeignKey(Agency, on_delete=models.CASCADE)
|
||||
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>
|
||||
</div>
|
||||
<datalist id="poss_files">
|
||||
{% for f in files %}
|
||||
<option id="files_{{f.pk}}" value="{{f.name}}">{{f.name}}</option>
|
||||
{% for f in files %}
|
||||
{% getNCFileInfos request f as filename %}
|
||||
{% if filename != "FAIL_TO_LOAD_NC_FILE_DATA" %}
|
||||
<option id="files_{{f}}" value="{{filename}}">{{filename}}</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
</div>
|
||||
Verlinkte Dateien:
|
||||
<table id="linked_files" class="table table-hover table-sm">
|
||||
<!-- TODO: JAVASCRIPT FUNKTIONEN NOCH ANPASSEN -->
|
||||
{% if update == True %}
|
||||
{% 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 %}
|
||||
<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 %}
|
||||
{% endif %}
|
||||
</table>
|
||||
|
||||
<!-- TODO: Upload ins richtige Verzeichnis-->
|
||||
<input type="file" id="uploadedfile" name="uploadedfile" style="display:none">
|
||||
{% if user|usergperm:"filesmanager" %}
|
||||
<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>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
@ -720,8 +722,9 @@
|
|||
var ua = window.navigator.userAgent;
|
||||
var isIE = /MSIE|Trident/.test(ua);
|
||||
var isSafari = /Safari/.test(ua);
|
||||
|
||||
if ( isIE || isSafari) {
|
||||
var isChrome = /Chrome/.test(ua);
|
||||
if ( isIE || (isSafari && !isChrome)) {
|
||||
|
||||
//IE specific code goes here
|
||||
setInterval(function()
|
||||
{
|
||||
|
|
@ -765,7 +768,7 @@ function checkGroupVerant(){
|
|||
$("#id_group_verant").val(act_verant_group);
|
||||
}
|
||||
|
||||
console.log($("#id_group_verant").val());
|
||||
//console.log($("#id_group_verant").val());
|
||||
}
|
||||
|
||||
function removeGroupFromVeran(id, name){
|
||||
|
|
@ -775,7 +778,7 @@ function removeGroupFromVeran(id, name){
|
|||
$("#id_group_verant").val(act_verant_group);
|
||||
$("#span_btn_verant_group_" + id).remove();
|
||||
|
||||
console.log($("#id_group_verant").val());
|
||||
//console.log($("#id_group_verant").val());
|
||||
}
|
||||
|
||||
//AUSFÜHRENDER
|
||||
|
|
@ -801,7 +804,7 @@ function checkGroupEx(){
|
|||
$("#id_group_ex").val(act_ex_group);
|
||||
}
|
||||
|
||||
console.log($("#id_group_ex").val());
|
||||
//console.log($("#id_group_ex").val());
|
||||
}
|
||||
|
||||
function removeGroupFromEx(id, name){
|
||||
|
|
@ -811,7 +814,7 @@ function removeGroupFromEx(id, name){
|
|||
$("#id_group_ex").val(act_ex_group);
|
||||
$("#span_btn_ex_group_" + id).remove();
|
||||
|
||||
console.log($("#id_group_ex").val());
|
||||
//console.log($("#id_group_ex").val());
|
||||
}
|
||||
|
||||
//VERTRETER
|
||||
|
|
@ -1008,8 +1011,8 @@ actualStandards = [];
|
|||
actualFiles = [];
|
||||
{% if update == True %}
|
||||
actualFiles = [
|
||||
{% for f in standard.addedfiles.all %}
|
||||
'{{f.pk}}',
|
||||
{% for f in standard.addedfiles_nc.all %}
|
||||
'{{f.nc_id}}',
|
||||
{% endfor %}
|
||||
];
|
||||
$("#id_added_files").val(actualFiles);
|
||||
|
|
@ -1057,8 +1060,7 @@ function clearSearchField(type){
|
|||
function updateLinkedElements(type){
|
||||
var g = $('#searchfield_' + type).val();
|
||||
var id = $('#poss_' + type).find('option[value="' + g + '"]').attr('id');
|
||||
|
||||
if(id != undefined && id.length > 0){
|
||||
if((id != undefined || id != "undefined") && id.length > 0){
|
||||
clearSearchField(type);
|
||||
tempid = id.split("_")[1];
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1120,15 +1120,18 @@ def getAbsenceLastHistory(absence):
|
|||
import urllib.parse
|
||||
@register.simple_tag
|
||||
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>'
|
||||
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(str(ncid))
|
||||
print(r.text)
|
||||
|
||||
split_response = r.text.split("<d:href>")
|
||||
split_fileele = split_response[1].split("</d:href>")
|
||||
split_filename = split_fileele[0].split("/")
|
||||
split_filenameclear = split_filename[len(split_filename)-1]
|
||||
return urllib.parse.unquote(split_filenameclear)
|
||||
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>'
|
||||
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>")
|
||||
split_filename = split_fileele[0].split("/")
|
||||
split_filenameclear = split_filename[len(split_filename)-1]
|
||||
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.models import User
|
||||
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.http import HttpResponse, JsonResponse
|
||||
from .forms import StandardAddStandard, StandardAddStandardEditor, StandardUpdateStandard, StandardUpdateStandardEditor
|
||||
|
|
@ -515,8 +515,6 @@ def StandardAdd(request, id=False):
|
|||
return redirect('/standards')
|
||||
# SHOW EXISTING STANDARD
|
||||
else:
|
||||
|
||||
|
||||
# CHECK IF USER HAS RIGHTS TO SEE THIS DIR
|
||||
groupsofstandard = standard
|
||||
|
||||
|
|
@ -531,33 +529,54 @@ def StandardAdd(request, id=False):
|
|||
userisingroup = True
|
||||
|
||||
if userisingroup:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
normalForm = StandardUpdateStandard(instance=standard)
|
||||
editorForm = StandardUpdateStandardEditor(instance=standard)
|
||||
|
||||
# TODO: Hier ändern, dass NC die Dateien anbietet!
|
||||
# GET ALL DATAS FROM STANDARD
|
||||
# FILES
|
||||
possibleFilesByVisible = []
|
||||
|
||||
allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
|
||||
#allfiles = DataFile.objects.filter(agency=request.user.profile.agency)
|
||||
# Get all files by view
|
||||
for f in allfiles:
|
||||
actParent = DataDir.objects.get(pk=f.parent.pk)
|
||||
if actParent.is_root:
|
||||
possibleFilesByVisible.append(f)
|
||||
else:
|
||||
if(checkUserDirRights(request, actParent, request.user.pk)):
|
||||
possibleFilesByVisible.append(f)
|
||||
#for f in allfiles:
|
||||
# actParent = DataDir.objects.get(pk=f.parent.pk)
|
||||
# if actParent.is_root:
|
||||
# possibleFilesByVisible.append(f)
|
||||
# else:
|
||||
# if(checkUserDirRights(request, actParent, request.user.pk)):
|
||||
# possibleFilesByVisible.append(f)
|
||||
|
||||
# Remove files which are in standard
|
||||
for f in possibleFilesByVisible:
|
||||
if f in standard.addedfiles.all():
|
||||
possibleFilesByVisible.remove(f)
|
||||
#for f in possibleFilesByVisible:
|
||||
# if f in standard.addedfiles.all():
|
||||
# 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
|
||||
possible_standards = []
|
||||
|
|
@ -825,12 +844,10 @@ def CopyStandard(request, pk):
|
|||
new_standard.save()
|
||||
|
||||
datadir_parentid = list(DataDir.objects.filter(is_defaultstandard=True, agency__pk=request.user.profile.agency.pk))[0]
|
||||
|
||||
for f in sc.addedfiles.all():
|
||||
tempdatafile = DataFile(file=f.file, name=f.name, owner=request.user, parent=datadir_parentid, agency=request.user.profile.agency)
|
||||
for f in sc.addedfiles_nc.all():
|
||||
tempdatafile = NCFile(agency=request.user.profile.agency, nc_id=f.nc_id)
|
||||
tempdatafile.save()
|
||||
new_standard.addedfiles.add(tempdatafile)
|
||||
# TASK: Hier das kopieren der Dateien auf dem Server noch einfügen
|
||||
new_standard.addedfiles_nc.add(tempdatafile)
|
||||
|
||||
# Sende Info, dass ein Standard übernommen wurde, an die Erstelleragentur
|
||||
usersofagency = User.objects.filter(profile__agency=sc.agency)
|
||||
|
|
|
|||
Loading…
Reference in New Issue