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
b0cc52e0
Commit
b0cc52e0
authored
May 13, 2021
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable custom column datetime (adv. search not working yet) #1984
parent
9ef70565
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
10 deletions
+29
-10
db.py
cps/db.py
+6
-4
editbooks.py
cps/editbooks.py
+6
-1
edit_books.js
cps/static/js/edit_books.js
+1
-5
book_edit.html
cps/templates/book_edit.html
+14
-0
detail.html
cps/templates/detail.html
+2
-0
No files found.
cps/db.py
View file @
b0cc52e0
...
...
@@ -59,7 +59,7 @@ except ImportError:
log
=
logger
.
create
()
cc_exceptions
=
[
'
datetime'
,
'
comments'
,
'composite'
,
'series'
]
cc_exceptions
=
[
'comments'
,
'composite'
,
'series'
]
cc_classes
=
{}
Base
=
declarative_base
()
...
...
@@ -491,23 +491,25 @@ class CalibreDB():
ccdict
[
'value'
]
=
Column
(
Float
)
elif
row
.
datatype
==
'int'
:
ccdict
[
'value'
]
=
Column
(
Integer
)
elif
row
.
datatype
==
'datetime'
:
ccdict
[
'value'
]
=
Column
(
TIMESTAMP
)
elif
row
.
datatype
==
'bool'
:
ccdict
[
'value'
]
=
Column
(
Boolean
)
else
:
ccdict
[
'value'
]
=
Column
(
String
)
if
row
.
datatype
in
[
'float'
,
'int'
,
'bool'
]:
if
row
.
datatype
in
[
'float'
,
'int'
,
'bool'
,
'datetime'
]:
ccdict
[
'book'
]
=
Column
(
Integer
,
ForeignKey
(
'books.id'
))
cc_classes
[
row
.
id
]
=
type
(
str
(
'custom_column_'
+
str
(
row
.
id
)),
(
Base
,),
ccdict
)
for
cc_id
in
cc_ids
:
if
(
cc_id
[
1
]
==
'bool'
)
or
(
cc_id
[
1
]
==
'int'
)
or
(
cc_id
[
1
]
==
'float'
)
:
if
cc_id
[
1
]
in
[
'bool'
,
'int'
,
'float'
,
'datetime'
]
:
setattr
(
Books
,
'custom_column_'
+
str
(
cc_id
[
0
]),
relationship
(
cc_classes
[
cc_id
[
0
]],
primaryjoin
=
(
Books
.
id
==
cc_classes
[
cc_id
[
0
]]
.
book
),
backref
=
'books'
))
elif
(
cc_id
[
1
]
==
'series'
)
:
elif
cc_id
[
1
]
==
'series'
:
setattr
(
Books
,
'custom_column_'
+
str
(
cc_id
[
0
]),
relationship
(
books_custom_column_links
[
cc_id
[
0
]],
...
...
cps/editbooks.py
View file @
b0cc52e0
...
...
@@ -501,6 +501,11 @@ def edit_cc_data_number(book_id, book, c, to_save, cc_db_value, cc_string):
to_save
[
cc_string
]
=
None
elif
c
.
datatype
==
'bool'
:
to_save
[
cc_string
]
=
1
if
to_save
[
cc_string
]
==
'True'
else
0
elif
c
.
datatype
==
'datetime'
:
try
:
to_save
[
cc_string
]
=
datetime
.
strptime
(
to_save
[
cc_string
],
"
%
Y-
%
m-
%
d"
)
except
ValueError
:
to_save
[
cc_string
]
=
db
.
Books
.
DEFAULT_PUBDATE
if
to_save
[
cc_string
]
!=
cc_db_value
:
if
cc_db_value
is
not
None
:
...
...
@@ -559,7 +564,7 @@ def edit_cc_data(book_id, book, to_save):
else
:
cc_db_value
=
None
if
to_save
[
cc_string
]
.
strip
():
if
c
.
datatype
==
'int'
or
c
.
datatype
==
'bool'
or
c
.
datatype
==
'float'
:
if
c
.
datatype
in
[
'int'
,
'bool'
,
'float'
,
"datetime"
]
:
changed
,
to_save
=
edit_cc_data_number
(
book_id
,
book
,
c
,
to_save
,
cc_db_value
,
cc_string
)
else
:
changed
,
to_save
=
edit_cc_data_string
(
book
,
c
,
to_save
,
cc_db_value
,
cc_string
)
...
...
cps/static/js/edit_books.js
View file @
b0cc52e0
...
...
@@ -63,6 +63,7 @@ if (!Modernizr.inputtypes.date) {
}).
trigger
(
"change"
);
}
/*
Takes a prefix, query typeahead callback, Bloodhound typeahead adapter
and returns the completions it gets from the bloodhound engine prefixed.
...
...
@@ -78,11 +79,6 @@ function prefixedSource(prefix, query, cb, bhAdapter) {
});
}
/*function getPath() {
var jsFileLocation = $("script[src*=edit_books]").attr("src"); // the js file path
return jsFileLocation.substr(0, jsFileLocation.search("/static/js/edit_books.js")); // the js folder path
}*/
var
authors
=
new
Bloodhound
({
name
:
"authors"
,
datumTokenizer
:
function
datumTokenizer
(
datum
)
{
...
...
cps/templates/book_edit.html
View file @
b0cc52e0
...
...
@@ -149,6 +149,20 @@
{% endif %}>
{% endif %}
{% if c.datatype == 'datetime' %}
<div
style=
"position: relative"
>
<input
type=
"date"
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
{%
if
book
['
custom_column_
'
~
c
.
id
]|
length
>
0 %}
value="{% if book['custom_column_' ~ c.id][0].value %}{{ book['custom_column_' ~ c.id][0].value|formatdateinput}}{% endif %}"
{% endif %}>
<input
type=
"text"
class=
"fake_custom_column_{{ c.id }} form-control fake-input hidden "
{%
if
book
['
custom_column_
'
~
c
.
id
]|
length
>
0 %}
value="{% if book['custom_column_' ~ c.id][0].value %}{{book['custom_column_' ~ c.id][0].value|formatdate}}{% endif %}"
{% endif %}>
</div>
{% endif %}
{% if c.datatype == 'enumeration' %}
<select
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
>
...
...
cps/templates/detail.html
View file @
b0cc52e0
...
...
@@ -193,6 +193,8 @@
{% else %}
{% if c.datatype == 'float' %}
{{ column.value|formatfloat(2) }}
{% elif c.datatype == 'datetime' %}
{{ column.value|formatdate }}
{% else %}
{% if c.datatype == 'series' %}
{{ '%s [%s]' % (column.value, column.extra|formatfloat(2)) }}
...
...
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