@ -172,7 +172,7 @@ def remove_book_by_id(id):
@app.route ( ' /books/<int:id>/edit ' , methods = [ ' POST ' , ' GET ' ] )
def edit_book_by_id ( id ) :
book_to_edit = Book . query . filter_by ( id = id ) . first ( )
user_form = EditForm ( title = book_to_edit . title , author = book_to_edit . authors , category = book_to_edit . category , year_published = book_to_edit . year_published , message = book_to_edit . message )
user_form = EditForm ( title = book_to_edit . title , author = book_to_edit . authors , category = book_to_edit . category , year_published = book_to_edit . year_published , message = book_to_edit . message , sameness = book_to_edit . sameness , gender = book_to_edit . gender , diversity = book_to_edit . diversity , who = book_to_edit . who )
if request . method == ' POST ' :
if user_form . validate_on_submit ( ) :
@ -182,6 +182,11 @@ def edit_book_by_id(id):
category = user_form . category . data
year_published = user_form . year_published . data
message = user_form . message . data
sameness = user_form . sameness . data
gender = user_form . gender . data
diversity = user_form . diversity . data
who = user_form . who . data
if year_published == " " :
year_published = None
book = Book . query . filter_by ( id = id ) . first ( )
@ -189,6 +194,10 @@ def edit_book_by_id(id):
book . category = category
book . year_published = year_published
book . message = message
book . sameness = sameness
book . gender = gender
book . diversity = diversity
book . who = who
#authors update
book . authors . clear ( )
@ -258,9 +267,6 @@ def add_book():
sameness = upload_form . sameness . data
gender = upload_form . gender . data
diversity = upload_form . diversity . data
time = None
if time :
time = upload_form . time . data
who = upload_form . who . data
if year_published == " " :
@ -310,9 +316,8 @@ def add_book():
html_string = render_template ( ' potential_pdf.html ' , pbooks = pbooks )
html = HTML ( string = html_string )
html . write_pdf ( target = ' app/uploads/potential.pdf ' ) ;
print ( ' potential_pdf ' )
book = Book ( title , filename , cover , file_extension , category , year_published , message , sameness , diversity , gender , who , time )
book = Book ( title , filename , cover , file_extension , category , year_published , message , sameness , diversity , gender , who )
db . session . add ( book )
for author in authors :
author_name = author . get ( " author_name " )
@ -395,7 +400,7 @@ def show_stack_by_id(id, is_tab=False):
stack = Stack . query . get ( id )
if not stack :
abort ( 404 )
return render_template ( ' add_stack.html ' , stacks = stacks , form = form )
else :
if is_tab == False :
return render_template ( ' show_stack_detail.html ' , stack = stack )
@ -520,14 +525,16 @@ def search_results(searchtype, query, viewby):
if searchtype == ' Stack ' :
results = db . session . query ( Book ) . join ( Book . stacks ) . filter ( Stack . stack_name . contains ( query ) ) . order_by ( Book . title )
if searchtype == ' Outliers ' :
results = Book . query . filter ( Book . sameness > 50 ) . order_by ( Book . title )
if searchtype == ' All ' :
# results=Book.query.whoosh_search(query)
results = Book . query . filter ( Book . title . contains ( query ) )
results = results . union ( Book . query . filter ( Book . category . contains ( query ) ) )
results = results . union ( Book . query . filter ( Book . year_published . contains ( query ) ) )
results = results . union ( db . session . query ( Book ) . join ( Book . authors ) . filter ( Author . author_name . contains ( query ) ) )
results = results . union ( db . session . query ( Book ) . join ( Book . stacks ) . filter ( Stack . stack_name . contains ( query ) ) )
results = results . union ( db . session . query ( Book ) . join ( Book . stacks ) . filter ( Stack . stack_description . contains ( query ) ) ) . order_by ( Book . title )
results = results . union ( db . session . query ( Book ) . join ( Book . stacks ) . filter ( Stack . stack_name . contains ( query ) ) ) . order_by ( Book . title )
if results . count ( ) == 0 :
books = Book . query . filter ( Book . file . like ( ' potential.pdf ' ) )
@ -669,17 +676,32 @@ def import_csv():
print ( " allreadyexists " )
else :
cover = ' '
if row [ ' file ' ] :
if row [ ' file ' ] == ' ' :
file = ' potential.pdf '
# file_extension = '.pdf'
# ptitle = row['title']
# pbook = Potential(ptitle)
# db.session.add(pbook)
# db.session.commit()
# pbooks = Potential.query.all()
# template = 'app/templates/potential_pdf.html'
# html_string = render_template('potential_pdf.html', pbooks = pbooks)
# html = HTML(string=html_string)
# html.write_pdf(target='app/uploads/potential.pdf')
# print ('writing to potential_pdf')
else :
fullpath = os . path . join ( app . config [ ' UPLOAD_FOLDER ' ] , row [ ' file ' ] )
name , file_extension = os . path . splitext ( row [ ' file ' ] )
print ( ' get_cover ' , fullpath , name )
cover = get_cover ( fullpath , name )
file = str ( id ) + " _ " + row [ ' file ' ]
if row [ ' year_published ' ] :
year_published = int ( row [ ' year_published ' ] )
else :
year_published = None ;
book = Book ( row [ ' title ' ] , row [ ' file ' ] , cover , row [ ' fileformat ' ] , row [ ' category ' ] , year_published , None , None , None , None , None , None )
book = Book ( row [ ' title ' ] , file, cover , row [ ' fileformat ' ] , row [ ' category ' ] , year_published , None , None , None , None , None )
if row [ ' scapeX ' ] :
book . scapeX = float ( row [ ' scapeX ' ] )
if row [ ' scapeY ' ] :