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
2e4117ea
Commit
2e4117ea
authored
Oct 12, 2015
by
Jan Broer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for removing books from shelfs
parent
597c1ef2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
24 deletions
+77
-24
detail.html
cps/templates/detail.html
+51
-23
web.py
cps/web.py
+26
-1
No files found.
cps/templates/detail.html
View file @
2e4117ea
...
@@ -47,26 +47,9 @@
...
@@ -47,26 +47,9 @@
<ul
class=
"list-unstyled more-stuff"
>
<ul
class=
"list-unstyled more-stuff"
>
{% if g.user.shelf.all() or g.public_shelfes %}
<li>
<div
class=
"btn-group"
>
<button
type=
"button"
class=
"btn btn-default dropdown-toggle"
data-toggle=
"dropdown"
>
<span
class=
"glyphicon glyphicon-list"
></span>
add this book to a shelf
<span
class=
"caret"
></span>
</button>
<ul
class=
"dropdown-menu"
role=
"menu"
>
{% for shelf in g.user.shelf %}
<li><a
href=
"{{ url_for('add_to_shelf', book_id=entry.id, shelf_id=shelf.id) }}"
>
{{shelf.name}}
</a></li>
{% endfor %}
{% for shelf in g.public_shelfes %}
<li><a
href=
"{{ url_for('add_to_shelf', book_id=entry.id, shelf_id=shelf.id) }}"
>
{{shelf.name}}
</a></li>
{% endfor %}
</ul>
</div>
</li>
{% endif %}
{% if g.user.kindle_mail %}
{% if g.user.kindle_mail %}
<li><a
href=
"{{url_for('send_to_kindle', book_id=entry.id)}}"
><div
class=
"btn btn-
default"
><span
class=
"glyphicon glyphicon-send"
></span>
Send ebook to k
indle
</div></a></li>
<li><a
href=
"{{url_for('send_to_kindle', book_id=entry.id)}}"
><div
class=
"btn btn-
info"
><span
class=
"glyphicon glyphicon-send"
></span>
Send to K
indle
</div></a></li>
{% endif %}
{% endif %}
...
@@ -80,8 +63,8 @@
...
@@ -80,8 +63,8 @@
</li> -->
</li> -->
<li>
<li>
<div
class=
"btn-group"
>
<div
class=
"btn-group"
>
<button
type=
"button"
class=
"btn btn-
success
dropdown-toggle"
data-toggle=
"dropdown"
>
<button
type=
"button"
class=
"btn btn-
primary
dropdown-toggle"
data-toggle=
"dropdown"
>
<span
class=
"glyphicon glyphicon-download"
></span>
download this ebook
<span
class=
"caret"
></span>
<span
class=
"glyphicon glyphicon-download"
></span>
Download
<span
class=
"caret"
></span>
</button>
</button>
<ul
class=
"dropdown-menu"
role=
"menu"
>
<ul
class=
"dropdown-menu"
role=
"menu"
>
{% for format in entry.data %}
{% for format in entry.data %}
...
@@ -91,11 +74,56 @@
...
@@ -91,11 +74,56 @@
</div>
</div>
</li>
</li>
<li><a
target=
"_blank"
href=
"{{url_for('read_book', book_id=entry.id)}}"
><div
class=
"btn btn-default"
><span
class=
"glyphicon glyphicon-eye-open"
></span>
read this book online
</div></a></li>
<li><a
target=
"_blank"
href=
"{{url_for('read_book', book_id=entry.id)}}"
><div
class=
"btn btn-primary"
><span
class=
"glyphicon glyphicon-eye-open"
></span>
Read online
</div></a></li>
{% if g.user.shelf.all() or g.public_shelfes %}
<li>
<div
class=
"btn-group"
>
<button
type=
"button"
class=
"btn btn-sm btn-default dropdown-toggle"
data-toggle=
"dropdown"
>
<span
class=
"glyphicon glyphicon-list"
></span>
Add to shelf
<span
class=
"caret"
></span>
</button>
<ul
class=
"dropdown-menu"
role=
"menu"
>
{% for shelf in g.user.shelf %}
{% if not shelf.id in books_shelfs and shelf.is_public != 1 %}
<li><a
href=
"{{ url_for('add_to_shelf', book_id=entry.id, shelf_id=shelf.id) }}"
>
{{shelf.name}}
</a></li>
{% endif %}
{% endfor %}
{% for shelf in g.public_shelfes %}
{% if not shelf.id in books_shelfs %}
<li><a
href=
"{{ url_for('add_to_shelf', book_id=entry.id, shelf_id=shelf.id) }}"
>
{{shelf.name}}
</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
</li>
{% endif %}
{% if books_shelfs %}
<li>
<div
class=
"btn-group"
>
<button
type=
"button"
class=
"btn btn-sm btn-default dropdown-toggle"
data-toggle=
"dropdown"
>
<span
class=
"glyphicon glyphicon-list"
></span>
Remove from shelf
<span
class=
"caret"
></span>
</button>
<ul
class=
"dropdown-menu"
role=
"menu"
>
{% for shelf in g.user.shelf %}
{% if shelf.id in books_shelfs and shelf.is_public != 1 %}
<li><a
href=
"{{ url_for('remove_from_shelf', book_id=entry.id, shelf_id=shelf.id) }}"
>
{{shelf.name}}
</a></li>
{% endif %}
{% endfor %}
{% for shelf in g.public_shelfes %}
{% if shelf.id in books_shelfs %}
<li><a
href=
"{{ url_for('remove_from_shelf', book_id=entry.id, shelf_id=shelf.id) }}"
>
{{shelf.name}}
</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
</li>
{% endif %}
{% if g.user.role %}
{% if g.user.role %}
<li><a
href=
"{{ url_for('edit_book', book_id=entry.id) }}"
><div
class=
"btn btn-warning"
><span
class=
"glyphicon glyphicon-edit"
></span>
Edit book
</div></a></li>
<li><a
href=
"{{ url_for('edit_book', book_id=entry.id) }}"
><div
class=
"btn btn-
xs btn-
warning"
><span
class=
"glyphicon glyphicon-edit"
></span>
Edit book
</div></a></li>
<li><a
href=
"{{ url_for('edit_book', book_id=entry.id) }}"
><div
class=
"btn btn-danger"
><span
class=
"glyphicon glyphicon-trash"
></span>
Delete book
</div></a></li>
<li><a
href=
"{{ url_for('edit_book', book_id=entry.id) }}"
><div
class=
"btn btn-
xs btn-
danger"
><span
class=
"glyphicon glyphicon-trash"
></span>
Delete book
</div></a></li>
{% endif %}
{% endif %}
{% endif %}
{% endif %}
</ul>
</ul>
...
...
cps/web.py
View file @
2e4117ea
...
@@ -206,7 +206,11 @@ def discover(page):
...
@@ -206,7 +206,11 @@ def discover(page):
@
app
.
route
(
"/book/<int:id>"
)
@
app
.
route
(
"/book/<int:id>"
)
def
show_book
(
id
):
def
show_book
(
id
):
entries
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
id
)
.
first
()
entries
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
id
)
.
first
()
return
render_template
(
'detail.html'
,
entry
=
entries
,
title
=
entries
.
title
)
book_in_shelfs
=
[]
shelfs
=
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
id
)
.
all
()
for
entry
in
shelfs
:
book_in_shelfs
.
append
(
entry
.
shelf
)
return
render_template
(
'detail.html'
,
entry
=
entries
,
title
=
entries
.
title
,
books_shelfs
=
book_in_shelfs
)
@
app
.
route
(
"/category"
)
@
app
.
route
(
"/category"
)
def
category_list
():
def
category_list
():
...
@@ -348,6 +352,27 @@ def add_to_shelf(shelf_id, book_id):
...
@@ -348,6 +352,27 @@ def add_to_shelf(shelf_id, book_id):
ub
.
session
.
add
(
ins
)
ub
.
session
.
add
(
ins
)
ub
.
session
.
commit
()
ub
.
session
.
commit
()
flash
(
"Book has been added to shelf:
%
s"
%
shelf
.
name
,
category
=
"success"
)
#return redirect(url_for('show_book', id=book_id))
return
redirect
(
request
.
environ
[
"HTTP_REFERER"
])
@
app
.
route
(
"/shelf/remove/<int:shelf_id>/<int:book_id>"
)
@
login_required
def
remove_from_shelf
(
shelf_id
,
book_id
):
shelf
=
ub
.
session
.
query
(
ub
.
Shelf
)
.
filter
(
ub
.
Shelf
.
id
==
shelf_id
)
.
first
()
if
not
shelf
.
is_public
and
not
shelf
.
user_id
==
int
(
current_user
.
id
):
flash
(
"Sorry you are not allowed to remove a book from this shelf:
%
s"
%
shelf
.
name
)
return
redirect
(
url_for
(
'index'
))
book_shelf
=
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
shelf
==
shelf_id
,
ub
.
BookShelf
.
book_id
==
book_id
)
.
first
()
#rem = ub.BookShelf(shelf=shelf.id, book_id=book_id)
ub
.
session
.
delete
(
book_shelf
)
ub
.
session
.
commit
()
flash
(
"Book has been removed from shelf:
%
s"
%
shelf
.
name
,
category
=
"success"
)
return
redirect
(
request
.
environ
[
"HTTP_REFERER"
])
return
redirect
(
request
.
environ
[
"HTTP_REFERER"
])
@
app
.
route
(
"/shelf/create"
,
methods
=
[
"GET"
,
"POST"
])
@
app
.
route
(
"/shelf/create"
,
methods
=
[
"GET"
,
"POST"
])
...
...
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