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
57d37ffb
Commit
57d37ffb
authored
Feb 01, 2020
by
Michael Shavit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add schema support for more reading states to the ReadBook table.
parent
4e8b814e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
ub.py
cps/ub.py
+14
-1
web.py
cps/web.py
+8
-4
No files found.
cps/ub.py
View file @
57d37ffb
...
@@ -34,8 +34,9 @@ except ImportError:
...
@@ -34,8 +34,9 @@ except ImportError:
from
sqlalchemy
import
create_engine
,
exc
,
exists
from
sqlalchemy
import
create_engine
,
exc
,
exists
from
sqlalchemy
import
Column
,
ForeignKey
from
sqlalchemy
import
Column
,
ForeignKey
from
sqlalchemy
import
String
,
Integer
,
SmallInteger
,
Boolean
,
DateTime
from
sqlalchemy
import
String
,
Integer
,
SmallInteger
,
Boolean
,
DateTime
from
sqlalchemy.orm
import
relationship
,
sessionmaker
from
sqlalchemy.orm
import
foreign
,
relationship
,
remote
,
sessionmaker
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.sql.expression
import
and_
from
werkzeug.security
import
generate_password_hash
from
werkzeug.security
import
generate_password_hash
from
.
import
constants
# , config
from
.
import
constants
# , config
...
@@ -284,10 +285,15 @@ class BookShelf(Base):
...
@@ -284,10 +285,15 @@ class BookShelf(Base):
class
ReadBook
(
Base
):
class
ReadBook
(
Base
):
__tablename__
=
'book_read_link'
__tablename__
=
'book_read_link'
STATUS_UNREAD
=
0
STATUS_FINISHED
=
1
STATUS_IN_PROGRESS
=
2
id
=
Column
(
Integer
,
primary_key
=
True
)
id
=
Column
(
Integer
,
primary_key
=
True
)
book_id
=
Column
(
Integer
,
unique
=
False
)
book_id
=
Column
(
Integer
,
unique
=
False
)
user_id
=
Column
(
Integer
,
ForeignKey
(
'user.id'
),
unique
=
False
)
user_id
=
Column
(
Integer
,
ForeignKey
(
'user.id'
),
unique
=
False
)
is_read
=
Column
(
Boolean
,
unique
=
False
)
is_read
=
Column
(
Boolean
,
unique
=
False
)
read_status
=
Column
(
Integer
,
unique
=
False
,
default
=
STATUS_UNREAD
)
class
Bookmark
(
Base
):
class
Bookmark
(
Base
):
...
@@ -373,6 +379,13 @@ def migrate_Database(session):
...
@@ -373,6 +379,13 @@ def migrate_Database(session):
conn
.
execute
(
"ALTER TABLE remote_auth_token ADD column 'token_type' INTEGER DEFAULT 0"
)
conn
.
execute
(
"ALTER TABLE remote_auth_token ADD column 'token_type' INTEGER DEFAULT 0"
)
conn
.
execute
(
"update remote_auth_token set 'token_type' = 0"
)
conn
.
execute
(
"update remote_auth_token set 'token_type' = 0"
)
session
.
commit
()
session
.
commit
()
try
:
session
.
query
(
exists
()
.
where
(
ReadBook
.
read_status
))
.
scalar
()
except
exc
.
OperationalError
:
# Database is not compatible, some columns are missing
conn
=
engine
.
connect
()
conn
.
execute
(
"ALTER TABLE book_read_link ADD column 'read_status' INTEGER DEFAULT 0"
)
conn
.
execute
(
"UPDATE book_read_link SET 'read_status' = 1 WHERE is_read"
)
session
.
commit
()
# Handle table exists, but no content
# Handle table exists, but no content
cnt
=
session
.
query
(
Registration
)
.
count
()
cnt
=
session
.
query
(
Registration
)
.
count
()
...
...
cps/web.py
View file @
57d37ffb
...
@@ -314,12 +314,15 @@ def toggle_read(book_id):
...
@@ -314,12 +314,15 @@ def toggle_read(book_id):
book
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
and_
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
),
book
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
and_
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
),
ub
.
ReadBook
.
book_id
==
book_id
))
.
first
()
ub
.
ReadBook
.
book_id
==
book_id
))
.
first
()
if
book
:
if
book
:
book
.
is_read
=
not
book
.
is_read
if
book
.
read_status
==
ub
.
ReadBook
.
STATUS_FINISHED
:
book
.
read_status
=
ub
.
ReadBook
.
STATUS_UNREAD
else
:
book
.
read_status
=
ub
.
ReadBook
.
STATUS_FINISHED
else
:
else
:
readBook
=
ub
.
ReadBook
()
readBook
=
ub
.
ReadBook
()
readBook
.
user_id
=
int
(
current_user
.
id
)
readBook
.
user_id
=
int
(
current_user
.
id
)
readBook
.
book_id
=
book_id
readBook
.
book_id
=
book_id
readBook
.
is_read
=
True
readBook
.
read_status
=
ub
.
ReadBook
.
STATUS_FINISHED
book
=
readBook
book
=
readBook
ub
.
session
.
merge
(
book
)
ub
.
session
.
merge
(
book
)
ub
.
session
.
commit
()
ub
.
session
.
commit
()
...
@@ -980,7 +983,7 @@ def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs)
...
@@ -980,7 +983,7 @@ def render_read_books(page, are_read, as_xml=False, order=None, *args, **kwargs)
order
=
order
or
[]
order
=
order
or
[]
if
not
config
.
config_read_column
:
if
not
config
.
config_read_column
:
readBooks
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
))
\
readBooks
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
filter
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
))
\
.
filter
(
ub
.
ReadBook
.
is_read
==
True
)
.
all
()
.
filter
(
ub
.
ReadBook
.
read_status
==
ub
.
ReadBook
.
STATUS_FINISHED
)
.
all
()
readBookIds
=
[
x
.
book_id
for
x
in
readBooks
]
readBookIds
=
[
x
.
book_id
for
x
in
readBooks
]
else
:
else
:
try
:
try
:
...
@@ -1448,7 +1451,8 @@ def show_book(book_id):
...
@@ -1448,7 +1451,8 @@ def show_book(book_id):
if
not
config
.
config_read_column
:
if
not
config
.
config_read_column
:
matching_have_read_book
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
\
matching_have_read_book
=
ub
.
session
.
query
(
ub
.
ReadBook
)
.
\
filter
(
and_
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
),
ub
.
ReadBook
.
book_id
==
book_id
))
.
all
()
filter
(
and_
(
ub
.
ReadBook
.
user_id
==
int
(
current_user
.
id
),
ub
.
ReadBook
.
book_id
==
book_id
))
.
all
()
have_read
=
len
(
matching_have_read_book
)
>
0
and
matching_have_read_book
[
0
]
.
is_read
have_read
=
len
(
matching_have_read_book
)
>
0
and
matching_have_read_book
[
0
]
.
read_status
==
ub
.
ReadBook
.
STATUS_FINISHED
else
:
else
:
try
:
try
:
matching_have_read_book
=
getattr
(
entries
,
'custom_column_'
+
str
(
config
.
config_read_column
))
matching_have_read_book
=
getattr
(
entries
,
'custom_column_'
+
str
(
config
.
config_read_column
))
...
...
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