diff --git a/__pycache__/contextualise.cpython-35.pyc b/__pycache__/contextualise.cpython-35.pyc index 42e862e..9fa3bb5 100644 Binary files a/__pycache__/contextualise.cpython-35.pyc and b/__pycache__/contextualise.cpython-35.pyc differ diff --git a/contextualise.py b/contextualise.py index de78577..a0aca37 100644 --- a/contextualise.py +++ b/contextualise.py @@ -1,9 +1,5 @@ from flask import Flask, url_for, render_template, Markup, redirect, request, flash from flask import session as login_session -from flask_wtf import FlaskForm -from wtforms.validators import DataRequired -from wtforms import Form, TextField, TextAreaField, BooleanField, validators, StringField, SubmitField -from forms import ReusableForm from config import Config import json import os @@ -16,103 +12,114 @@ app.jinja_env.add_extension('jinja2.ext.loopcontrols') app.config.from_object(Config) -#### THE CHECKBOX RESULT DOESNT GET RECORDED TO THE JSON FILE -#### FULL LOOP WITH FILE AND RELOADING THE FORM WITH NEXT FILE IN THE ARRAY HAS TO BE MADE -#### OPTIONS TO SWITCH BETWEEN FILES NEED TO BE AVAILABLE -#### MAYBE CONFIRMATION BEFORE JSON IS RECORDED TO FORCE PEOPLE TO DOUBLE THINK - - # setting variables for holding paths, folder names and the one file for description path = "static/files/" +jsonfiles = [] #json files + +fullpathjsonfiles = [] #fullpath for some situations listingfiles= [] #fullpaths listingdirectories = [] #paths + jsonfiles = [] #json files +fullpathjsonfiles = [] #fullpath for some situations thefile = None #selected file for description now = strftime("%Y-%m-%d_%H:%M:%S", gmtime()) #description time positioninarray = 8 #counter - listofdicts=[] #to be able to import and use json content +datafromjson = [] + #listing paths and files, not in order but well... for path, subdirs, files in os.walk(path): - for name in files: + for name in files: #excluding json files from listing :-) - if not name.endswith(".json") and not name.endswith(".DS_Store"): - fullpath = os.path.join(path, name) - listingdirectories.append(path) - listingfiles.append(fullpath[7:]) #fullpaths minus static/ - # print (path) - # print (name) - # print (os.path.join(path, name)) - if name.endswith(".json"): - fullpath = os.path.join(path, name) - jsonfiles.append(fullpath[7:]) - # print(name) - for line in open(fullpath, 'r'): - listofdicts.append(json.loads(line)) - -# print(listofdicts[0]["name"]) #test + if not name.endswith(".json") and not name.endswith(".DS_Store"): + fullpath = os.path.join(path, name) + listingdirectories.append(path) + listingfiles.append(fullpath[7:]) #fullpaths minus static/ + + if name.endswith(".json"): + fullpath = os.path.join(path, name) + jsonfiles.append(fullpath[7:]) + # print(name) + # for line in open(fullpath, "r"): + # listofdicts.append(json.loads(line)) + +#================================================= +#listing the json paths +for path, subdirs, files in os.walk(path): + for name in files: + if name.endswith(".json"): + fullpath = os.path.join(path, name) + jsonfiles.append(fullpath[7:]) + fullpathjsonfiles.append(fullpath) + +print(jsonfiles) +print("-------------------------") + dict = {} #dict for the form entries + +with open("static/"+jsonfiles[4], 'r') as f: + data_dict = json.load(f) + datafromjson = data_dict["files"] +print(datafromjson) + @app.route("/") def home(): - return render_template('home.html') + return render_template('home.html') @app.route('/about/') def about(): - return render_template('about.html') + return render_template('about.html') @app.route('/all/') def all(): - thefile = listingfiles[positioninarray] - print(listingfiles) - # print(dict) - counter2=0 - return render_template('all.html', file=thefile, listingfiles=listingfiles, jsonfiles=jsonfiles, listofdicts=listofdicts, counter2=counter2) - + thefile = listingfiles[positioninarray] + print(listingfiles) + # print(dict) + counter2=0 + return render_template('all.html', file=thefile, listingfiles=listingfiles, jsonfiles=jsonfiles, listofdicts=listofdicts, counter2=counter2) + @app.route('/description') def description(): -#pick a file but that will be done an other way later - thefile = listingfiles[positioninarray] #select one file from fullpath minus static/ - -# assigning html tag on the basis of extension, to be finished when all the files have been sent - if thefile.lower().endswith(('.png', '.jpg', '.jpeg')): - thefile = Markup('
') - - #if sound - elif thefile.lower().endswith(('.mp3')): - thefile = Markup('''''') - #if txtfile - elif thefile.lower().endswith(('.txt')): - # print(thefile) - - with open("static/"+thefile,"r") as f: - path = f.read() - thefile = path - - # yotxt = open(thefile, 'r+') - # thefile = text.read() - # text.close() - - # thefile = Markup('''