diff --git a/cloud/__pycache__/models.cpython-38.pyc b/cloud/__pycache__/models.cpython-38.pyc index 1d819fd..07c3bcd 100644 Binary files a/cloud/__pycache__/models.cpython-38.pyc and b/cloud/__pycache__/models.cpython-38.pyc differ diff --git a/cloud/__pycache__/urls.cpython-38.pyc b/cloud/__pycache__/urls.cpython-38.pyc index 54d3df9..cb7a74a 100644 Binary files a/cloud/__pycache__/urls.cpython-38.pyc and b/cloud/__pycache__/urls.cpython-38.pyc differ diff --git a/cloud/__pycache__/views.cpython-38.pyc b/cloud/__pycache__/views.cpython-38.pyc index 0a875b8..948fdfb 100644 Binary files a/cloud/__pycache__/views.cpython-38.pyc and b/cloud/__pycache__/views.cpython-38.pyc differ diff --git a/cloud/models.py b/cloud/models.py index 12cf7a5..668db3c 100644 --- a/cloud/models.py +++ b/cloud/models.py @@ -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) diff --git a/cloud/templates/cloud/cloud_main.html b/cloud/templates/cloud/cloud_main.html index 5c204f7..ac18deb 100644 --- a/cloud/templates/cloud/cloud_main.html +++ b/cloud/templates/cloud/cloud_main.html @@ -17,21 +17,27 @@

- {% if all_files %} + {% if files %} - + - - {% for ele in all_files %} - - + + {% for dir in dirs_level %} + + + + + {% endfor %} + {% for ele in files %} + + diff --git a/cloud/urls.py b/cloud/urls.py index 646bc4f..424fb0d 100644 --- a/cloud/urls.py +++ b/cloud/urls.py @@ -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('/', CloudMain.as_view(template_name="cloud/cloud_main.html"), name='cloud-main'), ] diff --git a/cloud/views.py b/cloud/views.py index 18bc967..dd5eab7 100644 --- a/cloud/views.py +++ b/cloud/views.py @@ -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 \ No newline at end of file + 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}) +''' \ No newline at end of file diff --git a/users/templates/users/base.html b/users/templates/users/base.html index aeb741e..522294c 100644 --- a/users/templates/users/base.html +++ b/users/templates/users/base.html @@ -132,7 +132,7 @@ {% else%}
# Name Eigentümer Datum
{{forloop.counter}}
{{dir}}
{{ele.file}} {{ele.owner.first_name}} {{ele.owner.last_name}} {{ele.date_created}}