Removed unused wishlist code

Added renaming of shelf name
Added sorting abilty to shelfs
jquery is loaded locally now
pull/90/head
OzzieIsaacs 8 years ago
parent 580389d279
commit e0459eb62b

@ -5,7 +5,6 @@ import db, ub
import config import config
from flask import current_app as app from flask import current_app as app
import logging import logging
import smtplib import smtplib
import tempfile import tempfile
import socket import socket

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,30 @@
Sortable.create(sortTrue, {
group: "sorting",
sort: true
});
function sendData(path){
var elements;
var counter;
var maxElements;
var tmp=[];
elements=Sortable.utils.find(sortTrue,"div");
maxElements=elements.length;
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", path);
for(counter=0;counter<maxElements;counter++){
tmp[counter]=elements[counter].getAttribute("id");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", elements[counter].getAttribute("id"));
hiddenField.setAttribute("value", counter+1);
form.appendChild(hiddenField);
}
document.body.appendChild(form);
form.submit();
}

@ -20,7 +20,8 @@
<![endif]--> <![endif]-->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery.js"></script> <!--script src="https://code.jquery.com/jquery.js"></script-->
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
<!-- Include all compiled plugins (below), or include individual files as needed --> <!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script> <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/underscore.min.js') }}"></script> <script src="{{ url_for('static', filename='js/underscore.min.js') }}"></script>
@ -28,6 +29,8 @@
<script src="{{ url_for('static', filename='js/context.js') }}"></script> <script src="{{ url_for('static', filename='js/context.js') }}"></script>
<script src="{{ url_for('static', filename='js/plugins.js') }}"></script> <script src="{{ url_for('static', filename='js/plugins.js') }}"></script>
<script src="{{ url_for('static', filename='js/main.js') }}"></script> <script src="{{ url_for('static', filename='js/main.js') }}"></script>
<script src="{{ url_for('static', filename='js/Sortable.min.js') }}"></script>
{% block header %}{% endblock %} {% block header %}{% endblock %}
</head> </head>
<body> <body>

@ -0,0 +1,20 @@
{% extends "layout.html" %}
{% block body %}
<div class="col-sm-6 col-lg-6 col-xs-6">
<h2>{{title}}</h2>
<div id="sortTrue" class="list-group">
{% for entry in entries %}
<div id="{{entry.id}}" class="list-group-item">{{entry.title}}</div>
{% endfor %}
</div>
<button onclick="sendData('{{ url_for('order_shelf', shelf_id=shelf.id) }}')" class="btn btn-default" id="ChangeOrder">{{_('Change order')}}</button>
<a href="{{ url_for('show_shelf', shelf_id=shelf.id) }}" class="btn btn-default">{{_('Back')}}</a>
</div>
{% endblock %}
{% block js %}
<script src="{{ url_for('static', filename='js/shelforder.js') }}"></script>
{% endblock %}

@ -4,6 +4,8 @@
<h2>{{title}}</h2> <h2>{{title}}</h2>
{% if g.user.is_authenticated %} {% if g.user.is_authenticated %}
<a href=" {{ url_for('delete_shelf', shelf_id=shelf.id) }} " class="btn btn-danger">{{ _('Delete this Shelf') }} </a> <a href=" {{ url_for('delete_shelf', shelf_id=shelf.id) }} " class="btn btn-danger">{{ _('Delete this Shelf') }} </a>
<a href=" {{ url_for('edit_shelf', shelf_id=shelf.id) }} " class="btn btn-primary">{{ _('Edit Shelf name') }} </a>
<a href=" {{ url_for('order_shelf', shelf_id=shelf.id) }} " class="btn btn-primary">{{ _('change order') }} </a>
{% endif %} {% endif %}
<div class="row"> <div class="row">

@ -5,14 +5,17 @@
<form role="form" method="POST"> <form role="form" method="POST">
<div class="form-group"> <div class="form-group">
<label for="title">{{_('Title')}}</label> <label for="title">{{_('Title')}}</label>
<input type="text" class="form-control" name="title" id="title" value=""> <input type="text" class="form-control" name="title" id="title" value="{{ shelf.name if shelf.name != None }}">
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" name="is_public"> {{_('should the shelf be public?')}} <input type="checkbox" name="is_public" {% if shelf.is_public == 1 %}checked{% endif %}> {{_('should the shelf be public?')}}
</label> </label>
</div> </div>
<button type="submit" class="btn btn-default">{{_('Submit')}}</button> <button type="submit" class="btn btn-default">{{_('Submit')}}</button>
{% if shelf.id != None %}
<a href="{{ url_for('show_shelf', shelf_id=shelf.id) }}" class="btn btn-default">{{_('Back')}}</a>
{% endif %}
</form> </form>
</div> </div>
{% endblock %} {% endblock %}

File diff suppressed because it is too large Load Diff

