From f0179dacbb77d35ba9167ff717e1cd97121d66c3 Mon Sep 17 00:00:00 2001 From: Cristina Cochior Date: Wed, 23 Jan 2019 01:51:15 +0100 Subject: [PATCH] added new template that displays all files --- .DS_Store | Bin 6148 -> 6148 bytes contextualise.py | 37 ++++++++-- data_file.json | 1 + forms.py | 3 +- json_actions.py | 38 +++++++++++ static/.DS_Store | Bin 0 -> 6148 bytes static/files/.DS_Store | Bin 0 -> 6148 bytes static/files/001/.DS_Store | Bin 0 -> 6148 bytes .../001/2019-01-22_08:49:43_data_file.json | 1 + static/files/002/.DS_Store | Bin 0 -> 6148 bytes .../002/2019-01-15_21:42:00_data_file.json | 1 - .../002/2019-01-20_17:47:03_data_file.json | 1 + .../002/2019-01-22_09:09:09_data_file.json | 1 + .../003/2019-01-22_09:09:52_data_file.json | 1 + templates/all.html | 64 ++++++++++++++++++ templates/layout.html | 1 + 16 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 data_file.json create mode 100644 json_actions.py create mode 100644 static/.DS_Store create mode 100644 static/files/.DS_Store create mode 100644 static/files/001/.DS_Store create mode 100644 static/files/001/2019-01-22_08:49:43_data_file.json create mode 100644 static/files/002/.DS_Store delete mode 100644 static/files/002/2019-01-15_21:42:00_data_file.json create mode 100644 static/files/002/2019-01-20_17:47:03_data_file.json create mode 100644 static/files/002/2019-01-22_09:09:09_data_file.json create mode 100644 static/files/003/2019-01-22_09:09:52_data_file.json create mode 100644 templates/all.html diff --git a/.DS_Store b/.DS_Store index b8ca9541f369b7e9c1bbc83ee9ea266a40e134cb..e41ef18d19a819f95a1291bc03fd3a72dd7e42ed 100644 GIT binary patch delta 319 zcmZvX(Fy@U7=_QUSYfRT-h#FyFW|#(m=*Nex(lI4g;vrnc%nRuLK!F}vo9SMFGMfDZw)2MGNS9pDkF diff --git a/contextualise.py b/contextualise.py index ffb65e9..3afecde 100644 --- a/contextualise.py +++ b/contextualise.py @@ -8,6 +8,8 @@ from config import Config import json import os from time import gmtime, strftime +from pprint import pprint + app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") app.config.from_object(Config) @@ -23,24 +25,35 @@ app.config.from_object(Config) path = "static/files/" listingfiles= [] #fullpaths listingdirectories = [] #paths +jsonfiles = [] #json files thefile = None #selected file for description now = strftime("%Y-%m-%d_%H:%M:%S", gmtime()) #description time -positioninarray = 0 #counter +positioninarray = 2 #counter + +listofdicts=[] #to be able to import and use json content #listing paths and files, not in order but well... for path, subdirs, files in os.walk(path): for name in files: #excluding json files from listing :-) - if not name.endswith(".json"): + if not name.endswith(".json") and not name.endswith(".DS_Store"): fullpath = os.path.join(path, name) - listingdirectories.append(path) + listingdirectories.append(path[7:]) listingfiles.append(fullpath[7:]) #fullpaths minus static/ - print (path) - print (name) - print (os.path.join(path, name)) + # 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 -dict={} #dict for the form entries +dict = {} #dict for the form entries @app.route("/") def home(): @@ -50,6 +63,15 @@ def home(): def about(): return render_template('about.html') +@app.route('/all/') +def all(): + thefile = listingfiles[positioninarray] + print(listingfiles) + #here i need to json.load each file + print(dict) + return render_template('all.html', file=thefile, listingfiles=listingfiles, jsonfiles=jsonfiles, listofdicts=listofdicts) + + @app.route('/description', methods=['GET', 'POST']) def description(): form = ReusableForm(request.form) @@ -87,6 +109,7 @@ def savepost(): # open with "a" if the file should concatenate content #json file naming gone unique by adding time and date of submission + with open(listingdirectories[positioninarray]+"/"+now+"_data_file.json", "w") as write_file: json.dump(dict, write_file) return "The JSON file is ready." diff --git a/data_file.json b/data_file.json new file mode 100644 index 0000000..d75b1a0 --- /dev/null +++ b/data_file.json @@ -0,0 +1 @@ +{"name": "as", "email": "asd", "friend": "Y", "content": "asd"} \ No newline at end of file diff --git a/forms.py b/forms.py index 44f290a..03018ac 100644 --- a/forms.py +++ b/forms.py @@ -8,4 +8,5 @@ class ReusableForm(Form): email = TextField('Email:',[validators.Required('Please enter your email address.'), validators.Email('Please enter your email address.')]) friend = RadioField('Are you a friend of De Player?', choices = [('Y','Yes'),('NY','Not Yet')]) content = StringField('Description:',[validators.Required('Please enter a description.')]) - submit = SubmitField('Send') \ No newline at end of file + submit = SubmitField('Send') + diff --git a/json_actions.py b/json_actions.py new file mode 100644 index 0000000..d00ed47 --- /dev/null +++ b/json_actions.py @@ -0,0 +1,38 @@ +import json + + +# # to iterate through existing json file and find the correct json file +# def find_json(id): +# get path/to/file + +# return file + +# # +# def save_json(id, name, email, friend, content): +# file +# data = {"id": "path/to/file", "name":,"email":,"friend":,"content":} + +# with open('file.json', 'w') as f: +# json.dump(data, f) + + + + +# def jaction(original, id, name, email, friend, content): +# f = find_json_file(id) +# data = make_dict(f) + +# updated = update_dict(data, name, email, friend, content) +# save_json_file(f, updated) + +# # to find the file with the correct id +# def find_json_file(): +# f = open('file.json', 'w') +# iterate files to find id +# return f + +# # saving the json file +# def save_json_file(name, email, friend, content): +# dict= request.args.get( +# write(file, json.dump(data)) + diff --git a/static/.DS_Store b/static/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c191a5ac030c15dfd4b409946b81755a53d117d9 GIT binary patch literal 6148 zcmeH~J&FS{427RI2`p@rGNqe6KyF|{_5`^=$R8{WqzLJK^gPLGGTC|=!V}2PlCAmq zitz}5ZSJQvumtc)cg434BQwSeT=0tlXWUM=<8ZiM2T$W8_j*9*HJ;aVSt0@=AOa#F z0wORW0&$4*{QsKJGwD%8Km?{iz`qZL?pjk@*Z6dBh!%i4XF81Y=q0Gd6V#g8x-vtv z>>eyjE!q&zM>)0RzM9&)_HtM@AC`AE?_y}y%VC89&1#4S5fFh9fmx52e*XW^|LXro zB??7A1m28*&9}SlhA)+8>&xqTexF&NH##-8b9nj*VBkmbiXO)G;uC63ZC#n6=|>l2Is literal 0 HcmV?d00001 diff --git a/static/files/.DS_Store b/static/files/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..72b407ca6a8c2c8e37990de86f36c897aadbc5ef GIT binary patch literal 6148 zcmeH~F>V4u3`K3AK%${cIY$U^fe|7n$OWQ=5{V*8za7`+f7_r%t4LHSqHpB+vtD~g z`-(L-GvEIlH)d-yTf(V!;W9Per%!BFkvY`)jIYz@`Fz6G7<$T>IJZ~)HplOAJww}R zXg3Z$b%K&aKmZ5x5iJ_o2b5y>v*8PY0G50iX+n!?2H8 z0@@gW_R=905twHwG)uik49{}JTjllAAvMd*YxwXw*=s`aI33S#k#62owTgfUJQAoO zea-&=2LEOLe=O3K2#CPHBH)X|`(ck)s@^(zIriEH|A5~Nxsi?~S}`bH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 +

These are all the files

+ +
+ {% for filename in listingfiles %} + + {% if filename.lower().endswith(('.png', '.jpg', '.jpeg')) %} + + {% for jsonfile in jsonfiles %} + {% if filename[0:9] == jsonfile[0:9] %} +
+ {{ jsonfile }} +

{{listofdicts[0]["name"]}}
+ {{listofdicts[0]["email"]}}
+ {{listofdicts[0]["friend"]}}
+ {{listofdicts[0]["content"]}}

+
+ {% endif %} + {% endfor %} + + {% elif filename.lower().endswith(('.mp4')) %} + + {% for jsonfile in jsonfiles %} + {% if filename[0:9] == jsonfile[0:9] %} +
+ {{ jsonfile }} +

{{listofdicts[1]["name"]}}
+ {{listofdicts[1]["email"]}}
+ {{listofdicts[1]["friend"]}}
+ {{listofdicts[1]["content"]}}

+
+ {% endif %} + {% endfor %} + + {% elif filename.lower().endswith(('.mp3')) %} + + {% for jsonfile in jsonfiles %} + {% if filename[0:9] == jsonfile[0:9] %} +
+ {{ jsonfile }} +

{{listofdicts[2]["name"]}}
+ {{listofdicts[2]["email"]}}
+ {{listofdicts[2]["friend"]}}
+ {{listofdicts[2]["content"]}}

+
+ {% endif %} + {% endfor %} + {% endif %} + + {% endfor %} +
+ + {% endblock %} + + diff --git a/templates/layout.html b/templates/layout.html index dd68974..8caf8e6 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -14,6 +14,7 @@
  • Home
  • About
  • Form
  • +
  • All files