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
cc0b0196
Commit
cc0b0196
authored
Sep 27, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store UI settings in flask session for guest user
parent
6dfa171b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
21 deletions
+25
-21
filter_grid.js
cps/static/js/filter_grid.js
+2
-0
ub.py
cps/ub.py
+19
-6
web.py
cps/web.py
+4
-15
No files found.
cps/static/js/filter_grid.js
View file @
cc0b0196
...
...
@@ -24,6 +24,7 @@ var $list = $("#list").isotope({
});
$
(
"#desc"
).
click
(
function
()
{
var
page
=
$
(
this
).
data
(
"id"
);
$
.
ajax
({
method
:
"post"
,
contentType
:
"application/json; charset=utf-8"
,
...
...
@@ -39,6 +40,7 @@ $("#desc").click(function() {
});
$
(
"#asc"
).
click
(
function
()
{
var
page
=
$
(
this
).
data
(
"id"
);
$
.
ajax
({
method
:
"post"
,
contentType
:
"application/json; charset=utf-8"
,
...
...
cps/ub.py
View file @
cc0b0196
...
...
@@ -23,7 +23,7 @@ import sys
import
datetime
import
itertools
import
uuid
import
js
on
from
flask
import
session
as
flask_sessi
on
from
binascii
import
hexlify
from
flask
import
g
...
...
@@ -71,15 +71,16 @@ def get_sidebar_config(kwargs=None):
"visibility"
:
constants
.
SIDEBAR_HOT
,
'public'
:
True
,
"page"
:
"hot"
,
"show_text"
:
_
(
'Show Hot Books'
),
"config_show"
:
True
})
sidebar
.
append
({
"glyph"
:
"glyphicon-download"
,
"text"
:
_
(
'Downloaded Books'
),
"link"
:
'web.books_list'
,
"id"
:
"download"
,
"visibility"
:
constants
.
SIDEBAR_DOWNLOAD
,
'public'
:
True
,
"page"
:
"download"
,
"show_text"
:
_
(
'Show Downloaded Books'
),
"config_show"
:
True
})
"id"
:
"download"
,
"visibility"
:
constants
.
SIDEBAR_DOWNLOAD
,
'public'
:
(
not
g
.
user
.
is_anonymous
),
"page"
:
"download"
,
"show_text"
:
_
(
'Show Downloaded Books'
),
"config_show"
:
content
})
sidebar
.
append
(
{
"glyph"
:
"glyphicon-star"
,
"text"
:
_
(
'Top Rated Books'
),
"link"
:
'web.books_list'
,
"id"
:
"rated"
,
"visibility"
:
constants
.
SIDEBAR_BEST_RATED
,
'public'
:
True
,
"page"
:
"rated"
,
"show_text"
:
_
(
'Show Top Rated Books'
),
"config_show"
:
True
})
sidebar
.
append
({
"glyph"
:
"glyphicon-eye-open"
,
"text"
:
_
(
'Read Books'
),
"link"
:
'web.books_list'
,
"id"
:
"read"
,
"visibility"
:
constants
.
SIDEBAR_READ_AND_UNREAD
,
'public'
:
(
not
g
.
user
.
is_anonymous
),
"page"
:
"read"
,
"show_text"
:
_
(
'Show read and unread'
),
"config_show"
:
content
})
"visibility"
:
constants
.
SIDEBAR_READ_AND_UNREAD
,
'public'
:
(
not
g
.
user
.
is_anonymous
),
"
page"
:
"read"
,
"
show_text"
:
_
(
'Show read and unread'
),
"config_show"
:
content
})
sidebar
.
append
(
{
"glyph"
:
"glyphicon-eye-close"
,
"text"
:
_
(
'Unread Books'
),
"link"
:
'web.books_list'
,
"id"
:
"unread"
,
"visibility"
:
constants
.
SIDEBAR_READ_AND_UNREAD
,
'public'
:
(
not
g
.
user
.
is_anonymous
),
"page"
:
"unread"
,
...
...
@@ -242,7 +243,6 @@ class User(UserBase, Base):
denied_column_value
=
Column
(
String
,
default
=
""
)
allowed_column_value
=
Column
(
String
,
default
=
""
)
remote_auth_token
=
relationship
(
'RemoteAuthToken'
,
backref
=
'user'
,
lazy
=
'dynamic'
)
#series_view = Column(String(10), default="list")
view_settings
=
Column
(
JSON
,
default
=
{})
...
...
@@ -286,6 +286,9 @@ class Anonymous(AnonymousUserMixin, UserBase):
self
.
denied_column_value
=
data
.
denied_column_value
self
.
allowed_column_value
=
data
.
allowed_column_value
self
.
view_settings
=
data
.
view_settings
# Initialize flask_session once
if
'view'
not
in
flask_session
:
flask_session
[
'view'
]
=
{}
def
role_admin
(
self
):
...
...
@@ -303,6 +306,16 @@ class Anonymous(AnonymousUserMixin, UserBase):
def
is_authenticated
(
self
):
return
False
def
get_view_property
(
self
,
page
,
prop
):
if
not
flask_session
[
'view'
]
.
get
(
page
):
return
None
return
flask_session
[
'view'
][
page
]
.
get
(
prop
)
def
set_view_property
(
self
,
page
,
prop
,
value
):
if
not
flask_session
[
'view'
]
.
get
(
page
):
flask_session
[
'view'
][
page
]
=
dict
()
flask_session
[
'view'
][
page
][
prop
]
=
value
# Baseclass representing Shelfs in calibre-web in app.db
class
Shelf
(
Base
):
...
...
cps/web.py
View file @
cc0b0196
...
...
@@ -234,9 +234,8 @@ def admin_required(f):
def
unconfigured
(
f
):
"""
Checks if c
urrent_user.role == 1
Checks if c
alibre-web instance is not configured
"""
@
wraps
(
f
)
def
inner
(
*
args
,
**
kwargs
):
if
not
config
.
db_configured
:
...
...
@@ -464,25 +463,15 @@ def toggle_archived(book_id):
@
web
.
route
(
"/ajax/view"
,
methods
=
[
"POST"
])
@
login_required
@
login_required
_if_no_ano
def
update_view
():
to_save
=
request
.
get_json
()
try
:
for
element
in
to_save
:
if
not
current_user
.
view_settings
.
get
(
element
):
current_user
.
view_settings
[
element
]
=
dict
()
for
param
in
to_save
[
element
]:
current_user
.
view_settings
[
element
][
param
]
=
to_save
[
element
][
param
]
try
:
flag_modified
(
current_user
,
"view_settings"
)
except
AttributeError
:
pass
ub
.
session
.
commit
()
except
InvalidRequestError
:
log
.
error
(
"Invalid request received:
%
r "
,
request
,
)
return
"Invalid request"
,
400
current_user
.
set_view_property
(
element
,
param
,
to_save
[
element
][
param
])
except
Exception
as
e
:
log
.
error
(
"Could not save
series_view_settings:
%
r
%
r"
,
request
,
to_sav
e
)
log
.
error
(
"Could not save
view_settings:
%
r
%
r: e"
,
request
,
to_save
,
e
)
return
"Invalid request"
,
400
return
"1"
,
200
...
...
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