Dateisystem einmal umgeschrieben und auf Objekte umgestellt, dragndrop angefangen
This commit is contained in:
parent
c4570154ff
commit
670b2bce6c
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from users.models import Agency
|
from users.models import Agency, AgencyGroup
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
@ -20,5 +20,35 @@ class Data(models.Model):
|
||||||
agency = models.ForeignKey(Agency, on_delete=models.CASCADE, default=None)
|
agency = models.ForeignKey(Agency, on_delete=models.CASCADE, default=None)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
print(self.file.name)
|
|
||||||
return str(self.file.name)
|
return str(self.file.name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class DataDir(models.Model):
|
||||||
|
name = models.CharField(max_length=2000, default="", blank=True, null=True)
|
||||||
|
is_root = models.BooleanField(default=False)
|
||||||
|
dirs = models.ManyToManyField('self', blank=True, related_name='dirs_in_dirs', symmetrical = False)
|
||||||
|
datafiles = models.ManyToManyField('DataFile', blank=True, related_name='files_in_dir')
|
||||||
|
visibleby = models.ManyToManyField(AgencyGroup, blank=True, related_name='visible_by_user')
|
||||||
|
date_created = models.DateTimeField(default = timezone.now)
|
||||||
|
date_last_modified = models.DateTimeField(default = timezone.now)
|
||||||
|
owner = models.ForeignKey(User, on_delete=models.PROTECT, blank=True, null=True)
|
||||||
|
agency = models.ForeignKey(Agency, on_delete=models.CASCADE)
|
||||||
|
parent = models.ForeignKey('DataDir', on_delete=models.CASCADE, blank=True, null=True, related_name='dir_in_dir')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.name)
|
||||||
|
|
||||||
|
|
||||||
|
class DataFile(models.Model):
|
||||||
|
name = models.CharField(max_length=2000, default="", blank=True, null=True)
|
||||||
|
file = models.FileField(null=True, max_length=255, upload_to=user_directory_path)
|
||||||
|
date_created = models.DateTimeField(default = timezone.now)
|
||||||
|
date_last_modified = models.DateTimeField(default = timezone.now)
|
||||||
|
owner = models.ForeignKey(User, on_delete=models.PROTECT)
|
||||||
|
agency = models.ForeignKey(Agency, on_delete=models.CASCADE, default=None)
|
||||||
|
parent = models.ForeignKey(DataDir, on_delete=models.PROTECT, related_name='thisfileindir')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.name)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
{% load crispy_forms_tags %}
|
{% load crispy_forms_tags %}
|
||||||
{% load counter_tag %}
|
{% load counter_tag %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
||||||
<style>
|
<style>
|
||||||
.icon-hover:hover{
|
.icon-hover:hover{
|
||||||
color: gray;
|
color: gray;
|
||||||
|
|
@ -10,38 +11,22 @@
|
||||||
<div class="content-section col-12">
|
<div class="content-section col-12">
|
||||||
<h3>Dateien <small><i data-toggle="tooltip" data-placement="top" title="Hier können Sie Dateien und Ordner für ihre Agentur verwalten." class="far fa-question-circle"></i></small></h3>
|
<h3>Dateien <small><i data-toggle="tooltip" data-placement="top" title="Hier können Sie Dateien und Ordner für ihre Agentur verwalten." class="far fa-question-circle"></i></small></h3>
|
||||||
<hr>
|
<hr>
|
||||||
{% if user|usergperm:"filesmanager" %}
|
</div>
|
||||||
<form method="POST" id="fileuploadform" enctype="multipart/form-data" class="col-6">
|
|
||||||
{% csrf_token %}
|
<nav aria-label="breadcrumb">
|
||||||
<input type="hidden" name="subdirinfo" value="{{level}}">
|
|
||||||
{{form.media}}
|
|
||||||
{{form|crispy}}
|
|
||||||
<div class="mt-2">
|
|
||||||
<button class="btn btn-primary" type="submit">Hochladen</button>
|
|
||||||
<small>Dateien werden immer in das aktuelle Verzeichnis hochgeladen.</small>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
|
||||||
<div class="mt-4">
|
|
||||||
<nav aria-label="breadcrumb">
|
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li class="breadcrumb-item" aria-current="page"><a href="{% url 'cloud-main' level='home' %}"><i class="fas fa-home"></i></a></li>
|
<li class="breadcrumb-item" aria-current="page"><a href="{% url 'cloud-main' 'first' %}"><i class="fas fa-home"></i></a></li>
|
||||||
{% for cr in crumplevel %}
|
{% for cr in breadcrump %}
|
||||||
{% if cr != 'home' %}
|
|
||||||
{{forloop.counter1|add:1}}
|
|
||||||
{% if forloop.last %}
|
{% if forloop.last %}
|
||||||
<li class="breadcrumb-item" active>{{cr}}</li>
|
<li class="breadcrumb-item" active>{{cr}}</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="breadcrumb-item"><a href="{% url 'cloud-main' cr %}">{{cr}}</a></li>
|
<li class="breadcrumb-item"><a href="{% url 'cloud-main' cr.pk %}">{{cr.name}}</a></li>
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if user|usergperm:"filedirmanager" and user|usergperm:"filesviewer" %}
|
|
||||||
<li class="breadcrumb-item" active><i onclick="javascript:addDirModal()" class="fas fa-folder-plus icon-hover"></i></li>
|
<li class="breadcrumb-item" active><i onclick="javascript:addDirModal()" class="fas fa-folder-plus icon-hover"></i></li>
|
||||||
{% endif %}
|
|
||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
||||||
<table class="table table-hover">
|
<table class="table table-hover" id="dirfilestable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
|
|
@ -52,39 +37,23 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for dir in dirs %}
|
{% for d in dirs %}
|
||||||
<tr>
|
<tr id="dir_{{d.pk}}" class="droppable_tr">
|
||||||
<td><i class="fas fa-folder"></i></td>
|
<td id="dir_{{d.pk}}_icon"><i class="fas fa-folder" ></i></td>
|
||||||
<td><a href="{% url 'cloud-main' dir %}">{{dir|splitdirstyle}}</a></td>
|
<td><a href="{% url 'cloud-main' d.pk %}">{{d.name}}</a></td>
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
<td>
|
|
||||||
{% if user|usergperm:"filedirmanager" and user|usergperm:"filesviewer" %}
|
|
||||||
<button type="button" class="btn btn-danger btn-sm" onclick="javascript:tryDelDir('{{dir|splitdirstyle}}')" data-toggle="tooltip" data-placement="top" title="Ordner löschen"><i class="fas fa-trash-alt"></i></button>
|
|
||||||
<button type="button" class="btn btn-primary btn-sm" onclick="javascript:changeDirName('{{dir|splitdirstyle}}')" data-toggle="tooltip" data-placement="top" title="Ordnernnamen andern"><small><i class="fas fa-pen"></i></small></button>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for ele in files %}
|
{% for file in dir.DataFiles %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><i class="fas fa-file"></i></td>
|
|
||||||
<td><a href="{{ele.file.url}}" download>{{ele.file|filename}}</a></td>
|
|
||||||
<td>{{ele.owner.first_name}} {{ele.owner.last_name}}</td>
|
|
||||||
<td>{{ele.date_created}}</td>
|
|
||||||
<td>
|
<td>
|
||||||
{% if user|usergperm:"filesmanager" and user|usergperm:"filesviewer" %}
|
<i class="fas fa-file" ></i>{{file}}
|
||||||
<button type="button" class="btn btn-danger btn-sm" onclick="javascript:tryDelFile({{ele.pk}})" data-toggle="tooltip" data-placement="top" title="Datei löschen"><i class="fas fa-trash-alt"></i></button>
|
|
||||||
<button type="button" class="btn btn-primary btn-sm" onclick="javascript:changeFileName({{ele.pk}})" data-toggle="tooltip" data-placement="top" title="Dateinamen andern"><small><i class="fas fa-pen"></i></small></button>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div class="alert alert-secondary droppable_div text-center" id="{{parentid}}_div" role="alert" style="min-height: 80px; line-height: 50px; text-align: center;">
|
||||||
</p>
|
<i class="fas fa-plus"></i> Dateien ins aktuelle Verzeichnis hier hineinziehen.
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- MODEAL ADD DIR -->
|
<!-- MODEAL ADD DIR -->
|
||||||
|
|
@ -92,7 +61,7 @@
|
||||||
<div class="modal-dialog " role="document">
|
<div class="modal-dialog " role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title" id="mainmodalArea_title">Ordner in {{crumplevel|last}} erstellen</h5>
|
<h5 class="modal-title" id="mainmodalArea_title">Ordner in TODO erstellen</h5>
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Schließen">
|
<button type="button" class="close" data-dismiss="modal" aria-label="Schließen">
|
||||||
<span aria-hidden="true">×</span>
|
<span aria-hidden="true">×</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -110,26 +79,77 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function tryDelFile(dataid){
|
//DROPPABLE
|
||||||
console.log("FILE " + dataid);
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeFileName(dataid){
|
// preventing page from redirecting
|
||||||
console.log("FILE " + dataid);
|
$("html").on("dragover", function(e) {
|
||||||
}
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
});
|
||||||
|
|
||||||
function tryDelDir(dataid){
|
$("html").on("drop", function(e) { e.preventDefault(); e.stopPropagation(); });
|
||||||
console.log("DIR " + dataid);
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeDirName(dataid){
|
|
||||||
console.log("DIR " + dataid);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$( ".droppable_tr" ).on('dragenter', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
currentid = e["currentTarget"]['id'];
|
||||||
|
$("#" + currentid + "_icon").html("");
|
||||||
|
$("#" + currentid + "_icon").html('<i class="fas fa-folder-open"></i>');
|
||||||
|
$("#" + currentid).addClass('table-secondary');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('.droppable_tr').on('drop', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
console.log("UPLOAD TO: DIR" + e["currentTarget"]['id']);
|
||||||
|
var file = e.originalEvent.dataTransfer.files;
|
||||||
|
$("#" + currentid).removeClass('table-secondary');
|
||||||
|
$("#" + currentid + "_icon").html("");
|
||||||
|
$("#" + currentid + "_icon").html('<i class="fas fa-folder"></i>');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.droppable_tr').on('dragleave', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
currentid = e["currentTarget"]['id'];
|
||||||
|
$("#" + currentid + "_icon").html("");
|
||||||
|
$("#" + currentid + "_icon").html('<i class="fas fa-folder"></i>');
|
||||||
|
$("#" + currentid).removeClass('table-secondary');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$( ".droppable_div" ).on('dragenter', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
currentid = e["currentTarget"]['id'];
|
||||||
|
$("#{{parentid}}_div").addClass('bg-secondary');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('.droppable_div').on('drop', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
$("#{{parentid}}_div").removeClass('bg-secondary');
|
||||||
|
console.log("UPLOAD TO: DIR " + {{parentid}});
|
||||||
|
var file = e.originalEvent.dataTransfer.files;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.droppable_div').on('dragleave', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
currentid = e["currentTarget"]['id'];
|
||||||
|
$("#{{parentid}}_div").removeClass('bg-secondary');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// DIR FUNCTIONS
|
||||||
function addDirModal(){
|
function addDirModal(){
|
||||||
|
|
||||||
$("#addDir").modal("toggle");
|
$("#addDir").modal("toggle");
|
||||||
$("#newdirname").val("");
|
$("#newdirname").val("");
|
||||||
|
|
||||||
|
|
@ -143,14 +163,14 @@ function validateDirName(newdirname){
|
||||||
$("#doActionTaskModal").attr("disabled", true);
|
$("#doActionTaskModal").attr("disabled", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDirAction(){
|
function addDirAction(){
|
||||||
$.ajax(
|
$.ajax(
|
||||||
{
|
{
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: "/cloud/clajax",
|
url: "{% url 'cloud-adddir' %}",
|
||||||
data:{
|
data:{
|
||||||
adddirname : "{{level}}",
|
action : "adddir",
|
||||||
|
parent : {{parentid}},
|
||||||
newdirname : $("#newdirname").val()
|
newdirname : $("#newdirname").val()
|
||||||
},
|
},
|
||||||
success: function( data )
|
success: function( data )
|
||||||
|
|
@ -159,7 +179,5 @@ function addDirAction(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
{% endblock %}
|
||||||
{% endblock content %}
|
|
||||||
|
|
@ -3,6 +3,6 @@ from .views import CloudMain
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('<str:level>/', CloudMain.as_view(template_name="cloud/cloud_main.html"), name='cloud-main'),
|
path('<slug:pk>', CloudMain, name='cloud-main'),
|
||||||
path('clajax/', views.adddirbyajax, name="cloud-ajax"),
|
path('clajax/', views.adddirbyajax, name="cloud-adddir"),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,79 @@ from django.core.files.storage import default_storage
|
||||||
from digitaleagentur.settings import BASE_DIR
|
from digitaleagentur.settings import BASE_DIR
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
import os
|
import os
|
||||||
|
from .models import DataDir, DataFile
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def CloudMain(request, pk):
|
||||||
|
diragency = []
|
||||||
|
alldirs = []
|
||||||
|
context = {}
|
||||||
|
breadcrump = []
|
||||||
|
|
||||||
|
if(pk == "first"):
|
||||||
|
diragency = list(DataDir.objects.filter(is_root=True, agency=request.user.profile.agency))[0]
|
||||||
|
alldirs = DataDir.objects.filter(is_root=False, agency=request.user.profile.agency, parent=diragency)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'active_link' : 'cloud',
|
||||||
|
'dirs' : alldirs,
|
||||||
|
'parentid' : diragency.pk
|
||||||
|
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
alldirs = DataDir.objects.filter(is_root=False, agency=request.user.profile.agency, parent=pk)
|
||||||
|
|
||||||
|
singleObj = DataDir.objects.get(pk=pk)
|
||||||
|
while( singleObj.is_root != True):
|
||||||
|
breadcrump.append(singleObj)
|
||||||
|
singleObj = DataDir.objects.get(pk=singleObj.parent.pk)
|
||||||
|
|
||||||
|
breadcrump = breadcrump[::-1]
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'active_link' : 'cloud',
|
||||||
|
'dirs' : alldirs,
|
||||||
|
'parentid' : pk,
|
||||||
|
'breadcrump' : breadcrump
|
||||||
|
|
||||||
|
}
|
||||||
|
return render(request, 'cloud/cloud_main.html', context)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def adddirbyajax(request):
|
||||||
|
success = True
|
||||||
|
if(request.method == "GET"):
|
||||||
|
parentid = request.GET.get("parent")
|
||||||
|
newdirname = request.GET.get("newdirname")
|
||||||
|
|
||||||
|
parent_obj = DataDir.objects.get(pk=parentid, agency=request.user.profile.agency)
|
||||||
|
tempdir = DataDir(name=newdirname, parent=parent_obj, agency=request.user.profile.agency, owner=request.user)
|
||||||
|
tempdir.save()
|
||||||
|
parent_obj.dirs.add(tempdir)
|
||||||
|
parent_obj.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return JsonResponse({"success" : success})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
''' CLOUD ALT '''
|
||||||
|
'''
|
||||||
class CloudMain(LoginRequiredMixin, FormView):
|
class CloudMain(LoginRequiredMixin, FormView):
|
||||||
form_class = CloudAddFileForm
|
form_class = CloudAddFileForm
|
||||||
success_url = '/cloud/home'
|
success_url = '/cloud/home'
|
||||||
|
|
@ -80,3 +150,7 @@ class CloudMain(LoginRequiredMixin, FormView):
|
||||||
|
|
||||||
def adddirbyajax(request):
|
def adddirbyajax(request):
|
||||||
return {"success" : success}
|
return {"success" : success}
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -133,7 +133,7 @@
|
||||||
{% else%}
|
{% else%}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
{%endif%}
|
{%endif%}
|
||||||
<a class="nav-link " href="{% url 'cloud-main' level='home' %}" aria-expanded="true">
|
<a class="nav-link " href="{% url 'cloud-main' 'first' %}" aria-expanded="true">
|
||||||
<i class="fas fa-file"></i>
|
<i class="fas fa-file"></i>
|
||||||
<span>Dateien</span>
|
<span>Dateien</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ from django.template.loader import render_to_string
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from users.models import AgencyJob, AgencyGroup
|
from users.models import AgencyJob, AgencyGroup
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
|
from cloud.models import DataDir
|
||||||
|
|
||||||
def randomString(stringLength=10):
|
def randomString(stringLength=10):
|
||||||
"""Generate a random string of fixed length """
|
"""Generate a random string of fixed length """
|
||||||
|
|
@ -87,7 +87,16 @@ def toUpdate(request):
|
||||||
else:
|
else:
|
||||||
print("default groups existing")
|
print("default groups existing")
|
||||||
|
|
||||||
|
# INITIAL ROOT DIR
|
||||||
|
rootdir = DataDir.objects.filter(is_root=True, agency__pk=request.user.profile.agency.pk)
|
||||||
|
|
||||||
|
if(len(rootdir) == 0):
|
||||||
|
print("NO MAIN DIR FOUND - CREATE")
|
||||||
|
rootdir = DataDir(is_root=True, agency=request.user.profile.agency)
|
||||||
|
rootdir.save()
|
||||||
|
print("AGENCY ROOT DIR CREATED")
|
||||||
|
else:
|
||||||
|
print("MAIN ROOT DIR FOUND - FILESMODULE READY")
|
||||||
'''
|
'''
|
||||||
|
|
||||||
DASHBOARD-View
|
DASHBOARD-View
|
||||||
|
|
@ -126,8 +135,6 @@ class AgencyCreateView(CreateView):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard(request):
|
def dashboard(request):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue