Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
c6500b7e
Commit
c6500b7e
authored
Mar 29, 2016
by
Cervinko Cera
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master'
parents
1a922d45
e8b2ea87
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
60 deletions
+38
-60
helper.py
cps/helper.py
+13
-26
style.css
cps/static/css/style.css
+10
-2
detail.html
cps/templates/detail.html
+0
-1
email_edit.html
cps/templates/email_edit.html
+2
-2
user_list.html
cps/templates/user_list.html
+1
-1
web.py
cps/web.py
+12
-28
No files found.
cps/helper.py
View file @
c6500b7e
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
from
cps
import
db
,
ub
from
cps
import
db
,
ub
from
cps
import
config
from
cps
import
config
from
flask
import
current_app
as
app
import
smtplib
import
smtplib
import
sys
import
sys
...
@@ -29,19 +30,17 @@ def update_download(book_id, user_id):
...
@@ -29,19 +30,17 @@ def update_download(book_id, user_id):
def
make_mobi
(
book_id
):
def
make_mobi
(
book_id
):
kindlegen
=
os
.
path
.
join
(
config
.
MAIN_DIR
,
"vendor"
,
"kindlegen"
)
kindlegen
=
os
.
path
.
join
(
config
.
MAIN_DIR
,
"vendor"
,
"kindlegen"
)
if
not
os
.
path
.
exists
(
kindlegen
):
if
not
os
.
path
.
exists
(
kindlegen
):
print
"make_mobie: kindlegen binary not found in:
%
s"
%
kindlegen
app
.
logger
.
error
(
"make_mobi: kindlegen binary not found in:
%
s"
%
kindlegen
)
return
None
return
None
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
data
=
db
.
session
.
query
(
db
.
Data
)
.
filter
(
db
.
Data
.
book
==
book
.
id
)
.
filter
(
db
.
Data
.
format
==
'EPUB'
)
.
first
()
data
=
db
.
session
.
query
(
db
.
Data
)
.
filter
(
db
.
Data
.
book
==
book
.
id
)
.
filter
(
db
.
Data
.
format
==
'EPUB'
)
.
first
()
if
not
data
:
if
not
data
:
print
"make_mobie: epub format not found for book id:
%
d"
%
book_id
app
.
logger
.
error
(
"make_mobi: epub format not found for book id:
%
d"
%
book_id
)
return
None
return
None
file_path
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
data
.
name
)
file_path
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
data
.
name
)
# print os.path.getsize(file_path + ".epub")
if
os
.
path
.
exists
(
file_path
+
".epub"
):
if
os
.
path
.
exists
(
file_path
+
".epub"
):
# print u"conversion started for %s" % book.title
check
=
subprocess
.
call
([
kindlegen
,
file_path
+
".epub"
],
stdout
=
subprocess
.
PIPE
)
check
=
subprocess
.
call
([
kindlegen
,
file_path
+
".epub"
],
stdout
=
subprocess
.
PIPE
)
if
not
check
or
check
<
2
:
if
not
check
or
check
<
2
:
book
.
data
.
append
(
db
.
Data
(
book
.
data
.
append
(
db
.
Data
(
...
@@ -53,15 +52,14 @@ def make_mobi(book_id):
...
@@ -53,15 +52,14 @@ def make_mobi(book_id):
db
.
session
.
commit
()
db
.
session
.
commit
()
return
file_path
+
".mobi"
return
file_path
+
".mobi"
else
:
else
:
print
"make_mobie: kindlegen failed to convert book"
app
.
logger
.
error
(
"make_mobi: kindlegen failed with error while converting book"
)
return
None
return
None
else
:
else
:
print
"make_mobie: epub not found: "
+
file_path
+
".epub"
app
.
logger
.
error
(
"make_mobie: epub not found:
%
s.epub"
%
file_path
)
return
None
return
None
def
send_mail
(
book_id
,
kindle_mail
):
def
send_mail
(
book_id
,
kindle_mail
):
'''Send email with attachments'''
'''Send email with attachments'''
is_mobi
=
False
is_mobi
=
False
is_azw
=
False
is_azw
=
False
is_azw3
=
False
is_azw3
=
False
...
@@ -73,14 +71,12 @@ def send_mail(book_id, kindle_mail):
...
@@ -73,14 +71,12 @@ def send_mail(book_id, kindle_mail):
msg
=
MIMEMultipart
()
msg
=
MIMEMultipart
()
msg
[
'From'
]
=
settings
[
"mail_from"
]
msg
[
'From'
]
=
settings
[
"mail_from"
]
msg
[
'To'
]
=
kindle_mail
msg
[
'To'
]
=
kindle_mail
msg
[
'Subject'
]
=
'Sen
t
to Kindle'
msg
[
'Subject'
]
=
'Sen
d
to Kindle'
text
=
'This email has been sent via calibre web.'
text
=
'This email has been sent via calibre web.'
msg
.
attach
(
MIMEText
(
text
))
msg
.
attach
(
MIMEText
(
text
))
use_ssl
=
settings
.
get
(
'mail_use_ssl'
,
0
)
use_ssl
=
settings
.
get
(
'mail_use_ssl'
,
0
)
print
"use ssl:
%
d"
%
use_ssl
# attach files
# attach files
#msg.attach(self.get_attachment(file_path))
#msg.attach(self.get_attachment(file_path))
...
@@ -92,24 +88,15 @@ def send_mail(book_id, kindle_mail):
...
@@ -92,24 +88,15 @@ def send_mail(book_id, kindle_mail):
for
entry
in
data
:
for
entry
in
data
:
if
entry
.
format
==
"MOBI"
:
if
entry
.
format
==
"MOBI"
:
formats
[
"mobi"
]
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
entry
.
name
+
".mobi"
)
formats
[
"mobi"
]
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
entry
.
name
+
".mobi"
)
if
entry
.
format
==
"AZW"
:
formats
[
"azw"
]
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
entry
.
name
+
".azw"
)
if
entry
.
format
==
"AZW3"
:
formats
[
"azw3"
]
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
entry
.
name
+
".azw3"
)
if
entry
.
format
==
"EPUB"
:
if
entry
.
format
==
"EPUB"
:
formats
[
"epub"
]
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
entry
.
name
+
".epub"
)
formats
[
"epub"
]
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
entry
.
name
+
".epub"
)
if
entry
.
format
==
"PDF"
:
if
entry
.
format
==
"PDF"
:
formats
[
"pdf"
]
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
entry
.
name
+
".pdf"
)
formats
[
"pdf"
]
=
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
,
entry
.
name
+
".pdf"
)
if
len
(
formats
)
==
0
:
if
len
(
formats
)
==
0
:
print
"no formats found"
return
"Could not find any formats suitable for sending by email"
return
"Could not find any formats that can be send by email"
if
'mobi'
in
formats
:
if
'azw3'
in
formats
:
msg
.
attach
(
get_attachment
(
formats
[
'azw3'
]))
elif
'azw'
in
formats
:
msg
.
attach
(
get_attachment
(
formats
[
'azw'
]))
elif
'mobi'
in
formats
:
msg
.
attach
(
get_attachment
(
formats
[
'mobi'
]))
msg
.
attach
(
get_attachment
(
formats
[
'mobi'
]))
elif
'epub'
in
formats
:
elif
'epub'
in
formats
:
filepath
=
make_mobi
(
book
.
id
)
filepath
=
make_mobi
(
book
.
id
)
...
@@ -120,7 +107,7 @@ def send_mail(book_id, kindle_mail):
...
@@ -120,7 +107,7 @@ def send_mail(book_id, kindle_mail):
elif
'pdf'
in
formats
:
elif
'pdf'
in
formats
:
msg
.
attach
(
get_attachment
(
formats
[
'pdf'
]))
msg
.
attach
(
get_attachment
(
formats
[
'pdf'
]))
else
:
else
:
return
"Could not find any formats
that can be send
by email"
return
"Could not find any formats
suitable for sending
by email"
# convert MIME message to string
# convert MIME message to string
fp
=
StringIO
()
fp
=
StringIO
()
...
@@ -141,9 +128,9 @@ def send_mail(book_id, kindle_mail):
...
@@ -141,9 +128,9 @@ def send_mail(book_id, kindle_mail):
mailserver
.
login
(
settings
[
"mail_login"
],
settings
[
"mail_password"
])
mailserver
.
login
(
settings
[
"mail_login"
],
settings
[
"mail_password"
])
mailserver
.
sendmail
(
settings
[
"mail_login"
],
kindle_mail
,
msg
)
mailserver
.
sendmail
(
settings
[
"mail_login"
],
kindle_mail
,
msg
)
mailserver
.
quit
()
mailserver
.
quit
()
except
smtplib
.
SMTPException
:
except
(
socket
.
error
,
smtplib
.
SMTPRecipientsRefused
,
smtplib
.
SMTPException
),
e
:
traceback
.
print_exc
(
)
app
.
logger
.
error
(
traceback
.
print_exc
()
)
return
"
Error communicating with the mail server, please check the logs for details."
return
"
Failed to send mail:
%
s"
%
str
(
e
)
return
None
return
None
...
...
cps/static/css/style.css
View file @
c6500b7e
...
@@ -8,9 +8,9 @@ a{color: #45b29d}a:hover{color: #444;}
...
@@ -8,9 +8,9 @@ a{color: #45b29d}a:hover{color: #444;}
.container-fluid
img
{
display
:
block
;
max-width
:
100%
;
height
:
auto
}
.container-fluid
img
{
display
:
block
;
max-width
:
100%
;
height
:
auto
}
.container-fluid
.discover
{
margin-bottom
:
50px
}
.container-fluid
.discover
{
margin-bottom
:
50px
}
.container-fluid
.new-books
{
border-top
:
1px
solid
#ccc
}
.container-fluid
.new-books
h2
{
margin
:
50px
0
0
0
}
.container-fluid
.new-books
{
border-top
:
1px
solid
#ccc
}
.container-fluid
.new-books
h2
{
margin
:
50px
0
0
0
}
.container-fluid
.book
{
margin-top
:
20px
}
.container-fluid
.book
.cover
{
height
:
225px
;
position
:
relative
}
.container-fluid
.book
.cover
img
{
border
:
1px
solid
#ccc
;
border-radius
:
5px
;
box-sizeing
:
border-box
;
height
:
100%
;
bottom
:
0
;
position
:
absolute
}
.container-fluid
.book
{
margin-top
:
20px
}
.container-fluid
.book
.cover
{
height
:
225px
;
position
:
relative
}
.container-fluid
.book
.cover
img
{
border
:
3px
solid
#fff
;
border-radius
:
5px
;
box-sizeing
:
border-box
;
height
:
100%
;
bottom
:
0
;
position
:
absolute
;
-webkit-box-shadow
:
0
5px
8px
-6px
#777
;
-moz-box-shadow
:
0
5px
8px
-6px
#777
;
box-shadow
:
0
5px
8px
-6px
#777
;
}
.container-fluid
.book
.meta
{
margin-top
:
10px
}
.container-fluid
.book
.meta
p
{
margin
:
0
}
.container-fluid
.book
.meta
{
margin-top
:
10px
}
.container-fluid
.book
.meta
p
{
margin
:
0
}
.container-fluid
.book
.meta
.title
{
font-weight
:
bold
;
font-size
:
1
6
px
;
color
:
#444
}
.container-fluid
.book
.meta
.title
{
font-weight
:
bold
;
font-size
:
1
5
px
;
color
:
#444
}
.container-fluid
.book
.meta
.author
{
font-size
:
12px
;
color
:
#999
}
.container-fluid
.book
.meta
.author
{
font-size
:
12px
;
color
:
#999
}
.container-fluid
.book
.meta
.rating
{
margin-top
:
5px
}
.rating
.glyphicon-star
{
color
:
#999
}
.rating
.glyphicon-star.good
{
color
:
#45b29d
}
.container-fluid
.book
.meta
.rating
{
margin-top
:
5px
}
.rating
.glyphicon-star
{
color
:
#999
}
.rating
.glyphicon-star.good
{
color
:
#45b29d
}
.navbar-brand
{
font-family
:
'Grand Hotel'
,
cursive
;
font-size
:
35px
;
color
:
#45b29d
!important
;}
.navbar-brand
{
font-family
:
'Grand Hotel'
,
cursive
;
font-size
:
35px
;
color
:
#45b29d
!important
;}
...
@@ -20,3 +20,11 @@ a{color: #45b29d}a:hover{color: #444;}
...
@@ -20,3 +20,11 @@ a{color: #45b29d}a:hover{color: #444;}
span
.glyphicon.glyphicon-tags
{
padding-right
:
5px
;
color
:
#999
;
vertical-align
:
text-top
;}
span
.glyphicon.glyphicon-tags
{
padding-right
:
5px
;
color
:
#999
;
vertical-align
:
text-top
;}
.book-meta
{
padding-bottom
:
20px
;}
.book-meta
{
padding-bottom
:
20px
;}
.book-meta
.tags
a
{
display
:
inline
;}
.book-meta
.tags
a
{
display
:
inline
;}
.container-fluid
.single
.cover
img
{
border
:
3px
solid
#fff
;
border-radius
:
5px
;
box-sizeing
:
border-box
;
-webkit-box-shadow
:
0
5px
8px
-6px
#777
;
-moz-box-shadow
:
0
5px
8px
-6px
#777
;
box-shadow
:
0
5px
8px
-6px
#777
;
}
\ No newline at end of file
cps/templates/detail.html
View file @
c6500b7e
...
@@ -126,7 +126,6 @@
...
@@ -126,7 +126,6 @@
{% endif %}
{% endif %}
{% if g.user.role %}
{% if g.user.role %}
</br>
<div
class=
"btn-toolbar"
role=
"toolbar"
>
<div
class=
"btn-toolbar"
role=
"toolbar"
>
<div
class=
"btn-group"
role=
"group"
aria-label=
"Edit/Delete book"
>
<div
class=
"btn-group"
role=
"group"
aria-label=
"Edit/Delete book"
>
<a
href=
"{{ url_for('edit_book', book_id=entry.id) }}"
class=
"btn btn-sm btn-warning"
role=
"button"
><span
class=
"glyphicon glyphicon-edit"
></span>
Edit metadata
</a>
<a
href=
"{{ url_for('edit_book', book_id=entry.id) }}"
class=
"btn btn-sm btn-warning"
role=
"button"
><span
class=
"glyphicon glyphicon-edit"
></span>
Edit metadata
</a>
...
...
cps/templates/email_edit.html
View file @
c6500b7e
...
@@ -8,11 +8,11 @@
...
@@ -8,11 +8,11 @@
<input
type=
"text"
class=
"form-control"
name=
"mail_server"
id=
"mail_server"
value=
"{{content.mail_server}}"
>
<input
type=
"text"
class=
"form-control"
name=
"mail_server"
id=
"mail_server"
value=
"{{content.mail_server}}"
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"mail_port"
>
SMTP port (usually 25 for
unencrypted and 587 for StartTLS
)
</label>
<label
for=
"mail_port"
>
SMTP port (usually 25 for
plain SMTP and 587 for SSL
)
</label>
<input
type=
"text"
class=
"form-control"
name=
"mail_port"
id=
"mail_port"
value=
"{{content.mail_port}}"
>
<input
type=
"text"
class=
"form-control"
name=
"mail_port"
id=
"mail_port"
value=
"{{content.mail_port}}"
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"mail_use_ssl"
>
Server
requires encryption
(StartTLS)
</label>
<label
for=
"mail_use_ssl"
>
Server
uses SSL
(StartTLS)
</label>
<input
type=
"checkbox"
name=
"mail_use_ssl"
id=
"mail_use_ssl"
{%
if
content
.
mail_use_ssl
%}
checked
{%
endif
%}
>
<input
type=
"checkbox"
name=
"mail_use_ssl"
id=
"mail_use_ssl"
{%
if
content
.
mail_use_ssl
%}
checked
{%
endif
%}
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
...
...
cps/templates/user_list.html
View file @
c6500b7e
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
<tr>
<tr>
<th>
SMTP hostname
</th>
<th>
SMTP hostname
</th>
<th>
SMTP port
</th>
<th>
SMTP port
</th>
<th>
S
erver requires S
SL
</th>
<th>
SSL
</th>
<th>
SMTP login
</th>
<th>
SMTP login
</th>
<th>
SMTP password
</th>
<th>
SMTP password
</th>
<th>
From mail
</th>
<th>
From mail
</th>
...
...
cps/web.py
View file @
c6500b7e
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
mimetypes
import
mimetypes
import
logging
import
sys
mimetypes
.
add_type
(
'application/xhtml+xml'
,
'.xhtml'
)
mimetypes
.
add_type
(
'application/xhtml+xml'
,
'.xhtml'
)
from
flask
import
Flask
,
render_template
,
session
,
request
,
Response
,
redirect
,
url_for
,
send_from_directory
,
make_response
,
g
,
flash
,
abort
from
flask
import
Flask
,
render_template
,
session
,
request
,
Response
,
redirect
,
url_for
,
send_from_directory
,
make_response
,
g
,
flash
,
abort
from
cps
import
db
,
config
,
ub
,
helper
from
cps
import
db
,
config
,
ub
,
helper
...
@@ -21,6 +23,15 @@ import json
...
@@ -21,6 +23,15 @@ import json
app
=
(
Flask
(
__name__
))
app
=
(
Flask
(
__name__
))
# Log only in production mode.
#if not app.debug:
file_handler
=
logging
.
StreamHandler
(
sys
.
stdout
)
file_handler
.
setLevel
(
logging
.
INFO
)
app
.
logger
.
addHandler
(
file_handler
)
app
.
logger_name
=
'calibre web'
app
.
logger
.
setLevel
(
logging
.
INFO
)
app
.
logger
.
info
(
'Starting Calibre Web...'
)
Principal
(
app
)
Principal
(
app
)
lm
=
LoginManager
(
app
)
lm
=
LoginManager
(
app
)
...
@@ -42,8 +53,6 @@ def load_user_from_header(header_val):
...
@@ -42,8 +53,6 @@ def load_user_from_header(header_val):
header_val
=
base64
.
b64decode
(
header_val
)
header_val
=
base64
.
b64decode
(
header_val
)
basic_username
=
header_val
.
split
(
':'
)[
0
]
basic_username
=
header_val
.
split
(
':'
)[
0
]
basic_password
=
header_val
.
split
(
':'
)[
1
]
basic_password
=
header_val
.
split
(
':'
)[
1
]
#print basic_username
#print basic_password
except
TypeError
:
except
TypeError
:
pass
pass
user
=
ub
.
session
.
query
(
ub
.
User
)
.
filter
(
ub
.
User
.
nickname
==
basic_username
)
.
first
()
user
=
ub
.
session
.
query
(
ub
.
User
)
.
filter
(
ub
.
User
.
nickname
==
basic_username
)
.
first
()
...
@@ -213,14 +222,7 @@ def get_opds_download_link(book_id, format):
...
@@ -213,14 +222,7 @@ def get_opds_download_link(book_id, format):
file_name
=
author
+
'-'
+
file_name
file_name
=
author
+
'-'
+
file_name
file_name
=
helper
.
get_valid_filename
(
file_name
)
file_name
=
helper
.
get_valid_filename
(
file_name
)
response
=
make_response
(
send_from_directory
(
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
),
data
.
name
+
"."
+
format
))
response
=
make_response
(
send_from_directory
(
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
),
data
.
name
+
"."
+
format
))
#response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (data.name, format)
response
.
headers
[
"Content-Disposition"
]
=
"attachment; filename=
%
s.
%
s"
%
(
data
.
name
,
format
)
response
.
headers
[
"Content-Disposition"
]
=
\
"attachment; "
\
"filename={utf_filename}.{suffix};"
\
"filename*=UTF-8''{utf_filename}.{suffix}"
.
format
(
utf_filename
=
file_name
.
encode
(
'utf-8'
),
suffix
=
format
)
return
response
return
response
@
app
.
route
(
"/get_authors_json"
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
"/get_authors_json"
,
methods
=
[
'GET'
,
'POST'
])
...
@@ -247,12 +249,6 @@ def index(page):
...
@@ -247,12 +249,6 @@ def index(page):
@
app
.
route
(
'/hot/page/<int:page>'
)
@
app
.
route
(
'/hot/page/<int:page>'
)
def
hot_books
(
page
):
def
hot_books
(
page
):
random
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
false
())
random
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
false
())
# if page == 1:
# entries = db.session.query(db.Books).filter(db.Books.ratings.any(db.Ratings.rating > 9)).order_by(db.Books.last_modified.desc()).limit(config.NEWEST_BOOKS)
# else:
# off = int(int(config.NEWEST_BOOKS) * (page - 1))
# entries = db.session.query(db.Books).filter(db.Books.ratings.any(db.Ratings.rating > 9)).order_by(db.Books.last_modified.desc()).offset(60).limit(config.NEWEST_BOOKS)
off
=
int
(
int
(
6
)
*
(
page
-
1
))
off
=
int
(
int
(
6
)
*
(
page
-
1
))
all_books
=
ub
.
session
.
query
(
ub
.
Downloads
,
ub
.
func
.
count
(
ub
.
Downloads
.
book_id
))
.
order_by
(
ub
.
func
.
count
(
ub
.
Downloads
.
book_id
)
.
desc
())
.
group_by
(
ub
.
Downloads
.
book_id
)
all_books
=
ub
.
session
.
query
(
ub
.
Downloads
,
ub
.
func
.
count
(
ub
.
Downloads
.
book_id
))
.
order_by
(
ub
.
func
.
count
(
ub
.
Downloads
.
book_id
)
.
desc
())
.
group_by
(
ub
.
Downloads
.
book_id
)
hot_books
=
all_books
.
offset
(
off
)
.
limit
(
config
.
NEWEST_BOOKS
)
hot_books
=
all_books
.
offset
(
off
)
.
limit
(
config
.
NEWEST_BOOKS
)
...
@@ -379,7 +375,6 @@ def get_download_link(book_id, format):
...
@@ -379,7 +375,6 @@ def get_download_link(book_id, format):
file_name
=
author
+
'-'
+
file_name
file_name
=
author
+
'-'
+
file_name
file_name
=
helper
.
get_valid_filename
(
file_name
)
file_name
=
helper
.
get_valid_filename
(
file_name
)
response
=
make_response
(
send_from_directory
(
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
),
data
.
name
+
"."
+
format
))
response
=
make_response
(
send_from_directory
(
os
.
path
.
join
(
config
.
DB_ROOT
,
book
.
path
),
data
.
name
+
"."
+
format
))
#response.headers["Content-Disposition"] = "attachment; filename=%s.%s" % (file_name, format)
response
.
headers
[
"Content-Disposition"
]
=
\
response
.
headers
[
"Content-Disposition"
]
=
\
"attachment; "
\
"attachment; "
\
"filename={utf_filename}.{suffix};"
\
"filename={utf_filename}.{suffix};"
\
...
@@ -553,7 +548,6 @@ def profile():
...
@@ -553,7 +548,6 @@ def profile():
downloads
.
append
(
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book
.
book_id
)
.
first
())
downloads
.
append
(
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book
.
book_id
)
.
first
())
if
request
.
method
==
"POST"
:
if
request
.
method
==
"POST"
:
to_save
=
request
.
form
.
to_dict
()
to_save
=
request
.
form
.
to_dict
()
#print to_save
if
to_save
[
"password"
]:
if
to_save
[
"password"
]:
content
.
password
=
generate_password_hash
(
to_save
[
"password"
])
content
.
password
=
generate_password_hash
(
to_save
[
"password"
])
if
to_save
[
"kindle_mail"
]
and
to_save
[
"kindle_mail"
]
!=
content
.
kindle_mail
:
if
to_save
[
"kindle_mail"
]
and
to_save
[
"kindle_mail"
]
!=
content
.
kindle_mail
:
...
@@ -669,7 +663,6 @@ def edit_book(book_id):
...
@@ -669,7 +663,6 @@ def edit_book(book_id):
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
to_save
=
request
.
form
.
to_dict
()
to_save
=
request
.
form
.
to_dict
()
#print to_save
book
.
title
=
to_save
[
"book_title"
]
book
.
title
=
to_save
[
"book_title"
]
is_author
=
db
.
session
.
query
(
db
.
Authors
)
.
filter
(
db
.
Authors
.
name
.
like
(
'
%
'
+
to_save
[
"author_name"
]
.
strip
()
+
'
%
'
))
.
first
()
is_author
=
db
.
session
.
query
(
db
.
Authors
)
.
filter
(
db
.
Authors
.
name
.
like
(
'
%
'
+
to_save
[
"author_name"
]
.
strip
()
+
'
%
'
))
.
first
()
...
@@ -701,7 +694,6 @@ def edit_book(book_id):
...
@@ -701,7 +694,6 @@ def edit_book(book_id):
for
tag
in
to_save
[
"tags"
]
.
split
(
","
):
for
tag
in
to_save
[
"tags"
]
.
split
(
","
):
if
tag
.
strip
():
if
tag
.
strip
():
#print tag
is_tag
=
db
.
session
.
query
(
db
.
Tags
)
.
filter
(
db
.
Tags
.
name
.
like
(
'
%
'
+
tag
.
strip
()
+
'
%
'
))
.
first
()
is_tag
=
db
.
session
.
query
(
db
.
Tags
)
.
filter
(
db
.
Tags
.
name
.
like
(
'
%
'
+
tag
.
strip
()
+
'
%
'
))
.
first
()
if
is_tag
:
if
is_tag
:
book
.
tags
.
append
(
is_tag
)
book
.
tags
.
append
(
is_tag
)
...
@@ -729,11 +721,3 @@ def edit_book(book_id):
...
@@ -729,11 +721,3 @@ def edit_book(book_id):
return
render_template
(
'edit_book.html'
,
book
=
book
)
return
render_template
(
'edit_book.html'
,
book
=
book
)
else
:
else
:
return
render_template
(
'edit_book.html'
,
book
=
book
)
return
render_template
(
'edit_book.html'
,
book
=
book
)
# @app.route('/admin/delete/<int:book_id>')
# def delete_book(book_id):
# to_delete = db.session.query(db.Books).filter(db.Books.id == book_id).first()
# print to_delete
# db.session.delete(to_delete)
# db.session.commit()
# return redirect(url_for('index'))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment