starting point
This commit is contained in:
parent
d12cf209e1
commit
f393e03a8e
@ -1,2 +1,2 @@
|
||||
# PushingScores
|
||||
|
||||
# Pushing Scores
|
||||
## Initial experiments for the Pushing Scores project
|
||||
|
BIN
__pycache__/config.cpython-36.pyc
Normal file
BIN
__pycache__/config.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/contextualise.cpython-36.pyc
Normal file
BIN
__pycache__/contextualise.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/forms.cpython-36.pyc
Normal file
BIN
__pycache__/forms.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/json_actions.cpython-36.pyc
Normal file
BIN
__pycache__/json_actions.cpython-36.pyc
Normal file
Binary file not shown.
BIN
__pycache__/startform.cpython-36.pyc
Normal file
BIN
__pycache__/startform.cpython-36.pyc
Normal file
Binary file not shown.
4
config.py
Normal file
4
config.py
Normal file
@ -0,0 +1,4 @@
|
||||
import os
|
||||
|
||||
class Config(object):
|
||||
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'
|
124
contextualise.py
Normal file
124
contextualise.py
Normal file
@ -0,0 +1,124 @@
|
||||
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', methods=['GET', 'POST'])
|
||||
def description():
|
||||
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('<img src="'+thefile+'" />')
|
||||
|
||||
#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> ''')
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@app.route('/get-data', methods=['GET', 'POST'])
|
||||
def savepost():
|
||||
if request.method=='POST':
|
||||
dict={'id':listingdirectories[positioninarray][13:],'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)
|
45
contextualiseold.py
Normal file
45
contextualiseold.py
Normal file
@ -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)
|
1
data_file.json
Normal file
1
data_file.json
Normal file
@ -0,0 +1 @@
|
||||
{"name": "as", "email": "asd", "friend": "Y", "content": "asd"}
|
12
forms.py
Normal file
12
forms.py
Normal file
@ -0,0 +1,12 @@
|
||||
from flask_wtf import Form
|
||||
from wtforms import TextField, IntegerField, TextAreaField, SubmitField, RadioField, SelectField, StringField
|
||||
|
||||
from wtforms import validators, ValidationError
|
||||
|
||||
class ReusableForm(Form):
|
||||
name = TextField('Name:', [validators.Required('Please enter your name.')])
|
||||
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')
|
||||
|
38
json_actions.py
Normal file
38
json_actions.py
Normal file
@ -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))
|
||||
|
34
startform.py
Normal file
34
startform.py
Normal file
@ -0,0 +1,34 @@
|
||||
from wtforms import Form, TextField, BooleanField, StringField, SubmitField, validators
|
||||
from flask import Flask, url_for, render_template, Markup, redirect, request, flash
|
||||
from flask import session as login_session
|
||||
from forms import ReusableForm
|
||||
from config import Config
|
||||
# import json_actions
|
||||
import json
|
||||
|
||||
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
|
||||
app.config.from_object(Config)
|
||||
|
||||
|
||||
@app.route('/', 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-prev.html', form=form)
|
||||
if __name__ == '__main__':
|
||||
app.run(debug = True)
|
||||
|
||||
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"
|
BIN
static/.DS_Store
vendored
Normal file
BIN
static/.DS_Store
vendored
Normal file
Binary file not shown.
4
static/css/main.css
Normal file
4
static/css/main.css
Normal file
@ -0,0 +1,4 @@
|
||||
body{
|
||||
background: lavender;
|
||||
color:blue;
|
||||
}
|
BIN
static/files/.DS_Store
vendored
Normal file
BIN
static/files/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
static/files/001/.DS_Store
vendored
Normal file
BIN
static/files/001/.DS_Store
vendored
Normal file
Binary file not shown.
1
static/files/001/2019-01-22_08:49:43_data_file.json
Normal file
1
static/files/001/2019-01-22_08:49:43_data_file.json
Normal file
@ -0,0 +1 @@
|
||||
{"id":"001","name": "Canonimouse", "email": "yes@mail.com", "friend": "Y", "content": "The contestants are embracing."}
|
BIN
static/files/001/DwySYC4X4AESeRh.jpg
Normal file
BIN
static/files/001/DwySYC4X4AESeRh.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
BIN
static/files/002/.DS_Store
vendored
Normal file
BIN
static/files/002/.DS_Store
vendored
Normal file
Binary file not shown.
1
static/files/002/2019-01-20_17:47:03_data_file.json
Normal file
1
static/files/002/2019-01-20_17:47:03_data_file.json
Normal file
@ -0,0 +1 @@
|
||||
{"id":"002","name": "XYZ", "email": "yesihave@one.com", "friend": "Y", "content": "Sure"}
|
1
static/files/002/2019-01-22_09:09:09_data_file.json
Normal file
1
static/files/002/2019-01-22_09:09:09_data_file.json
Normal file
@ -0,0 +1 @@
|
||||
{"id":"002","name": "Anonymousse", "email": "bettermail@mail.com", "friend": "Y", "content": "A beach in an Arab-speaking place."}
|
BIN
static/files/002/YvWL9feSIXyMC2il.mp4
Normal file
BIN
static/files/002/YvWL9feSIXyMC2il.mp4
Normal file
Binary file not shown.
BIN
static/files/003/.DS_Store
vendored
Normal file
BIN
static/files/003/.DS_Store
vendored
Normal file
Binary file not shown.
1
static/files/003/2019-01-23_10:38:26_data_file.json
Normal file
1
static/files/003/2019-01-23_10:38:26_data_file.json
Normal file
@ -0,0 +1 @@
|
||||
{"id": "003", "name": "Yes", "email": "sure@whynot.com", "friend": "Y", "content": "A sound file."}
|
BIN
static/files/003/Titanic drawing rose meme.-jWcZ2oNAKB4.mp3
Normal file
BIN
static/files/003/Titanic drawing rose meme.-jWcZ2oNAKB4.mp3
Normal file
Binary file not shown.
BIN
templates/.DS_Store
vendored
Normal file
BIN
templates/.DS_Store
vendored
Normal file
Binary file not shown.
7
templates/about.html
Normal file
7
templates/about.html
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="about">
|
||||
<h1>About me</h1>
|
||||
<p>This is a portfolio site about anything that can be put in a portfolio.</p>
|
||||
</div>
|
||||
{% endblock %}
|
75
templates/all.html
Normal file
75
templates/all.html
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="all">
|
||||
<h1>These are all the files</h1>
|
||||
{{ listingfiles }} <br>
|
||||
{{ jsonfiles }} <br>
|
||||
{{ listofdicts }} <br>
|
||||
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
|
||||
{% for filename in listingfiles %}
|
||||
{% if filename.lower().endswith(('.png', '.jpg', '.jpeg')) %}
|
||||
<img class="img-responsive" src=" ../{{ filename }}">
|
||||
{% for jsonfile in jsonfiles %}
|
||||
{% if filename[0:9] == jsonfile[0:9] %}
|
||||
<div class="descrip">
|
||||
{{ jsonfile }}
|
||||
{% for dict in listofdicts %}
|
||||
{% if jsonfile[6:9]==dict["id"] %}
|
||||
<p>{% for key, value in dict.items() %}
|
||||
{{key}}: {{value}}<br>
|
||||
{% endfor %}</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% break %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% elif filename.lower().endswith(('.mp4')) %}
|
||||
<video width="320" height="240" controls><source src="../{{filename}}" type="video/mp4">
|
||||
Your browser does not support the video tag.
|
||||
</video>
|
||||
{% for jsonfile in jsonfiles %}
|
||||
{% if filename[0:9] == jsonfile[0:9] %}
|
||||
<div class="descrip">
|
||||
{{ jsonfile }}
|
||||
{% for dict in listofdicts %}
|
||||
{% if jsonfile[6:9]==dict["id"] %}
|
||||
<p>{% for key, value in dict.items() %}
|
||||
{{key}}: {{value}}<br>
|
||||
{% endfor %}</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% break %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% elif filename.lower().endswith(('.mp3')) %}
|
||||
<audio controls><source src="../{{filename}}" type="audio/mpeg">
|
||||
Your browser does not support the audio tag.
|
||||
</audio>
|
||||
{% for jsonfile in jsonfiles %}
|
||||
{% if filename[0:9] == jsonfile[0:9]%}
|
||||
<div class="descrip">
|
||||
{{ jsonfile }}
|
||||
{% for dict in listofdicts %}
|
||||
{% if jsonfile[6:9]==dict["id"] %}
|
||||
<p>{% for key, value in dict.items() %}
|
||||
{{key}}: {{value}}<br>
|
||||
{% endfor %}</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% break %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
35
templates/description.html
Normal file
35
templates/description.html
Normal file
@ -0,0 +1,35 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="description">
|
||||
<h2 style = "text-align: center;">Write something very interesting here.</h2>
|
||||
|
||||
<!--passing files-->
|
||||
<p>{{ file }}</p>
|
||||
|
||||
<!-- <img src="{{ url_for('static', filename='/files/001/DwySYC4X4AESeRh.jpg') }}">
|
||||
-->
|
||||
<!--passing an array-->
|
||||
<!-- {% for v in listingdirectories %}
|
||||
<div>{{ v }}</div>
|
||||
{% endfor %}
|
||||
{% for f in listingfiles %}
|
||||
<div>{{ f }}</div>
|
||||
{% endfor %}
|
||||
-->
|
||||
|
||||
{% for message in form.name.errors %}
|
||||
<div>{{ message }}</div>
|
||||
{% endfor %}
|
||||
|
||||
<form method="POST" action="/get-data">
|
||||
<fieldset>
|
||||
{{ form.hidden_tag() }}
|
||||
<div>{{ form.name.label }} {{ form.name }}</div>
|
||||
<div>{{ form.email.label }} {{ form.email }}</div>
|
||||
<div>{{ form.friend.label }} {{ form.friend }}</div>
|
||||
<div>{{ form.content.label }} {{ form.content }}</div>
|
||||
<div>{{ form.submit }}</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
7
templates/home.html
Normal file
7
templates/home.html
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="home">
|
||||
<h1>THIS IS THE HOME PAGE</h1>
|
||||
<p>This website was built with Python via the Flask framework.</p>
|
||||
</div>
|
||||
{% endblock %}
|
27
templates/layout.html
Normal file
27
templates/layout.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>PARTOUT TITRE PARTOUT</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="container">
|
||||
<h1 class="logo">SUPERB</h1>
|
||||
<strong><nav>
|
||||
<ul class="menu">
|
||||
<li><a href="{{ url_for('home') }}">Home</a></li>
|
||||
<li><a href="{{ url_for('about') }}">About</a></li>
|
||||
<li><a href="{{ url_for('description') }}">Form</a></li>
|
||||
<li><a href="{{ url_for('all') }}">All files</a></li>
|
||||
</ul>
|
||||
</nav></strong>
|
||||
</div>
|
||||
</header>
|
||||
<div class="container">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user