Browse Source

committing so i can work from varia from another laptop

master
Cristina Cochior 4 years ago
parent
commit
9c4f0f82c5
  1. 79
      library_cristina.py
  2. 243
      templates/layout_cristina.html

79
library_cristina.py

@ -0,0 +1,79 @@
from flask import Flask, render_template, Markup, jsonify
import json
import os
from json import dumps
from flask import request # new
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
# SETTING THE VARIABLES
path = "/static/files/"
#move this list to Jinja so it can be placed in layout
#give back clicked value
# librarians = ["Alana", "Gentian", "Laurie", "Matias", "Scott", "Stacy", "Max", "Clara_B", "Michelle", "Clara_J_B", "Karen", "Lumsden_Primary_School", "Aaron", "Leo", "Maria", "Laura", "Honey", "Tender_Center", "wdka", "Naomi", "Cristina", "Julie", "ssw", "cyberspace", "Hannah", "Katarina", "Anastasia", "Kimmy", "Marie","Katherine", "Allison", "Mariana", "Viki", "Alice", "Eric", "hks", "cbk", "Sophie", "Antonio", "Jeremiah", "Angela", "Renee", "Marta", "Katherine", "Anna", "Auryn", "Ashley", "Anne", "Denise", "Eva", "Jonnah", "Kitty", "Masha", "Mia", "Cian", "Senke", "Maud", "Jinnie", "Rubin", "Julia", "Alana", "Gentian", "Laurie", "Matias","Scott", "Stacy"]
librarians = []
files_without_folders = []
with open('static/js/mergedjson.json', 'r', encoding='utf8') as filesandnames:
filetoname_dict = json.load(filesandnames)
#get full list librarians from json (printed later through global variable)
for file in filetoname_dict:
for name in file["librarian"]:
librarians.append(str(name))
librarians = list(dict.fromkeys(librarians))
#this value we should get from template
librarianselected = "Ruben"
#go from librarian name to file
for file in filetoname_dict:
# if librarianselected in file["librarian"]:
thedebris = file["debrisname"]
#apply regex to the debris
thedebris = os.path.basename(thedebris)
files_without_folders.append(str(thedebris))
# print(str(librarianselected)+" contributed with the following debris : "+str(thedebris))
#this value we should get from template
fileselected = filetoname_dict[1]["debrisname"]
#go from file name to librarian name
for file in filetoname_dict:
if fileselected in file["debrisname"]:
thelibrarian = file["librarian"]
print("librarians for "+ str(fileselected)+" are: " + str(thelibrarian))
print("---------------------------------------------------")
print(librarians)
@app.route("/", methods=['POST', 'GET']) # new
def home():
if request.args:
# We have our query string nicely serialized as a Python dictionary
args = request.args
# We'll create a string to display the parameters & values
serialized = ", ".join(f"{k}: {v}" for k, v in request.args.items())
# Display the query string to the client in a different format
# return f"(Query) {serialized}", 200
urllibrarian=request.args.getlist('librarian') # new
urlmethod=request.args.getlist('method') # new
for a in urllibrarian:
print('urllibrarian is: '+ a)
for b in urlmethod:
print('urlmethod is: ' + b)
return render_template('layout.html', urllibrarian=urllibrarian, urlmethod=urlmethod, filetoname_dict=filetoname_dict, librarians=librarians, files_without_folders = files_without_folders) # new
@app.route('/about/')
def about():
return render_template('about.html')
@app.route('/exchange')
def exchange():
return render_template('exchange.html')

243
templates/layout_cristina.html

