@ -1,7 +1,10 @@
from flask import Flask , render_template , Markup , jsonify
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 ' )
@ -9,6 +12,7 @@ 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
@ -50,16 +54,53 @@ with open('static/js/mergedjson.json', 'r', encoding='utf8') as filesandnames:
print ( " librarians for " + str ( fileselected ) + " are: " + str ( thelibrarian ) )
print ( " --------------------------------------------------- " )
print ( librarians )
@app . route ( " / " )
# preparing a index.json file of files
index_dict = { }
@app . route ( " / " , methods = [ ' POST ' , ' GET ' ] )
def home ( ) :
return render_template ( ' layout.html ' , filetoname_dict = filetoname_dict , librarians = librarians , files_without_folders = files_without_folders )
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 ( ) :
return render_template ( ' about.html ' )
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 ' )