@ -32,7 +32,6 @@ class User(Base):
password = Column(String) password = Column(String)
kindle_mail = Column(String(120), default="") kindle_mail = Column(String(120), default="")
shelf = relationship('Shelf', backref='user', lazy='dynamic') shelf = relationship('Shelf', backref='user', lazy='dynamic')
whislist = relationship('Whislist', backref='user', lazy='dynamic')
downloads = relationship('Downloads', backref='user', lazy='dynamic') downloads = relationship('Downloads', backref='user', lazy='dynamic')
locale = Column(String(2), default="en") locale = Column(String(2), default="en")
random_books = Column(Integer, default=1) random_books = Column(Integer, default=1)
@ -117,27 +116,12 @@ class Shelf(Base):
def __repr__(self): def __repr__(self):
return '<Shelf %r>' % self.name return '<Shelf %r>' % self.name
class Whislist(Base):
__tablename__ = "wishlist"
id = Column(Integer, primary_key=True)
name = Column(String)
is_public = Column(String)
user_id = Column(Integer, ForeignKey('user.id'))
def __init__(self):
pass
def __repr__(self):
return '<Whislist %r>' % self.name
class BookShelf(Base): class BookShelf(Base):
__tablename__ = 'book_shelf_link' __tablename__ = 'book_shelf_link'
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
book_id = Column(Integer) book_id = Column(Integer)
order = Column(Integer)
shelf = Column(Integer, ForeignKey('shelf.id')) shelf = Column(Integer, ForeignKey('shelf.id'))
def __repr__(self): def __repr__(self):
@ -154,19 +138,6 @@ class Downloads(Base):
def __repr__(self): def __repr__(self):
return '<Download %r' % self.book_id return '<Download %r' % self.book_id
class Whish(Base):
__tablename__ = 'whish'
id = Column(Integer, primary_key=True)
title = Column(String)
url = Column(String)
wishlist = Column(Integer, ForeignKey('wishlist.id'))
def __repr__(self):
return '<Whish %r>' % self.title
class Settings(Base): class Settings(Base):
__tablename__ = 'settings' __tablename__ = 'settings'

@ -1184,8 +1184,12 @@ def add_to_shelf(shelf_id, book_id):
if not shelf.is_public and not shelf.user_id == int(current_user.id): if not shelf.is_public and not shelf.user_id == int(current_user.id):
flash("Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name) flash("Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name)
return redirect(url_for('index', _external=True)) return redirect(url_for('index', _external=True))
maxO = ub.session.query(func.max(ub.BookShelf.order)).filter(ub.BookShelf.shelf == shelf_id).first()
ins = ub.BookShelf(shelf=shelf.id, book_id=book_id) if maxO[0] is None:
maxOrder = 0
else:
maxOrder = maxO[0]
ins = ub.BookShelf(shelf=shelf.id, book_id=book_id, order=maxOrder+1)
ub.session.add(ins) ub.session.add(ins)
ub.session.commit() ub.session.commit()
@ -1235,9 +1239,34 @@ def create_shelf():
flash(_(u"Shelf %(title)s created", title=to_save["title"]), category="success") flash(_(u"Shelf %(title)s created", title=to_save["title"]), category="success")
except: except:
flash(_(u"There was an error"), category="error") flash(_(u"There was an error"), category="error")
return render_template('shelf_edit.html', title=_(u"create a shelf")) return render_template('shelf_edit.html', shelf=shelf, title=_(u"create a shelf"))
else:
return render_template('shelf_edit.html', shelf=shelf, title=_(u"create a shelf"))
@app.route("/shelf/edit/<int:shelf_id>", methods=["GET", "POST"])
@login_required
def edit_shelf(shelf_id):
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first()
if request.method == "POST":
to_save = request.form.to_dict()
existing_shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.name == to_save["title"]).first()
if existing_shelf and existing_shelf.id != shelf_id:
flash(_(u"A shelf with the name '%(title)s' already exists.",title=to_save["title"]), category="error")
else:
shelf.name = to_save["title"]
if "is_public" in to_save:
shelf.is_public = 1
else:
shelf.is_public = 0
try:
ub.session.commit()
flash(_(u"Shelf %(title)s changed",title=to_save["title"]), category="success")
except:
flash(_(u"There was an error"), category="error")
return render_template('shelf_edit.html', shelf=shelf, title=_(u"Edit a shelf"))
else: else:
return render_template('shelf_edit.html', title=_(u"create a shelf")) return render_template('shelf_edit.html', shelf=shelf, title=_(u"Edit a shelf"))
@app.route("/shelf/delete/<int:shelf_id>") @app.route("/shelf/delete/<int:shelf_id>")
@ -1273,7 +1302,7 @@ def show_shelf(shelf_id):
ub.Shelf.id == shelf_id))).first() ub.Shelf.id == shelf_id))).first()
result = list() result = list()
if shelf: if shelf:
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).all() books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by(ub.BookShelf.order.asc()).all()
for book in books_in_shelf: for book in books_in_shelf:
cur_book = db.session.query(db.Books).filter(db.Books.id == book.book_id).first() cur_book = db.session.query(db.Books).filter(db.Books.id == book.book_id).first()
result.append(cur_book) result.append(cur_book)
@ -1281,6 +1310,34 @@ def show_shelf(shelf_id):
return render_template('shelf.html', entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name), shelf=shelf) return render_template('shelf.html', entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name), shelf=shelf)
@app.route("/shelf/order/<int:shelf_id>", methods=["GET", "POST"])
@login_required_if_no_ano
def order_shelf(shelf_id):
if request.method == "POST":
to_save = request.form.to_dict()
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by(
ub.BookShelf.order.asc()).all()
counter=0
for book in books_in_shelf:
setattr(book, 'order', to_save[str(book.book_id)])
counter+=1
ub.session.commit()
if current_user.is_anonymous():
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
else:
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),
ub.Shelf.id == shelf_id),
ub.and_(ub.Shelf.is_public == 1,
ub.Shelf.id == shelf_id))).first()
result = list()
if shelf:
books_in_shelf2 = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by(ub.BookShelf.order.asc()).all()
for book in books_in_shelf2:
cur_book = db.session.query(db.Books).filter(db.Books.id == book.book_id).first()
result.append(cur_book)
return render_template('order_shelf.html', entries=result, title=_(u"Change order of Shelf: '%(name)s'", name=shelf.name), shelf=shelf)
@app.route("/me", methods=["GET", "POST"]) @app.route("/me", methods=["GET", "POST"])
@login_required @login_required
def profile(): def profile():

Loading…
Cancel
Save