rsqlite UPDATE

master
Alex 6 years ago
parent e1d966924d
commit c4583482b5

BIN
.DS_Store vendored

Binary file not shown.

@ -16,7 +16,7 @@ app = Flask(__name__)
app.config['SECRET_KEY'] = 'super secret key' app.config['SECRET_KEY'] = 'super secret key'
#app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/mydatabase.db' #app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/mydatabase.db'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'mydatabase.db') app.config['SQLALCHEMY_DATABASE_URI'] = 'rqlite+pyrqlite://localhost:4001/'
db = SQLAlchemy(app) db = SQLAlchemy(app)
app.config.from_object(__name__) app.config.from_object(__name__)

@ -23,6 +23,8 @@ class Book(db.Model):
backref=db.backref('books', lazy=True)) backref=db.backref('books', lazy=True))
tags = db.relationship('Tag', secondary=tags, lazy='subquery', tags = db.relationship('Tag', secondary=tags, lazy='subquery',
backref=db.backref('books', lazy=True)) backref=db.backref('books', lazy=True))
scapeX = db.Column(db.Numeric(10,2))
scapeY = db.Column(db.Numeric(10,2))
def __init__(self, title, file, cover, fileformat, category): def __init__(self, title, file, cover, fileformat, category):
self.title = title self.title = title
@ -30,6 +32,8 @@ class Book(db.Model):
self.cover = cover self.cover = cover
self.fileformat = fileformat self.fileformat = fileformat
self.category = category self.category = category
self.scapeX = 0
self.scapeY = 0
def __repr__(self): def __repr__(self):

@ -38,14 +38,48 @@
<script src="https://code.jquery.com/jquery-2.1.4.js"></script> <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="{{ url_for("static", filename="js/app.js") }}"></script> <script src="{{ url_for("static", filename="js/app.js") }}"></script>
<script> <script>
$( ".no_cover" ).each(function() { $( ".no_cover" ).each(function() {
var randomColor = '#'+ ('000000' + Math.floor(Math.random()*16777215).toString(16)).slice(-6); var string = $(this).children("p").html()
var randomColor = colorHash(string).rgb
$(this).css({ $(this).css({
'background-color' : randomColor, 'background-color' : randomColor,
}); });
} }
) )
function colorHash(inputString){
var sum = 0;
for(var i in inputString){
sum += inputString.charCodeAt(i);
}
r = ~~(('0.'+Math.sin(sum+1).toString().substr(6))*256);
g = ~~(('0.'+Math.sin(sum+2).toString().substr(6))*256);
b = ~~(('0.'+Math.sin(sum+3).toString().substr(6))*256);
var rgb = "rgb("+r+", "+g+", "+b+")";
var hex = "#";
hex += ("00" + r.toString(16)).substr(-2,2).toUpperCase();
hex += ("00" + g.toString(18)).substr(-2,2).toUpperCase();
hex += ("00" + b.toString(20)).substr(-2,2).toUpperCase();
return {
r: r
,g: g
,b: b
,rgb: rgb
,hex: hex
};
}
</script> </script>
</body> </body>
</html> </html>

@ -11,7 +11,9 @@
{{ form.csrf_token }} {{ form.csrf_token }}
<div class="form-group"><h1 class="header">{{ form.title.label }} {{ form.title(size=20, class="form-control") }}</h1></div> <div class="form-group"><h1 class="header">{{ form.title.label }} {{ form.title(size=20, class="form-control") }}</h1></div>
<object class="no_cover" data="../../static/img/default_cover.png" type="image/png" width="150">
<img src="../../uploads/cover/{{ book.cover }}" width="200"> <img src="../../uploads/cover/{{ book.cover }}" width="200">
</object>
<br> <br> <br> <br>
<div data-toggle="fieldset" id="phone-fieldset"> <div data-toggle="fieldset" id="phone-fieldset">
{{ form.author.label }} <button type="button" data-toggle="fieldset-add-row" {{ form.author.label }} <button type="button" data-toggle="fieldset-add-row"

