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
765b8173
Commit
765b8173
authored
Mar 16, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored shelf.py and editbooks.py
parent
baf83b2f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
58 deletions
+17
-58
editbooks.py
cps/editbooks.py
+6
-22
shelf.py
cps/shelf.py
+10
-35
shelf.html
cps/templates/shelf.html
+1
-1
No files found.
cps/editbooks.py
View file @
765b8173
...
@@ -45,8 +45,6 @@ editbook = Blueprint('editbook', __name__)
...
@@ -45,8 +45,6 @@ editbook = Blueprint('editbook', __name__)
EXTENSIONS_CONVERT
=
{
'pdf'
,
'epub'
,
'mobi'
,
'azw3'
,
'docx'
,
'rtf'
,
'fb2'
,
'lit'
,
'lrf'
,
'txt'
,
'htmlz'
,
'rtf'
,
'odt'
}
EXTENSIONS_CONVERT
=
{
'pdf'
,
'epub'
,
'mobi'
,
'azw3'
,
'docx'
,
'rtf'
,
'fb2'
,
'lit'
,
'lrf'
,
'txt'
,
'htmlz'
,
'rtf'
,
'odt'
}
# Modifies different Database objects, first check if elements have to be added to database, than check
# Modifies different Database objects, first check if elements have to be added to database, than check
# if elements have to be deleted, because they are no longer used
# if elements have to be deleted, because they are no longer used
def
modify_database_object
(
input_elements
,
db_book_object
,
db_object
,
db_session
,
db_type
):
def
modify_database_object
(
input_elements
,
db_book_object
,
db_object
,
db_session
,
db_type
):
...
@@ -260,26 +258,12 @@ def edit_cc_data(book_id, book, to_save):
...
@@ -260,26 +258,12 @@ def edit_cc_data(book_id, book, to_save):
else
:
else
:
cc_db_value
=
None
cc_db_value
=
None
if
to_save
[
cc_string
]
.
strip
():
if
to_save
[
cc_string
]
.
strip
():
if
c
.
datatype
==
'bool'
:
if
c
.
datatype
==
'
int'
or
c
.
datatype
==
'
bool'
:
if
to_save
[
cc_string
]
==
'None'
:
if
to_save
[
cc_string
]
==
'None'
:
to_save
[
cc_string
]
=
None
to_save
[
cc_string
]
=
None
el
se
:
el
if
c
.
datatype
==
'bool'
:
to_save
[
cc_string
]
=
1
if
to_save
[
cc_string
]
==
'True'
else
0
to_save
[
cc_string
]
=
1
if
to_save
[
cc_string
]
==
'True'
else
0
if
to_save
[
cc_string
]
!=
cc_db_value
:
if
cc_db_value
is
not
None
:
if
to_save
[
cc_string
]
is
not
None
:
setattr
(
getattr
(
book
,
cc_string
)[
0
],
'value'
,
to_save
[
cc_string
])
else
:
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
db
.
session
.
delete
(
del_cc
)
else
:
cc_class
=
db
.
cc_classes
[
c
.
id
]
new_cc
=
cc_class
(
value
=
to_save
[
cc_string
],
book
=
book_id
)
db
.
session
.
add
(
new_cc
)
elif
c
.
datatype
==
'int'
:
if
to_save
[
cc_string
]
==
'None'
:
to_save
[
cc_string
]
=
None
if
to_save
[
cc_string
]
!=
cc_db_value
:
if
to_save
[
cc_string
]
!=
cc_db_value
:
if
cc_db_value
is
not
None
:
if
cc_db_value
is
not
None
:
if
to_save
[
cc_string
]
is
not
None
:
if
to_save
[
cc_string
]
is
not
None
:
...
@@ -401,12 +385,12 @@ def upload_cover(request, book):
...
@@ -401,12 +385,12 @@ def upload_cover(request, book):
requested_file
.
save
(
saved_filename
)
requested_file
.
save
(
saved_filename
)
# im=Image.open(saved_filename)
# im=Image.open(saved_filename)
book
.
has_cover
=
1
book
.
has_cover
=
1
except
OSError
:
flash
(
_
(
u"Failed to store cover-file
%(cover)
s."
,
cover
=
saved_filename
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.show_book'
,
book_id
=
book
.
id
))
except
IOError
:
except
IOError
:
flash
(
_
(
u"Cover-file is not a valid image file"
%
saved_filename
),
category
=
"error"
)
flash
(
_
(
u"Cover-file is not a valid image file"
%
saved_filename
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.show_book'
,
book_id
=
book
.
id
))
return
redirect
(
url_for
(
'web.show_book'
,
book_id
=
book
.
id
))
except
OSError
:
flash
(
_
(
u"Failed to store cover-file
%(cover)
s."
,
cover
=
saved_filename
),
category
=
"error"
)
return
redirect
(
url_for
(
'web.show_book'
,
book_id
=
book
.
id
))
@
editbook
.
route
(
"/admin/book/<int:book_id>"
,
methods
=
[
'GET'
,
'POST'
])
@
editbook
.
route
(
"/admin/book/<int:book_id>"
,
methods
=
[
'GET'
,
'POST'
])
@
login_required_if_no_ano
@
login_required_if_no_ano
...
...
cps/shelf.py
View file @
765b8173
...
@@ -109,9 +109,9 @@ def search_to_shelf(shelf_id):
...
@@ -109,9 +109,9 @@ def search_to_shelf(shelf_id):
book_ids
=
list
()
book_ids
=
list
()
for
book_id
in
books_in_shelf
:
for
book_id
in
books_in_shelf
:
book_ids
.
append
(
book_id
.
book_id
)
book_ids
.
append
(
book_id
.
book_id
)
for
id
in
searched_ids
[
current_user
.
id
]:
for
search
id
in
searched_ids
[
current_user
.
id
]:
if
id
not
in
book_ids
:
if
search
id
not
in
book_ids
:
books_for_shelf
.
append
(
id
)
books_for_shelf
.
append
(
search
id
)
else
:
else
:
books_for_shelf
=
searched_ids
[
current_user
.
id
]
books_for_shelf
=
searched_ids
[
current_user
.
id
]
...
@@ -259,10 +259,11 @@ def delete_shelf(shelf_id):
...
@@ -259,10 +259,11 @@ def delete_shelf(shelf_id):
app
.
logger
.
info
(
_
(
u"successfully deleted shelf
%(name)
s"
,
name
=
cur_shelf
.
name
,
category
=
"success"
))
app
.
logger
.
info
(
_
(
u"successfully deleted shelf
%(name)
s"
,
name
=
cur_shelf
.
name
,
category
=
"success"
))
return
redirect
(
url_for
(
'web.index'
))
return
redirect
(
url_for
(
'web.index'
))
# @shelf.route("/shelfdown/<int:shelf_id>")
@
shelf
.
route
(
"/shelf/<int:shelf_id>"
)
@
shelf
.
route
(
"/shelf/<int:shelf_id>"
,
defaults
=
{
'type'
:
1
})
@
shelf
.
route
(
"/shelf/<int:shelf_id>/<int:type>"
)
@
login_required
@
login_required
def
show_shelf
(
shelf_id
):
def
show_shelf
(
type
,
shelf_id
):
if
current_user
.
is_anonymous
:
if
current_user
.
is_anonymous
:
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
is_public
==
1
,
ub
.
Shelf
.
id
==
shelf_id
)
.
first
()
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
is_public
==
1
,
ub
.
Shelf
.
id
==
shelf_id
)
.
first
()
else
:
else
:
...
@@ -273,6 +274,8 @@ def show_shelf(shelf_id):
...
@@ -273,6 +274,8 @@ def show_shelf(shelf_id):
result
=
list
()
result
=
list
()
# user is allowed to access shelf
# user is allowed to access shelf
if
shelf
:
if
shelf
:
page
=
"shelf.html"
if
type
==
1
else
'shelfdown.html'
books_in_shelf
=
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
shelf
==
shelf_id
)
.
order_by
(
books_in_shelf
=
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
shelf
==
shelf_id
)
.
order_by
(
ub
.
BookShelf
.
order
.
asc
())
.
all
()
ub
.
BookShelf
.
order
.
asc
())
.
all
()
for
book
in
books_in_shelf
:
for
book
in
books_in_shelf
:
...
@@ -283,41 +286,13 @@ def show_shelf(shelf_id):
...
@@ -283,41 +286,13 @@ def show_shelf(shelf_id):
app
.
logger
.
info
(
'Not existing book
%
s in shelf
%
s deleted'
%
(
book
.
book_id
,
shelf
.
id
))
app
.
logger
.
info
(
'Not existing book
%
s in shelf
%
s deleted'
%
(
book
.
book_id
,
shelf
.
id
))
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
book
.
book_id
)
.
delete
()
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
book
.
book_id
)
.
delete
()
ub
.
session
.
commit
()
ub
.
session
.
commit
()
return
render_title_template
(
'shelf.html'
,
entries
=
result
,
title
=
_
(
u"Shelf: '
%(name)
s'"
,
name
=
shelf
.
name
),
return
render_title_template
(
page
,
entries
=
result
,
title
=
_
(
u"Shelf: '
%(name)
s'"
,
name
=
shelf
.
name
),
shelf
=
shelf
,
page
=
"shelf"
)
shelf
=
shelf
,
page
=
"shelf"
)
else
:
else
:
flash
(
_
(
u"Error opening shelf. Shelf does not exist or is not accessible"
),
category
=
"error"
)
flash
(
_
(
u"Error opening shelf. Shelf does not exist or is not accessible"
),
category
=
"error"
)
return
redirect
(
url_for
(
"web.index"
))
return
redirect
(
url_for
(
"web.index"
))
@
shelf
.
route
(
"/shelfdown/<int:shelf_id>"
)
@
login_required
def
show_shelf_down
(
shelf_id
):
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
()
# user is allowed to access shelf
if
shelf
:
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
:
cur_book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book
.
book_id
)
.
first
()
if
cur_book
:
result
.
append
(
cur_book
)
else
:
app
.
logger
.
info
(
'Not existing book
%
s in shelf
%
s deleted'
%
(
book
.
book_id
,
shelf
.
id
))
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
book
.
book_id
)
.
delete
()
ub
.
session
.
commit
()
return
render_title_template
(
'shelfdown.html'
,
entries
=
result
,
title
=
_
(
u"Shelf: '
%(name)
s'"
,
name
=
shelf
.
name
),
shelf
=
shelf
,
page
=
"shelf"
)
else
:
flash
(
_
(
u"Error opening shelf. Shelf does not exist or is not accessible"
),
category
=
"error"
)
return
redirect
(
url_for
(
"web.index"
))
@
shelf
.
route
(
"/shelf/order/<int:shelf_id>"
,
methods
=
[
"GET"
,
"POST"
])
@
shelf
.
route
(
"/shelf/order/<int:shelf_id>"
,
methods
=
[
"GET"
,
"POST"
])
@
login_required
@
login_required
...
...
cps/templates/shelf.html
View file @
765b8173
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<div
class=
"discover"
>
<div
class=
"discover"
>
<h2>
{{title}}
</h2>
<h2>
{{title}}
</h2>
{% if g.user.role_download() %}
{% if g.user.role_download() %}
<a
id=
"shelf_down"
href=
"{{ url_for('shelf.show_shelf
_down'
, shelf_id=shelf.id) }}"
class=
"btn btn-primary"
>
{{ _('Download') }}
</a>
<a
id=
"shelf_down"
href=
"{{ url_for('shelf.show_shelf
', type=2
, shelf_id=shelf.id) }}"
class=
"btn btn-primary"
>
{{ _('Download') }}
</a>
{% endif %}
{% endif %}
{% if g.user.is_authenticated %}
{% if g.user.is_authenticated %}
{% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %}
{% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %}
...
...
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