From de29d780e3c29d54c461a356828af399b6ae8242 Mon Sep 17 00:00:00 2001 From: zeroth Date: Fri, 9 Oct 2020 19:10:50 +0100 Subject: [PATCH] boxes for other items and zip works on server but corrupted at download --- __pycache__/library.cpython-35.pyc | Bin 1749 -> 2910 bytes library.py | 28 +- .../20201007-library.py | 2 +- library_julie.py => oldlibs/library_julie.py | 0 oldlibs/libraryjuju.py | 106 ++++++ oldlibs/llllllibrary.py | 65 ++++ static/default-files/hello.txt | 1 + templates/20201007-layout.html | 255 +++++++++++++ templates/layout.html | 6 +- templates/layoutjuju.html | 342 ++++++++++++++++++ templates/llllllllayout.html | 143 ++++++++ 11 files changed, 942 insertions(+), 6 deletions(-) rename library_cristina.py => oldlibs/20201007-library.py (97%) rename library_julie.py => oldlibs/library_julie.py (100%) create mode 100644 oldlibs/libraryjuju.py create mode 100644 oldlibs/llllllibrary.py create mode 100644 static/default-files/hello.txt create mode 100644 templates/20201007-layout.html create mode 100644 templates/layoutjuju.html create mode 100644 templates/llllllllayout.html diff --git a/__pycache__/library.cpython-35.pyc b/__pycache__/library.cpython-35.pyc index e781f6b4117764dca648caa87a0159e253cd28c9..48e2983b4154500e440392b07fb69ddbdc14e312 100644 GIT binary patch literal 2910 zcmb6bU2hx5arSt3{E#SGlx3RMhvkn*rW5mkegH+#6hWdmahuAnr9$Z<0de9k#iQ}#L=7xI*uJszz*meek1XJ%(+=TohEz4rKDf9d^a z1K@vf?X!yTr?~Xr8~}lT3}S$U0cVgnz#T|Rz)O(0z+Ff@;2tDCa37K~@G>yE<3L;i zUa|KPt^%)GxJ3A*2E4Z9TLHdO@T~%0E#Nxvx`kbc*C1&CZvc}Fcl1ZqIR zHF(QPd>!OEjG8do0I`A?)PVACfyC8RnpY+K+koRD8pJ+J> zRbFng(@U3~iVffoVD?Ea^Oq!(1m1);e+aS)qnj}L0OUif95Jmzyv30C%Wv2z8YDKM zZLjUa>?D`=wUxGC2)yt?ea{x=@&k~MK-{vX?vwPEXhDk%Kd>ijIda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RF9tRl!nP!Bld_G# z)}{6MwRl}CuOaRRM)*G4bba@rwdHMjKLS``yFCB^ delta 967 zcmZuv&1(}u9DTE!-6Wf&Nt5Pdn>ML!MRQ3&C_?>&mR>BaS|Kt}q;`hZHEEjNRAMhd z>cx}DUcGtpKPU*^y?FBy!GoUqU-+9zB0V_EKHmI3-n{wvRrrxwDyCA-r!NQ3K03f3 zTpCH@_vsHZAC{H}OaQ__%L2DB<~F#kxvApqD0mc1GRPQ21cK@)9fhE29B0hramYA4 z2VMfgp$M2rfG2SP@RY_W$TUO}A_Xx8k;a+9-lrKKWFReg(~ud}$Ft}^fXrfjcMUv; z{wib+A_I4Qw+=o7nSz&xEI`hvdbN}+LYCmUDmMzzn%!?`cF)li)8Mn{-x+DHC`~1p zh0Dv3HU?f2-W+6EuTG(JHMISh& zW_79zF*ivqPEvYNQGuvVQcLQlcWMh4>NV6NLu;cIel@N-TQxSc#7X-&2=itqd}r1f z56{hDV_y|cMvTZB{lOeTk6sOVGSDM5(KFP`=$Yik+^Jbxr-|0y>&{89e%Ncb!Yym1 z67fxH^Ro(a3T6mC!_O<855HU6?oFbBK>))q5}rmId(TOv5nkBWR~^l@V2zE$M!i%y zQYjD{TDt5O(TP+k{Aq7C{#P55{r$teqXT*GQn^dKwj92Rmy^SY7j%w>Mkny?@OS)1 zbnHBAI8~Mnx1CoHht{$G;;1*Yd@?GvZNEeczLFVl?jO?zW4GHKanh1^8O4KDf<>03 UFJn|#CKA>Y*P@1Flq2QHU#i@%0{{R3 diff --git a/library.py b/library.py index ee11bc7..36218e6 100644 --- a/library.py +++ b/library.py @@ -1,10 +1,11 @@ -from flask import Flask, render_template, Markup, jsonify, session, request +from flask import Flask, render_template, Markup, jsonify, session, request, send_file import json import os from json import dumps import collections import random import string +from zipfile import ZipFile app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") app.jinja_env.add_extension('jinja2.ext.loopcontrols') @@ -97,10 +98,33 @@ def exchange(): def test(): print("test") clicked=None + bundle = "bundle.zip" + zipObj = ZipFile(bundle, 'w') + if request.method == "POST": # clicked=request.form['data'] listofselecteddocs = request.get_json() print("hallo") print(listofselecteddocs) print("hola") - return render_template('test.html') + + + + # create a ZipFile object + + # Add multiple files to the zip + zipObj.write('static/files/'+listofselecteddocs[0]) + zipObj.write('static/files/'+listofselecteddocs[1]) + zipObj.write('static/default-files/hello.txt') + # close the Zip File + + # return render_template('test.html') + # return send_file(bundle, mimetype='application/zip', as_attachment=True, attachment_filename=bundle) + # TEST + # print("sending file...") + # result = send_file(bundle, as_attachment=True) + # print("file sent, deleting...") + # os.remove(bundle) + # return result + zipObj.close() + return send_file(bundle, mimetype='application/zip', attachment_filename="hello.zip", as_attachment=True) diff --git a/library_cristina.py b/oldlibs/20201007-library.py similarity index 97% rename from library_cristina.py rename to oldlibs/20201007-library.py index 57834df..b2c015e 100644 --- a/library_cristina.py +++ b/oldlibs/20201007-library.py @@ -59,7 +59,7 @@ def home(): # We have our query string nicely serialized as a Python dictionary args = request.args # We'll create a string to display the parameters & values - serialized = ", ".join(f"{k}: {v}" for k, v in request.args.items()) + # serialized = ", ".join(f"{k}: {v}" for k, v in request.args.items()) # Display the query string to the client in a different format # return f"(Query) {serialized}", 200 urllibrarian=request.args.getlist('librarian') # new diff --git a/library_julie.py b/oldlibs/library_julie.py similarity index 100% rename from library_julie.py rename to oldlibs/library_julie.py diff --git a/oldlibs/libraryjuju.py b/oldlibs/libraryjuju.py new file mode 100644 index 0000000..8230541 --- /dev/null +++ b/oldlibs/libraryjuju.py @@ -0,0 +1,106 @@ +from flask import Flask, render_template, Markup, jsonify, session, request +import json +import os +from json import dumps +import collections +import random +import string + +app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") +app.jinja_env.add_extension('jinja2.ext.loopcontrols') + + +# SETTING THE VARIABLES +path = "/static/files/" +max_selected_items = 30 + +#move this list to Jinja so it can be placed in layout +#give back clicked value +# librarians = ["Alana", "Gentian", "Laurie", "Matias", "Scott", "Stacy", "Max", "Clara_B", "Michelle", "Clara_J_B", "Karen", "Lumsden_Primary_School", "Aaron", "Leo", "Maria", "Laura", "Honey", "Tender_Center", "wdka", "Naomi", "Cristina", "Julie", "ssw", "cyberspace", "Hannah", "Katarina", "Anastasia", "Kimmy", "Marie","Katherine", "Allison", "Mariana", "Viki", "Alice", "Eric", "hks", "cbk", "Sophie", "Antonio", "Jeremiah", "Angela", "Renee", "Marta", "Katherine", "Anna", "Auryn", "Ashley", "Anne", "Denise", "Eva", "Jonnah", "Kitty", "Masha", "Mia", "Cian", "Senke", "Maud", "Jinnie", "Rubin", "Julia", "Alana", "Gentian", "Laurie", "Matias","Scott", "Stacy"] + +librarians = [] +files_without_folders = [] + +with open('static/js/mergedjson.json', 'r', encoding='utf8') as filesandnames: + filetoname_dict = json.load(filesandnames) + +#get full list librarians from json (printed later through global variable) + for file in filetoname_dict: + for name in file["librarian"]: + librarians.append(str(name)) + librarians = list(dict.fromkeys(librarians)) + +#this value we should get from template + librarianselected = "Ruben" + +#go from librarian name to file + for file in filetoname_dict: + # if librarianselected in file["librarian"]: + thedebris = file["debrisname"] + #apply regex to the debris + thedebris = os.path.basename(thedebris) + files_without_folders.append(str(thedebris)) + # print(str(librarianselected)+" contributed with the following debris : "+str(thedebris)) + + + +#this value we should get from template + fileselected = filetoname_dict[1]["debrisname"] + +#go from file name to librarian name + for file in filetoname_dict: + if fileselected in file["debrisname"]: + thelibrarian = file["librarian"] + print("librarians for "+ str(fileselected)+" are: " + str(thelibrarian)) + print("---------------------------------------------------") + + +# preparing a index.json file of files +index_dict = {} + + + +@app.route("/", methods=['POST', 'GET']) +def home(): + if request.args: + # We have our query string nicely serialized as a Python dictionary + args = request.args + # We'll create a string to display the parameters & values + #serialized = ", ".join(f"{k}: {v}" for k, v in request.args.items()) + # Display the query string to the client in a different format + # return f"(Query) {serialized}", 200 + urllibrarian=request.args.getlist('librarian') # new + urlmethod=request.args.getlist('method') # new + for a in urllibrarian: + print('urllibrarian is: '+ a) + for b in urlmethod: + print('urlmethod is: ' + b) +#unsure if Im really using that for now I think not + # selected = "textbysomeone" + # selections = collections.deque(session['selection'], maxlen=max_selected_items) #? + # selections.append(selected) + # session['selection'] = list(selections) + return render_template('layout.html', urllibrarian=urllibrarian, urlmethod=urlmethod, filetoname_dict=filetoname_dict, librarians=librarians, files_without_folders = files_without_folders) # new + + +@app.route('/about/') +def about(): + selectedstuff = session['selection'] + return render_template('about.html', selectedstuff=selectedstuff) + +@app.route('/exchange') +def exchange(): + return render_template('exchange.html') + + +@app.route('/test/', methods=['GET','POST']) +def test(): + print("test") + clicked=None + if request.method == "POST": + # clicked=request.form['data'] + listofselecteddocs = request.get_json() + print("hallo") + print(listofselecteddocs) + print("hola") + return render_template('test.html') diff --git a/oldlibs/llllllibrary.py b/oldlibs/llllllibrary.py new file mode 100644 index 0000000..3198fdf --- /dev/null +++ b/oldlibs/llllllibrary.py @@ -0,0 +1,65 @@ +from flask import Flask, render_template, Markup, jsonify +import json +import os +from json import dumps + +app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") +app.jinja_env.add_extension('jinja2.ext.loopcontrols') + + +# SETTING THE VARIABLES +path = "/static/files/" + +#move this list to Jinja so it can be placed in layout +#give back clicked value +# librarians = ["Alana", "Gentian", "Laurie", "Matias", "Scott", "Stacy", "Max", "Clara_B", "Michelle", "Clara_J_B", "Karen", "Lumsden_Primary_School", "Aaron", "Leo", "Maria", "Laura", "Honey", "Tender_Center", "wdka", "Naomi", "Cristina", "Julie", "ssw", "cyberspace", "Hannah", "Katarina", "Anastasia", "Kimmy", "Marie","Katherine", "Allison", "Mariana", "Viki", "Alice", "Eric", "hks", "cbk", "Sophie", "Antonio", "Jeremiah", "Angela", "Renee", "Marta", "Katherine", "Anna", "Auryn", "Ashley", "Anne", "Denise", "Eva", "Jonnah", "Kitty", "Masha", "Mia", "Cian", "Senke", "Maud", "Jinnie", "Rubin", "Julia", "Alana", "Gentian", "Laurie", "Matias","Scott", "Stacy"] + +librarians = [] +files_without_folders = [] + +with open('static/js/mergedjson.json', 'r', encoding='utf8') as filesandnames: + filetoname_dict = json.load(filesandnames) + +#get full list librarians from json (printed later through global variable) + for file in filetoname_dict: + for name in file["librarian"]: + librarians.append(str(name)) + librarians = list(dict.fromkeys(librarians)) + +#this value we should get from template + librarianselected = "Ruben" + +#go from librarian name to file + for file in filetoname_dict: + # if librarianselected in file["librarian"]: + thedebris = file["debrisname"] + #apply regex to the debris + thedebris = os.path.basename(thedebris) + files_without_folders.append(str(thedebris)) + # print(str(librarianselected)+" contributed with the following debris : "+str(thedebris)) + + + +#this value we should get from template + fileselected = filetoname_dict[1]["debrisname"] + +#go from file name to librarian name + for file in filetoname_dict: + if fileselected in file["debrisname"]: + thelibrarian = file["librarian"] + print("librarians for "+ str(fileselected)+" are: " + str(thelibrarian)) + print("---------------------------------------------------") + +print(librarians) + +@app.route("/") +def home(): + return render_template('layout.html', filetoname_dict=filetoname_dict, librarians=librarians, files_without_folders = files_without_folders) + +@app.route('/about/') +def about(): + return render_template('about.html') + +@app.route('/exchange') +def exchange(): + return render_template('exchange.html') diff --git a/static/default-files/hello.txt b/static/default-files/hello.txt new file mode 100644 index 0000000..86e6423 --- /dev/null +++ b/static/default-files/hello.txt @@ -0,0 +1 @@ +Hello this is your bundle \ No newline at end of file diff --git a/templates/20201007-layout.html b/templates/20201007-layout.html new file mode 100644 index 0000000..7ef7690 --- /dev/null +++ b/templates/20201007-layout.html @@ -0,0 +1,255 @@ + + + + + + + Library + + + + + + +
+
+ +
+ {% for librarian in librarians %} + + {{librarian}} + {% endfor %} +
+
+ +
+ + {% for querylibrarian in urllibrarian %} + {% for file in filetoname_dict %} + {% for item in file['librarian'] %} + {% if item == querylibrarian and urlmethod == []%} + {% set show_file = file['debrisname'] %} + {{show_file}} + {% elif item == querylibrarian %} + {% for urlmeth in urlmethod %} + {% if urlmeth.lower() == file['method'].lower() %} + {% set show_file = file['debrisname'] %} + {{show_file}} + {% endif %} + {% endfor %} + {% endif %} + {% endfor %} + {% endfor %} + {% endfor %} + + + {% for querymethod in urlmethod %} + {% for file in filetoname_dict %} + {% if querymethod.lower() == file['method'].lower()%} + {% set show_file = file['debrisname'] %} + {{show_file}} + {% endif %} + {% endfor %} + {% endfor %} +
+
+ +
+ test link +
    +

    hello world

    +
+ + {% block content %} + {% endblock content %} +
+
+ + + + + + diff --git a/templates/layout.html b/templates/layout.html index 72a62d3..e8329e4 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -118,10 +118,10 @@ $(".name-elements").append("
  • "+ledocument+"
  • "); } else if ((extension=="mp3") || (extension=="wav") || (extension=="m4a")) { - $(".name-elements").append("
  • "); + $(".name-elements").append("
  • "+checkboite+"
  • "); } else if ((extension=="mov") || (extension=="mp4")) { - $(".name-elements").append("
  • "); + $(".name-elements").append("
  • "+checkboite+"
  • "); } else if ((extension=="odt") || (extension=="docx")) { // something for odt and docx @@ -198,7 +198,7 @@ $.ajax({ - + diff --git a/templates/layoutjuju.html b/templates/layoutjuju.html new file mode 100644 index 0000000..e7f8b08 --- /dev/null +++ b/templates/layoutjuju.html @@ -0,0 +1,342 @@ + + + + + + + Library + + + + + + + + + + +
    + +
    + +
    + {% for librarian in librarians %} + + {{ librarian }} + {% endfor %} +
    + + + + + + +
    +
    + + {% for querylibrarian in urllibrarian %} + {% for file in filetoname_dict %} + {% for item in file['librarian'] %} + {% if item == querylibrarian and urlmethod == []%} + {% set show_file = file['debrisname'] %} + {{show_file}} + {% elif item == querylibrarian %} + {% for urlmeth in urlmethod %} + {% if urlmeth.lower() == file['method'].lower() %} + {% set show_file = file['debrisname'] %} + {{show_file}} + {% endif %} + {% endfor %} + {% endif %} + {% endfor %} + {% endfor %} + {% endfor %} + + + {% for querymethod in urlmethod %} + {% for file in filetoname_dict %} + {% if querymethod.lower() == file['method'].lower()%} + {% set show_file = file['debrisname'] %} + {{show_file}} + {% endif %} + {% endfor %} + {% endfor %} +
    +
    + +
    + test link +
      +

      hello world

      +
    + + {% block content %} + {% endblock content %} +
    +
    + + + + + + + + + \ No newline at end of file diff --git a/templates/llllllllayout.html b/templates/llllllllayout.html new file mode 100644 index 0000000..af330eb --- /dev/null +++ b/templates/llllllllayout.html @@ -0,0 +1,143 @@ + + + + + + + Library + + + + + + + + + +
    +
    + +
    + {% for librarian in librarians %} + + {{ librarian }} + {% endfor %} +
    +
    + +
    + {% for file in files_without_folders %} + {{file}}
    + {% endfor %} +
    +
    + +
    + test link +
      +

      hello world

      +
    + + {% block content %} + {% endblock content %} +
    +
    + + + +