@ -0,0 +1,145 @@
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"/>
<style>
body .ui-selecting { border:2px solid yellow; }
body .ui-selected {border:2px solid black;}
body {overflow: scroll;}
#scape_container{overflow: scroll;width: 100%; height:100vh;}
</style>
</head>
<body>
<div id ="scape_container">
{% for book in books|sort(attribute='title', reverse = False) %}
<div class = "drag" id = "{{ book.id }}" style="position: absolute;width:40px;height:auto; top:{{ book.scapeY }}px; left:{{ book.scapeX }}px;">
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" style="width:100%;height:auto;">
<p >{{ book.title }}</p>
<img src="../uploads/cover/{{ book.cover }}" width="80">
</object>
<p style="font-size:7px;"><a href="books/{{ book.id }}">{{ book.title }}</a></p>
</div>
{% endfor %}
<div id="random" style="padding:2px; margin: 0;position: absolute;width:120px;height:20px;background-color:yellow;z-index:999999999999999999900000000000000;cursor:pointer;">
<p style="padding:0; margin: 0;position: absolute; ">random position</p>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="{{ url_for("static", filename="js/app.js") }}"></script>
<script>
$( ".no_cover" ).each(function() {
var string = $(this).children("p").html()
var randomColor = colorHash(string).rgb
$(this).css({
'background-color' : randomColor,
});
}
)
function colorHash(inputString){
var sum = 0;
for(var i in inputString){
sum += inputString.charCodeAt(i);
}
r = ~~(('0.'+Math.sin(sum+1).toString().substr(6))*256);
g = ~~(('0.'+Math.sin(sum+2).toString().substr(6))*256);
b = ~~(('0.'+Math.sin(sum+3).toString().substr(6))*256);
var rgb = "rgb("+r+", "+g+", "+b+")";
var hex = "#";
hex += ("00" + r.toString(16)).substr(-2,2).toUpperCase();
hex += ("00" + g.toString(18)).substr(-2,2).toUpperCase();
hex += ("00" + b.toString(20)).substr(-2,2).toUpperCase();
return {
r: r
,g: g
,b: b
,rgb: rgb
,hex: hex
};
}
</script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( ".drag" ).draggable({ stack: ".drag",
stop: function(){
var offset = $(this).offset();
var id = $(this).attr('id');
var xPos = offset.left;
var yPos = offset.top;
console.log(xPos);
console.log(yPos);
var postForm = { //Fetch form data
'id' : id,
'x' : xPos, //Store name fields value,
'y' : yPos
};
$.ajax({ //Process the form using $.ajax()
type : 'POST', //Method type
url : '/scape', //Your form processing file URL
data : postForm, //Forms name
dataType : 'json'
});
} });
} );
$( function() {
$( ".drag" ).resizable({aspectRatio: true});
} );
/* $( function() {
$( "body" ).selectable();
} );*/
$( "#random" ).click(function() {
console.log("hallo");
$( ".drag" ).each(function() {
var id = $(this).attr('id');
var postForm = { //Fetch form data
'id' : id,
'x' : Math.floor(Math.random() * window.innerWidth) , //Store name fields value,
'y' : Math.floor(Math.random() * window.innerHeight)
};
$( this ).css("top", postForm['y']);
$( this ).css("left", postForm['x']);
$.ajax({ //Process the form using $.ajax()
type : 'POST', //Method type
url : '/scape', //Your form processing file URL
data : postForm, //Forms name
dataType : 'json'
});
});
});
</script>
</body>
</html>

@ -4,9 +4,10 @@
<div class="container"> <div class="container">
<h1 class="header">{{ book.title }}</h1> <h1 class="header">{{ book.title }}</h1>
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="150">
<p hidden="True">{{ book.title }}</p>
<img src="../uploads/cover/{{ book.cover }}" width="200"> <img src="../uploads/cover/{{ book.cover }}" width="200">
</object>
<p>Author(s): <ul>{% for author in book.authors %} <p>Author(s): <ul>{% for author in book.authors %}
<li><a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a> </li> <li><a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a> </li>

