From 52dc3e444e6042ebe049cf4eef5fc7bb02299616 Mon Sep 17 00:00:00 2001 From: "holger.trampe" Date: Wed, 12 Feb 2020 23:09:15 +0100 Subject: [PATCH] Dateibaum angefangen --- cloud/__pycache__/models.cpython-38.pyc | Bin 1219 -> 1240 bytes cloud/__pycache__/urls.cpython-38.pyc | Bin 346 -> 358 bytes cloud/__pycache__/views.cpython-38.pyc | Bin 1745 -> 2347 bytes cloud/models.py | 1 + cloud/templates/cloud/cloud_main.html | 18 ++++-- cloud/urls.py | 2 +- cloud/views.py | 74 +++++++++++++++++++++--- users/templates/users/base.html | 2 +- 8 files changed, 80 insertions(+), 17 deletions(-) diff --git a/cloud/__pycache__/models.cpython-38.pyc b/cloud/__pycache__/models.cpython-38.pyc index 1d819fd9e1d48dc54901fffea54f3a2d1da35c0e..07c3bcdf4a1fc9d1f4b5c7412a4bdb9a2e2cfe51 100644 GIT binary patch delta 102 zcmX@id4rQTl$V!_0SL_FT;k4dNelF5;fd$QTI# DQ=<(j delta 38 rcmaFHbc=~Ml$V!_0SI2jYs9Ud$XmvAi(%r#GBzHdP!Z2$UdBiO$)O3? diff --git a/cloud/__pycache__/views.cpython-38.pyc b/cloud/__pycache__/views.cpython-38.pyc index 0a875b88b6d9d241ccdfdada4ff23b517d0370a4..948fdfb4a6fb885973a982056a915c952576ce17 100644 GIT binary patch delta 1158 zcmaJ=&2Jk;6rVRc>s>pxW1N<>jS0}wk5!~Pe27z_Dx^Y{P!5fdkX2Z=JCk(n^+#vN z4Mc1C;9fzBd~6TStrgf?y6Yp(80U@!Y`OVCGzxmC~dvAZO{oJg7 zRjXAPemnbH-#)7z)?4uMaO2TOlF3?nuD{k<1BUZ@+Um6AvTQtLowvSV@(tO1$YfIq zwK5Z(by?qG!OG!pzfS|O{%1FKZiZX8Zg0n&lutenM;H6&*fWD**aC8P1Y7JIdB>UX zi8B#7U+|nsIN}S(u&y|QiJQAQNWRK?pes0YdJc{*jzU)qdS?L4xX3OoylKvlfDE}n z+3KW(gc7aqe|Ntk8QxNCTc&Gxyat58w|tmcu^**9>uEJgqgYut9*zgbI++?-ccc@X zi&13mS^sX7sX^3Nf!8T#Ceo%b3#pJP^l-S2OquA+y1PlLa7fhym0H++%Jc=s=GUC- zS8OFsG7}br76qe@z~B_N7WmM>t}mix{v7U<{dSxV$FjXSzre?3eG2V?(3j`G@Gl{l zzv4Gqq|5Ys1Ro%5V9$I625-XrM`vS7fnOr)69mI%tP8s=ho4}Aq3-go(-mE}Tbeky z@+6#PlJ~g2ZG2NUmG07_YHHG1Wu~4xGgxI(tYXrnJL44B!RG(*NO4M%#g@|X7R>Ro z^h{a$uO-VUi(XlIjOoMVaZJ?Gwtg2cY{k7{Umcun_mxbdcC@Dk@eeXGe@(*!uU&+) zT_p4mDmhFb1?`|o?CHPhub>@pyA;JHd7#2H8T9l!xFu-l_i1NiPnj?t4vhNVgmjFi zfaUSaHOhJ|FbEsaO0r!adT67PD! zJ2}agkKYw0Qh!X|zjOKtE-9}kRZ<6PSNJBJpT7`yZ;?wA$JW9yPNOV~Rhow3u|gqJ z2p08m33=3u`tU)3aH^grOYruyzIz_B&Ka5PB_>K0UC4~})l3 delta 552 zcmY*VO>Yx15cPPS-A&TnMEwX64Ictgb;%)uV?m&DK|-h(#08;Ro3$IoS(3`@r3G!( zLpgAvQnV5mIKUAhap5QM3%L5mxjz7j6ZQrnur<&2c;?NU`Mmr+2p7?m$dmJ|^$11n`L7@4uJhFQ21z>0*`WO9%Y0i9I=DO|{o|UsH?4QefI=roz#b~# z6ppaM!V#oEq9$D7318G1yn!R9z#ke67Y=jYG{G8KtJe}xzoThYdoboJc%8LjcBi$ZxMU&Z7@k2#ftYR4&DcYM21y59_T@$Xj zlwISM>lS(zIyMNKLTR&XZCHYyvHv#t4G

- {% 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}}