Browse Source

starting point

master
Cristina Cochior 6 years ago
parent
commit
f393e03a8e
  1. 2
      README.md
  2. BIN
      __pycache__/config.cpython-36.pyc
  3. BIN
      __pycache__/contextualise.cpython-36.pyc
  4. BIN
      __pycache__/forms.cpython-36.pyc
  5. BIN
      __pycache__/json_actions.cpython-36.pyc
  6. BIN
      __pycache__/startform.cpython-36.pyc
  7. 4
      config.py
  8. 124
      contextualise.py
  9. 45
      contextualiseold.py
  10. 1
      data_file.json
  11. 12
      forms.py
  12. 38
      json_actions.py
  13. 34
      startform.py
  14. BIN
      static/.DS_Store
  15. 4
      static/css/main.css
  16. BIN
      static/files/.DS_Store
  17. BIN
      static/files/001/.DS_Store
  18. 1
      static/files/001/2019-01-22_08:49:43_data_file.json
  19. BIN
      static/files/001/DwySYC4X4AESeRh.jpg
  20. BIN
      static/files/002/.DS_Store
  21. 1
      static/files/002/2019-01-20_17:47:03_data_file.json
  22. 1
      static/files/002/2019-01-22_09:09:09_data_file.json
  23. BIN
      static/files/002/YvWL9feSIXyMC2il.mp4
  24. BIN
      static/files/003/.DS_Store
  25. 1
      static/files/003/2019-01-23_10:38:26_data_file.json
  26. BIN
      static/files/003/Titanic drawing rose meme.-jWcZ2oNAKB4.mp3
  27. BIN
      templates/.DS_Store
  28. 7
      templates/about.html
  29. 75
      templates/all.html
  30. 35
      templates/description.html
  31. 7
      templates/home.html
  32. 27
      templates/layout.html

2
README.md

@ -1,2 +1,2 @@
# Pushing Scores # Pushing Scores
## Initial experiments for the Pushing Scores project

BIN
__pycache__/config.cpython-36.pyc

Binary file not shown.

BIN
__pycache__/contextualise.cpython-36.pyc

Binary file not shown.

BIN
__pycache__/forms.cpython-36.pyc

Binary file not shown.

BIN
__pycache__/json_actions.cpython-36.pyc

Binary file not shown.

BIN
__pycache__/startform.cpython-36.pyc

Binary file not shown.

4
config.py

@ -0,0 +1,4 @@
import os
class Config(object):
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'

124
contextualise.py

@ -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

@ -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

@ -0,0 +1 @@
{"name": "as", "email": "asd", "friend": "Y", "content": "asd"}

12
forms.py

@ -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

@ -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

@ -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

Binary file not shown.

4
static/css/main.css

@ -0,0 +1,4 @@
body{
background: lavender;
color:blue;
}

BIN
static/files/.DS_Store

Binary file not shown.

BIN
static/files/001/.DS_Store

Binary file not shown.

1
static/files/001/2019-01-22_08:49:43_data_file.json

@ -0,0 +1 @@
{"id":"001","name": "Canonimouse", "email": "yes@mail.com", "friend": "Y", "content": "The contestants are embracing."}

BIN
static/files/001/DwySYC4X4AESeRh.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
static/files/002/.DS_Store

Binary file not shown.

1
static/files/002/2019-01-20_17:47:03_data_file.json

@ -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

@ -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

Binary file not shown.

BIN
static/files/003/.DS_Store

Binary file not shown.

1
static/files/003/2019-01-23_10:38:26_data_file.json

@ -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

Binary file not shown.

BIN
templates/.DS_Store

Binary file not shown.

7
templates/about.html

@ -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

@ -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

@ -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

@ -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

@ -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…
Cancel
Save