You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.3 KiB
103 lines
3.3 KiB
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
|
|
from time import gmtime, strftime
|
|
from pprint import pprint
|
|
|
|
|
|
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
|
|
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/"
|
|
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 = 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") 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
|
|
|
|
dict = {} #dict for the form entries
|
|
|
|
@app.route("/")
|
|
def home():
|
|
return render_template('home.html')
|
|
|
|
@app.route('/about/')
|
|
def about():
|
|
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)
|
|
|
|
|
|
@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('<img src="'+thefile+'" /> <br />')
|
|
|
|
#if sound
|
|
elif thefile.lower().endswith(('.mp3')):
|
|
thefile = Markup('''<audio controls>
|
|
<source src="'''+thefile+'''" type="audio/mpeg">
|
|
Your browser does not support the audio tag.
|
|
</audio>''')
|
|
#ifvid to be added
|
|
elif thefile.lower().endswith(('.mp4')):
|
|
thefile = Markup(''' <video width="320" height="240" controls>
|
|
<source src="'''+thefile+'''" type="video/mp4">
|
|
Your browser does not support the video tag.
|
|
</video> ''')
|
|
|
|
|
|
return render_template('description.html', file=thefile)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True)
|