@ -15,9 +15,9 @@
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<table class="library_table" style="width:100%"> <table class="library_table" id="table" style="width:100%">
<tr> <tr id="header">
<th>Cover</th> <th>Cover</th>
<th>Title</th> <th>Title</th>
<th>Author</th> <th>Author</th>
<th>Filetype</th> <th>Filetype</th>
@ -27,6 +27,7 @@
<tr> <tr>
<td> <td>
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="65"> <object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="65">
<p hidden="True">{{ book.title }}</p>
<img src="../uploads/cover/{{ book.cover }}" width="80"> <img src="../uploads/cover/{{ book.cover }}" width="80">
</object> </object>
</td> </td>

@ -0,0 +1,31 @@
{% extends 'base.html' %}
{% block main %}
<div class="container">
<h1 class="page-header">All Books</h1>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="alert alert-success">
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endwith %}
{% for book in books|sort(attribute='title', reverse = False) %}
<a href="books/{{ book.id }}">
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="105">
<img src="../uploads/cover/{{ book.cover }}" width="80">
</object>
{{ book.title }}</a>
{% endfor %}
</div>
{% endblock %}

@ -7,7 +7,7 @@ This file creates your application.
from app import app, db from app import app, db
from flask import Flask, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort from flask import Flask, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort
import json
from app.forms import UserForm, UserForm_Edit from app.forms import UserForm, UserForm_Edit
from app.models import Book, BookSchema, Author, AuthorSchema from app.models import Book, BookSchema, Author, AuthorSchema
from app.cover import get_cover from app.cover import get_cover
@ -59,6 +59,25 @@ def show_books():
books = db.session.query(Book).all() # or you could have used User.query.all() books = db.session.query(Book).all() # or you could have used User.query.all()
return render_template('show_books.html', books=books) return render_template('show_books.html', books=books)
@app.route('/scape', methods=['POST', 'GET'])
def scape():
if request.method == 'POST':
data = request.form
book = Book.query.get(data['id'])
print(book.scapeX)
book.scapeX = data['x']
book.scapeY = data['y']
db.session.commit()
books = db.session.query(Book).all() # or you could have used User.query.all()
return render_template('scape.html', books=books)
@app.route('/books_grid')
def show_books_grid():
books = db.session.query(Book).all() # or you could have used User.query.all()
return render_template('show_books_grid.html', books=books)
@app.route('/books/<int:id>') @app.route('/books/<int:id>')
def show_book_by_id(id): def show_book_by_id(id):
book = Book.query.get(id) book = Book.query.get(id)
@ -73,7 +92,7 @@ def remove_book_by_id(id):
book_to_edit = Book.query.filter_by(id=id).first() book_to_edit = Book.query.filter_by(id=id).first()
title = book_to_edit.title title = book_to_edit.title
Book.query.filter_by(id=id).delete() Book.query.filter_by(id=id).delete()
author_table = Author.query.filter_by(user_id=book_to_edit.id).delete() #author_table = Author.query.filter_by(books_id=book_to_edit.id).delete()
db.session.commit() db.session.commit()
flash("%s deleted from library" % (title)) flash("%s deleted from library" % (title))
return redirect(url_for('show_books')) return redirect(url_for('show_books'))

