Dateibaum angefangen
This commit is contained in:
parent
ea33eaaffd
commit
52dc3e444e
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -20,4 +20,5 @@ class Data(models.Model):
|
|||
agency = models.ForeignKey(Agency, on_delete=models.CASCADE, default=None)
|
||||
|
||||
def __str__(self):
|
||||
print(self.file.name)
|
||||
return str(self.file.name)
|
||||
|
|
|
|||
|
|
@ -17,21 +17,27 @@
|
|||
</form>
|
||||
<div class="mt-4">
|
||||
<p>
|
||||
{% if all_files %}
|
||||
{% if files %}
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col">Eigentümer</th>
|
||||
<th scope="col">Datum</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for ele in all_files %}
|
||||
<tr>
|
||||
<td>{{forloop.counter}}</td>
|
||||
<tbody>
|
||||
{% for dir in dirs_level %}
|
||||
<tr>
|
||||
<td><i class="fas fa-folder"></i></td>
|
||||
<td><a href="{% url 'cloud-main' dir %}">{{dir}}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% for ele in files %}
|
||||
<tr>
|
||||
<td><i class="fas fa-file"></i></td>
|
||||
<td>{{ele.file}}</td>
|
||||
<td>{{ele.owner.first_name}} {{ele.owner.last_name}}</td>
|
||||
<td>{{ele.date_created}}</td>
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ from django.urls import path
|
|||
from .views import CloudMain
|
||||
|
||||
urlpatterns = [
|
||||
path('', CloudMain.as_view(template_name="cloud/cloud_main.html"), name='cloud-main'),
|
||||
path('<str:level>/', CloudMain.as_view(template_name="cloud/cloud_main.html"), name='cloud-main'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -9,25 +9,81 @@ from django.views.generic.edit import FormView
|
|||
from .forms import CloudAddFileForm
|
||||
from django.conf import settings
|
||||
from django.core.files.storage import default_storage
|
||||
from digitaleagentur.settings import BASE_DIR
|
||||
import os
|
||||
|
||||
# Create your views here.
|
||||
'''
|
||||
import os
|
||||
|
||||
def list_files(startpath):
|
||||
for root, dirs, files in os.walk(startpath):
|
||||
level = root.replace(startpath, '').count(os.sep)
|
||||
indent = ' ' * 4 * (level)
|
||||
print('{}{}/'.format(indent, os.path.basename(root)))
|
||||
subindent = ' ' * 4 * (level + 1)
|
||||
for f in files:
|
||||
print('{}{}'.format(subindent, f))
|
||||
'''
|
||||
|
||||
def list_files(startpath, deep):
|
||||
for root, dirs, files in os.walk(startpath):
|
||||
level = root.replace(startpath, '').count(os.sep)
|
||||
if(level <= deep+1 and (deep != 0 and(level > 0))):
|
||||
print(level)
|
||||
print(os.path.basename(root))
|
||||
for f in files:
|
||||
print(f)
|
||||
|
||||
|
||||
class CloudMain(LoginRequiredMixin, FormView):
|
||||
form_class = CloudAddFileForm
|
||||
success_url = '/cloud/'
|
||||
success_url = '/cloud/0'
|
||||
|
||||
|
||||
def form_valid(self, form):
|
||||
form = CloudAddFileForm(self.request.POST, self.request.FILES['file'])
|
||||
|
||||
tempdata = Data(file=self.request.FILES['file'], subdir="subdir1/subdir2", agency=self.request.user.profile.agency, owner=self.request.user)
|
||||
tempdata = Data(file=self.request.FILES['file'], subdir="", agency=self.request.user.profile.agency, owner=self.request.user)
|
||||
tempdata.save()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
# Change context and return for template-data
|
||||
def get_context_data(self, **kwargs):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
all_files = Data.objects.filter(agency__pk=self.request.user.profile.agency.pk)
|
||||
context.update({'active_link' : 'cloud', 'all_files': all_files})
|
||||
return context
|
||||
agency_id = self.request.user.profile.agency.pk
|
||||
if(self.kwargs['level'] == "home"):
|
||||
print(list_files(os.path.dirname(BASE_DIR+"/media/agencydata/agency_"+str(agency_id)+"/files/"), 0))
|
||||
else:
|
||||
print(list_files(os.path.dirname(BASE_DIR+"/media/agencydata/agency_"+str(agency_id)+"/files/"+self.kwargs['level']),2))
|
||||
context.update({'active_link' : 'cloud', 'files': list_files("agencydata/agency_"+str(agency_id)+"/", 2)})
|
||||
return context
|
||||
|
||||
|
||||
|
||||
'''
|
||||
dirs_level = []
|
||||
files = ""
|
||||
subdir = ""
|
||||
files_correcteddirname = []
|
||||
agency_id = self.request.user.profile.agency.pk
|
||||
if(self.kwargs["level"] == "home"):
|
||||
files = Data.objects.filter(agency__pk=agency_id, subdir="")
|
||||
|
||||
for f in files:
|
||||
tempstr = str(f.file)
|
||||
files_correcteddirname.append(tempstr.split("/")[3])
|
||||
|
||||
dirs = Data.objects.filter(agency__pk=agency_id).exclude(subdir="")
|
||||
|
||||
for d in dirs:
|
||||
tempstr = str(d.file)
|
||||
dirs_level.append(tempstr.split("/")[3])
|
||||
else:
|
||||
subdir = self.kwargs["level"]
|
||||
files = Data.objects.filter(agency__pk=agency_id, file__startswith="agencydata/agency_"+str(agency_id)+"/files/"+subdir)
|
||||
dirs = Data.objects.filter(agency__pk=agency_id).exclude(subdir="")
|
||||
for d in dirs:
|
||||
tempstr = str(d.file)
|
||||
dirs_level.append(tempstr.split("/")[4])
|
||||
|
||||
context.update({'active_link' : 'cloud', 'files': files, 'dirs_level' : dirs_level})
|
||||
'''
|
||||
|
|
@ -132,7 +132,7 @@
|
|||
{% else%}
|
||||
<li class="nav-item">
|
||||
{%endif%}
|
||||
<a class="nav-link " href="{% url 'cloud-main' %}" aria-expanded="true">
|
||||
<a class="nav-link " href="{% url 'cloud-main' level='home' %}" aria-expanded="true">
|
||||
<i class="fas fa-cloud"></i>
|
||||
<span>Dateien</span>
|
||||
</a>
|
||||
|
|
|
|||
Loading…
Reference in New Issue