@ -0,0 +1,243 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Library</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<!-- <script type="text/javascript">
$(document).ready(function() {
$(".librarian-names").click(function(event){
var thename = $(this).text();
$(".name-elements").empty();
$.getJSON('{{ url_for('static', filename='js/mergedjson.json') }}', function(test) {
// iterate in test[i].librarian to find where the name is present to get the test[i].debris that goes with it
var alldocs = [];
for (var i = 0; i < test.length; ++i) {
var item = test[i];
if(item.librarian.includes(thename)){
ledocument = item.debrispath;
lelibrarian = item.librarian;
//put ledocument into li and nest inside ul
var extension = ledocument.replace(/^.*\./, '');
console.log(ledocument);
if ((extension=="jpg") || (extension=="jpeg") || (extension=="png") || (extension=="gif") || (extension=="tiff")) {
$(".name-elements").append("<li><img class='listed-images' src='/files/"+ledocument+"'>Librarians: "+lelibrarian+"</li>");
}
else if (extension=="pdf") {
$(".name-elements").append("<li><embed class='listed-pdf' src='files/"+ledocument+"'/>Librarians: "+lelibrarian+"</li>");
}
else if (extension=="epub") {
$(".name-elements").append("<li>"+ledocument+lelibrarian+"</li>");
}
else if ((extension=="mp3") || (extension=="wav") || (extension=="m4a")) {
$(".name-elements").append("<li><audio class='listed-audio' controls><source src='files/"+ledocument+"'></audio>Librarians: "+lelibrarian+"</li>");
}
else if ((extension=="mov") || (extension=="mp4")) {
$(".name-elements").append("<li><video class='listed-videos' controls><source src='files/"+ledocument+"'></video>Librarians: "+lelibrarian+"</li>");
}
else if ((extension=="odt") || (extension=="docx")) {
// something for odt and docx
$(".name-elements").append("<li>"+ledocument+lelibrarian+"</li>");
};
};
};
});
});
$(".file-names").click(function(event){
var thefile = $(this).text();
$.getJSON('{{ url_for('static', filename='js/mergedjson.json') }}', function(test) {
$(".name-elements").empty();
// iterate in test[i].librarian to find where the name is present
//to get the test[i].debris that goes with it
var allpeeps = [];
var category = null;
for (var i = 0; i < test.length; ++i) {
var item = test[i];
if(item.debrisname.includes(thefile)){
ledocument = item.debrispath;
// allpeeps.push(ledocument);
var extension = ledocument.replace(/^.*\./, '');
console.log(ledocument);
if ((extension=="jpg") || (extension=="jpeg") || (extension=="png") || (extension=="gif") || (extension=="tiff")) {
$(".name-elements").append("<li><img class='listed-images' src='/files/"+ledocument+"'></li>");
}
else if (extension=="pdf") {
$(".name-elements").append("<li><object class='listed-pdf' data='files/"+ledocument+"'/></li>");
}
else if (extension=="epub") {
$(".name-elements").append("<li>"+ledocument+"</li>");
}
else if ((extension=="mp3") || (extension=="wav") || (extension=="m4a")) {
$(".name-elements").append("<li><audio class='listed-audio' controls><source src='files/"+ledocument+"'></audio></li>");
}
else if ((extension=="mov") || (extension=="mp4")) {
$(".name-elements").append("<li><video class='listed-videos' controls><source src='files/"+ledocument+"'></video></li>");
}
else if ((extension=="odt") || (extension=="docx")) {
// something for odt and docx
$(".name-elements").append("<li>"+ledocument+"</li>");
};
};
category = item.method;
};
});
});
});
</script> -->
</head>
<body>
<div class="nav-top">
<ul>
<li><span class="nav-button" style="text-align: left;" id="bought">BOUGHT</span></li>
<li><span class="nav-button" style="text-align: center;" id="stolen">STOLEN</span>
<li><span class="nav-button" style="text-align: right;" id="repurposed">REPURPOSED</span>
</ul>
</div>
<div class="main">
<div class="main-column-left">
<div id="listofpeople">
{% for librarian in librarians %}
<!-- <span class="librarian-names" id={{libid}}>{{librarian}}</span> -->
<span class="librarian-names" id={{librarian}}>{{librarian}}</span>
{% endfor %}
</div>
<br>
<div class="file-names-container">
{% for querylibrarian in urllibrarian %}
{% for file in filetoname_dict %}
{% for item in file['librarian'] %}
{% if item == querylibrarian and urlmethod != ['']%}
{% set show_file = file['debrisname'] %}
<span class="file-names" id="{{show_file}}">{{show_file}}</span>
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
</div>
</div>
<div class="main-column-right">
<a href="{{ url_for('static', filename='realjson.json') }}">test link</a>
<ul class="name-elements">
<p>hello world</p>
</ul>
{% block content %}
{% endblock content %}
</div>
</div>
<div class="nav-bottom">
<ul>
<li><span class="nav-button" style="text-align: left;" id="copied">COPIED</span></li>
<li><span class="nav-button" style="text-align: center;" id="found">FOUND</span></li>
<li><span class="nav-button" style="text-align: right;" id="gift">GIFT</span></li>
</ul>
</div>
<script type="text/javascript">
$(document).ready(function() {
var address = '/?';
$(".librarian-names").click(function(event){
var theid = $(this).attr('id');
if($(this).hasClass('clicked')==false){
address = address + "librarian=" + theid;
// location.href = address;
$(this).addClass('clicked');
$(".librarian-names").addClass('selected');
alert(address);
} else {
$(this).removeClass('clicked');
$(".librarian-names").removeClass('selected');
address = address - ("librarian=" + theid);
alert(address);
};
// var thename = $(this).text();
// $.getJSON('{{ url_for('static', filename='js/mergedjson.json') }}', function(test) {
// var alldocs = [];
// for (var i = 0; i < test.length; ++i) {
// var item = test[i];
// if(item.librarian.includes(thename)){
// ledocument = item.debrispath;
// lelibrarian = item.librarian;
// };
// }
// });
});
$(".nav-button").click(function(event){
var navid = $(this).attr('id');
if($(this).hasClass('clicked')==false){
address = address + "&method=" + navid;
$(this).addClass('clicked');
alert(address);
} else {
$(this).removeClass('clicked');
address = address - ("method=" + navid);
alert(address);
};
});
$(".file-names").click(function(event){
var thefile = $(this).text();
$.getJSON('{{ url_for('static', filename='js/mergedjson.json') }}', function(test) {
$(".name-elements").empty();
// iterate in test[i].librarian to find where the name is present
//to get the test[i].debris that goes with it
var allpeeps = [];
var category = null;
for (var i = 0; i < test.length; ++i) {
var item = test[i];
if(item.debrisname.includes(thefile)){
ledocument = item.debrispath;
// allpeeps.push(ledocument);
var extension = ledocument.replace(/^.*\./, '');
console.log(ledocument);
if ((extension=="jpg") || (extension=="jpeg") || (extension=="png") || (extension=="gif") || (extension=="tiff")) {
$(".name-elements").append("<li><img class='listed-images' src='/files/"+ledocument+"'></li>");
}
else if (extension=="pdf") {
$(".name-elements").append("<li><object class='listed-pdf' data='files/"+ledocument+"'/></li>");
}
else if (extension=="epub") {
$(".name-elements").append("<li>"+ledocument+"</li>");
}
else if ((extension=="mp3") || (extension=="wav") || (extension=="m4a")) {
$(".name-elements").append("<li><audio class='listed-audio' controls><source src='files/"+ledocument+"'></audio></li>");
}
else if ((extension=="mov") || (extension=="mp4")) {
$(".name-elements").append("<li><video class='listed-videos' controls><source src='files/"+ledocument+"'></video></li>");
}
else if ((extension=="odt") || (extension=="docx")) {
// something for odt and docx
$(".name-elements").append("<li>"+ledocument+"</li>");
};
};
category = item.method;
};
});
});
});
</script>
</body>
</html>
Loading…
Cancel
Save