@ -29,8 +29,6 @@ The Ultimate Guide to the Vi and Ex Text Editors,Hewlett-Packard,Technical,,,0,,
Getting Gread Sounds: The Microphone Book,Tom Lubin,Technical,,,0,, Getting Gread Sounds: The Microphone Book,Tom Lubin,Technical,,,0,,
How to Think Like a Computer Scientist,"Allen B. Downey, Jeffrey Elkner, Chris Meyers",Technical,pdf,1,1,LibGen, How to Think Like a Computer Scientist,"Allen B. Downey, Jeffrey Elkner, Chris Meyers",Technical,pdf,1,1,LibGen,
Python Pocket Reference,Mark Lutz,Technical,pdf,,1,LibGen, Python Pocket Reference,Mark Lutz,Technical,pdf,,1,LibGen,
Things That Talk,Lorraine Daston (Editor),Science/History,,,,,
The Social Construction of What?,Ian Hacking,Science/History,pdf,1,1,LibGen,
Instruments and the Imagination,Hankins & Silverman,Science/History,,,,, Instruments and the Imagination,Hankins & Silverman,Science/History,,,,,
"Mind, Machines and Human Consciousness",Robert Nadeau,Science/History,,,,, "Mind, Machines and Human Consciousness",Robert Nadeau,Science/History,,,,,
The Psychopath Test,Jon Ronson,Science/History,pdf,1,1,LibGen, The Psychopath Test,Jon Ronson,Science/History,pdf,1,1,LibGen,
@ -76,7 +74,6 @@ Loving Big Brother: Surveillance Culture and Performance Space,John McGrath,Medi
Selections from Cultural Writings,Antonio Gramsci,Media studies,,,0,, Selections from Cultural Writings,Antonio Gramsci,Media studies,,,0,,
Dark Money: The Hidden History of the Billionairs behind the Rise of the Radical Right,Jane Mayer,Media studies,EPUB,,1,Libgen, Dark Money: The Hidden History of the Billionairs behind the Rise of the Radical Right,Jane Mayer,Media studies,EPUB,,1,Libgen,
Walter Benjamin for beginners,"Howard Caygill, Alex Coles, Richard Appignanesi",Media studies,,,0,, Walter Benjamin for beginners,"Howard Caygill, Alex Coles, Richard Appignanesi",Media studies,,,0,,
What is Situationism? A Reader,Stewart Home (ed.),Media studies,pdf,1,1,MOTW,
Cyburbia,James Harkin,Media studies,,,0,, Cyburbia,James Harkin,Media studies,,,0,,
Mondothèque::a radiated book/un livre irradiant/een irradiërend boek,"Matthew Fuller +, Sînziana Păltineanu +, Michael Murtaugh +, Dennis Pohl +, ShinJoung Yeo +, Femke Snelting +, Natacha Roussel +, Dick Reckard +, Geraldine Juárez +, Tomislav Medak +, Marcell Mars +, Dušan Barok + and Alexia de Visscher +",Media studies,pdf,1,1,Monoskop, Mondothèque::a radiated book/un livre irradiant/een irradiërend boek,"Matthew Fuller +, Sînziana Păltineanu +, Michael Murtaugh +, Dennis Pohl +, ShinJoung Yeo +, Femke Snelting +, Natacha Roussel +, Dick Reckard +, Geraldine Juárez +, Tomislav Medak +, Marcell Mars +, Dušan Barok + and Alexia de Visscher +",Media studies,pdf,1,1,Monoskop,
Save and Forget,Thomas Walskaar,Media studies,pdf,1,1,Academia.edu, Save and Forget,Thomas Walskaar,Media studies,pdf,1,1,Academia.edu,

1 Title Author Shelf Format OCR Downloaded Origin Filename
29 Getting Gread Sounds: The Microphone Book Tom Lubin Technical 0
30 How to Think Like a Computer Scientist Allen B. Downey, Jeffrey Elkner, Chris Meyers Technical pdf 1 1 LibGen
31 Python Pocket Reference Mark Lutz Technical pdf 1 LibGen
Things That Talk Lorraine Daston (Editor) Science/History
The Social Construction of What? Ian Hacking Science/History pdf 1 1 LibGen
32 Instruments and the Imagination Hankins & Silverman Science/History
33 Mind, Machines and Human Consciousness Robert Nadeau Science/History
34 The Psychopath Test Jon Ronson Science/History pdf 1 1 LibGen
74 Selections from Cultural Writings Antonio Gramsci Media studies 0
75 Dark Money: The Hidden History of the Billionairs behind the Rise of the Radical Right Jane Mayer Media studies EPUB 1 Libgen
76 Walter Benjamin for beginners Howard Caygill, Alex Coles, Richard Appignanesi Media studies 0
What is Situationism? A Reader Stewart Home (ed.) Media studies pdf 1 1 MOTW
77 Cyburbia James Harkin Media studies 0
78 Mondothèque::a radiated book/un livre irradiant/een irradiërend boek Matthew Fuller +, Sînziana Păltineanu +, Michael Murtaugh +, Dennis Pohl +, ShinJoung Yeo +, Femke Snelting +, Natacha Roussel +, Dick Reckard +, Geraldine Juárez +, Tomislav Medak +, Marcell Mars +, Dušan Barok + and Alexia de Visscher + Media studies pdf 1 1 Monoskop
79 Save and Forget Thomas Walskaar Media studies pdf 1 1 Academia.edu
Loading…
Cancel
Save