diff --git a/contextualise.py b/contextualise.py index e1ba403..ffb65e9 100644 --- a/contextualise.py +++ b/contextualise.py @@ -6,40 +6,95 @@ from wtforms import Form, TextField, TextAreaField, BooleanField, validators, St from forms import ReusableForm from config import Config import json +import os +from time import gmtime, strftime app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") 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/" +listingfiles= [] #fullpaths +listingdirectories = [] #paths +thefile = None #selected file for description +now = strftime("%Y-%m-%d_%H:%M:%S", gmtime()) #description time +positioninarray = 0 #counter + +#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"): + 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)) + + +dict={} #dict for the form entries + @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('/description', methods=['GET', 'POST']) def description(): - form = ReusableForm(request.form) - print (form.errors) - if request.method == 'POST' and form.validate(): - return 'Success!' - return render_template('description.html', form=form) + form = ReusableForm(request.form) +#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('''''') + #ifvid to be added + elif thefile.lower().endswith(('.mp4')): + thefile = Markup(''' ''') + + print (form.errors) + if request.method == 'POST' and form.validate(): + return 'Success!' + # return render_template('description.html', form=form, file=thefile, listingdirectories=listingdirectories, listingfiles=listingfiles) + return render_template('description.html', form=form, file=thefile) -dict={} @app.route('/get-data', methods=['GET', 'POST']) def savepost(): - if request.method=='POST': - dict={'name':request.form['name'],'email':request.form['email'],'friend':request.form['friend'],'content':request.form['content']} - # open with "a" if the file should concatenate content - with open("data_file.json", "w") as write_file: - json.dump(dict, write_file) - return "The JSON file is ready." - else: - return "Error" + if request.method=='POST': + dict={'name':request.form['name'],'email':request.form['email'],'friend':request.form['friend'],'content':request.form['content']} + # 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." + #throw description and next item, wee need to iterate through the files + + else: + return "Error" if __name__ == '__main__': - app.run(debug=True) + app.run(debug=True) diff --git a/contextualiseold.py b/contextualiseold.py new file mode 100644 index 0000000..e1ba403 --- /dev/null +++ b/contextualiseold.py @@ -0,0 +1,45 @@ +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 + +app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") +app.config.from_object(Config) + +@app.route("/") +def home(): + return render_template('home.html') + +@app.route('/about/') +def about(): + return render_template('about.html') + +@app.route('/description', methods=['GET', 'POST']) +def description(): + form = ReusableForm(request.form) + print (form.errors) + if request.method == 'POST' and form.validate(): + return 'Success!' + return render_template('description.html', form=form) + + +dict={} + +@app.route('/get-data', methods=['GET', 'POST']) +def savepost(): + if request.method=='POST': + dict={'name':request.form['name'],'email':request.form['email'],'friend':request.form['friend'],'content':request.form['content']} + # open with "a" if the file should concatenate content + with open("data_file.json", "w") as write_file: + json.dump(dict, write_file) + return "The JSON file is ready." + else: + return "Error" + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/static/files/001/DwySYC4X4AESeRh.jpg b/static/files/001/DwySYC4X4AESeRh.jpg new file mode 100644 index 0000000..e0ecf5d Binary files /dev/null and b/static/files/001/DwySYC4X4AESeRh.jpg differ diff --git a/static/files/002/2019-01-15_21:42:00_data_file.json b/static/files/002/2019-01-15_21:42:00_data_file.json new file mode 100644 index 0000000..92717e4 --- /dev/null +++ b/static/files/002/2019-01-15_21:42:00_data_file.json @@ -0,0 +1 @@ +{"friend": "NY", "name": "mazouni", "email": "pasdechance", "content": "toute la nuit je pense"} \ No newline at end of file diff --git a/static/files/002/YvWL9feSIXyMC2il.mp4 b/static/files/002/YvWL9feSIXyMC2il.mp4 new file mode 100644 index 0000000..46aecc6 Binary files /dev/null and b/static/files/002/YvWL9feSIXyMC2il.mp4 differ diff --git a/static/files/003/Titanic drawing rose meme.-jWcZ2oNAKB4.mp3 b/static/files/003/Titanic drawing rose meme.-jWcZ2oNAKB4.mp3 new file mode 100644 index 0000000..45e52c0 Binary files /dev/null and b/static/files/003/Titanic drawing rose meme.-jWcZ2oNAKB4.mp3 differ diff --git a/templates/description.html b/templates/description.html index c3f99da..bb2fbfa 100644 --- a/templates/description.html +++ b/templates/description.html @@ -2,6 +2,21 @@ {% block content %}

Write something very interesting here.

+ + +

{{ file }}

+ + + + + {% for message in form.name.errors %}
{{ message }}
{% endfor %}