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
94ad93eb
Commit
94ad93eb
authored
Jul 25, 2020
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added series like custom columns #1501
parent
b309c1fc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
34 deletions
+64
-34
db.py
cps/db.py
+45
-27
jinjia.py
cps/jinjia.py
+7
-0
book_edit.html
cps/templates/book_edit.html
+6
-5
detail.html
cps/templates/detail.html
+6
-2
No files found.
cps/db.py
View file @
94ad93eb
...
...
@@ -34,6 +34,7 @@ from sqlalchemy.ext.declarative import declarative_base
from
sqlalchemy.exc
import
OperationalError
from
flask_login
import
current_user
from
sqlalchemy.sql.expression
import
and_
,
true
,
false
,
text
,
func
,
or_
from
sqlalchemy.ext.associationproxy
import
association_proxy
from
babel
import
Locale
as
LC
from
babel.core
import
UnknownLocaleError
from
flask_babel
import
gettext
as
_
...
...
@@ -48,7 +49,7 @@ except ImportError:
use_unidecode
=
False
cc_exceptions
=
[
'datetime'
,
'comments'
,
'composite'
,
'series'
]
cc_exceptions
=
[
'datetime'
,
'comments'
,
'composite'
]
cc_classes
=
{}
Base
=
declarative_base
()
...
...
@@ -280,7 +281,7 @@ class Books(Base):
flags
=
Column
(
Integer
,
nullable
=
False
,
default
=
1
)
authors
=
relationship
(
'Authors'
,
secondary
=
books_authors_link
,
backref
=
'books'
)
tags
=
relationship
(
'Tags'
,
secondary
=
books_tags_link
,
backref
=
'books'
,
order_by
=
"Tags.name"
)
tags
=
relationship
(
'Tags'
,
secondary
=
books_tags_link
,
backref
=
'books'
,
order_by
=
"Tags.name"
)
comments
=
relationship
(
'Comments'
,
backref
=
'books'
)
data
=
relationship
(
'Data'
,
backref
=
'books'
)
series
=
relationship
(
'Series'
,
secondary
=
books_series_link
,
backref
=
'books'
)
...
...
@@ -406,33 +407,45 @@ class CalibreDB(threading.Thread):
books_custom_column_links
=
{}
for
row
in
cc
:
if
row
.
datatype
not
in
cc_exceptions
:
books_custom_column_links
[
row
.
id
]
=
Table
(
'books_custom_column_'
+
str
(
row
.
id
)
+
'_link'
,
Base
.
metadata
,
Column
(
'book'
,
Integer
,
ForeignKey
(
'books.id'
),
primary_key
=
True
),
Column
(
'value'
,
Integer
,
ForeignKey
(
'custom_column_'
+
str
(
row
.
id
)
+
'.id'
),
primary_key
=
True
)
)
if
row
.
datatype
==
'series'
:
dicttable
=
{
'__tablename__'
:
'books_custom_column_'
+
str
(
row
.
id
)
+
'_link'
,
'id'
:
Column
(
Integer
,
primary_key
=
True
),
'book'
:
Column
(
Integer
,
ForeignKey
(
'books.id'
),
primary_key
=
True
),
'map_value'
:
Column
(
'value'
,
Integer
,
ForeignKey
(
'custom_column_'
+
str
(
row
.
id
)
+
'.id'
),
primary_key
=
True
),
'extra'
:
Column
(
Float
),
'asoc'
:
relationship
(
'Custom_Column_'
+
str
(
row
.
id
),
uselist
=
False
),
'value'
:
association_proxy
(
'asoc'
,
'value'
)
}
books_custom_column_links
[
row
.
id
]
=
type
(
str
(
'Books_Custom_Column_'
+
str
(
row
.
id
)
+
'_link'
),
(
Base
,),
dicttable
)
else
:
books_custom_column_links
[
row
.
id
]
=
Table
(
'books_custom_column_'
+
str
(
row
.
id
)
+
'_link'
,
Base
.
metadata
,
Column
(
'book'
,
Integer
,
ForeignKey
(
'books.id'
),
primary_key
=
True
),
Column
(
'value'
,
Integer
,
ForeignKey
(
'custom_column_'
+
str
(
row
.
id
)
+
'.id'
),
primary_key
=
True
)
)
cc_ids
.
append
([
row
.
id
,
row
.
datatype
])
if
row
.
datatype
==
'bool'
:
ccdict
=
{
'__tablename__'
:
'custom_column_'
+
str
(
row
.
id
),
'id'
:
Column
(
Integer
,
primary_key
=
True
),
'book'
:
Column
(
Integer
,
ForeignKey
(
'books.id'
)),
'value'
:
Column
(
Boolean
)}
ccdict
=
{
'__tablename__'
:
'custom_column_'
+
str
(
row
.
id
),
'id'
:
Column
(
Integer
,
primary_key
=
True
)}
if
row
.
datatype
==
'float'
:
ccdict
[
'value'
]
=
Column
(
Float
)
elif
row
.
datatype
==
'int'
:
ccdict
=
{
'__tablename__'
:
'custom_column_'
+
str
(
row
.
id
),
'id'
:
Column
(
Integer
,
primary_key
=
True
),
'book'
:
Column
(
Integer
,
ForeignKey
(
'books.id'
)),
'value'
:
Column
(
Integer
)}
elif
row
.
datatype
==
'float'
:
ccdict
=
{
'__tablename__'
:
'custom_column_'
+
str
(
row
.
id
),
'id'
:
Column
(
Integer
,
primary_key
=
True
),
'book'
:
Column
(
Integer
,
ForeignKey
(
'books.id'
)),
'value'
:
Column
(
Float
)}
ccdict
[
'value'
]
=
Column
(
Integer
)
elif
row
.
datatype
==
'bool'
:
ccdict
[
'value'
]
=
Column
(
Boolean
)
else
:
ccdict
=
{
'__tablename__'
:
'custom_column_'
+
str
(
row
.
id
),
'id'
:
Column
(
Integer
,
primary_key
=
True
),
'value'
:
Column
(
String
)}
ccdict
[
'value'
]
=
Column
(
String
)
if
row
.
datatype
in
[
'float'
,
'int'
,
'bool'
]:
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
:
...
...
@@ -440,9 +453,14 @@ class CalibreDB(threading.Thread):
setattr
(
Books
,
'custom_column_'
+
str
(
cc_id
[
0
]),
relationship
(
cc_classes
[
cc_id
[
0
]],
primaryjoin
=
(
primaryjoin
=
(
# ToDo: Check Remove
Books
.
id
==
cc_classes
[
cc_id
[
0
]]
.
book
),
backref
=
'books'
))
elif
(
cc_id
[
1
]
==
'series'
):
setattr
(
Books
,
'custom_column_'
+
str
(
cc_id
[
0
]),
relationship
(
books_custom_column_links
[
cc_id
[
0
]],
backref
=
'books'
))
else
:
setattr
(
Books
,
'custom_column_'
+
str
(
cc_id
[
0
]),
...
...
cps/jinjia.py
View file @
94ad93eb
...
...
@@ -111,3 +111,10 @@ def timestamptodate(date, fmt=None):
@
jinjia
.
app_template_filter
(
'yesno'
)
def
yesno
(
value
,
yes
,
no
):
return
yes
if
value
else
no
@
jinjia
.
app_template_filter
(
'formatfloat'
)
def
formatfloat
(
value
,
decimals
=
1
):
formatedstring
=
'
%
d'
%
value
if
(
value
%
1
)
!=
0
:
formatedstring
=
(
'
%
s.
%
d'
%
(
formatedstring
,
(
value
%
1
)
*
10
**
decimals
))
.
rstrip
(
'0'
)
return
formatedstring
cps/templates/book_edit.html
View file @
94ad93eb
...
...
@@ -132,19 +132,20 @@
<input
type=
"number"
step=
"{% if c.datatype == 'float' %}0.01{% else %}1{% endif %}"
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
value=
"{% if book['custom_column_' ~ c.id]|length > 0 %}{{ book['custom_column_' ~ c.id][0].value }}{% endif %}"
>
{% endif %}
{% if c.datatype
in ['text', 'series'] and not c.is_multiple
%}
{% if c.datatype
== 'text'
%}
<input
type=
"text"
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
{%
if
book
['
custom_column_
'
~
c
.
id
]|
length
>
0 %}
value="{{ book['custom_column_' ~ c.id][0].value }}"
{% endif %}>
value="{% for column in book['custom_column_' ~ c.id] %}{{ column.value.strip() }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}>
{% endif %}
{% if c.datatype
in ['text', 'series'] and c.is_multiple
%}
{% if c.datatype
== 'series'
%}
<input
type=
"text"
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
{%
if
book
['
custom_column_
'
~
c
.
id
]|
length
>
0 %}
value="{% for column in book['custom_column_' ~ c.id] %}{{ column.value.strip() }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}>
value="{% for column in book['custom_column_' ~ c.id] %} {{ '%s [%s]' % (book['custom_column_' ~ c.id][0].value, book['custom_column_' ~ c.id][0].extra|formatfloat(2)) }}{% if not loop.last %}, {% endif %}{% endfor %}"
{% endif %}>
{% endif %}
{% if c.datatype == 'enumeration' %}
<select
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
>
<option></option>
...
...
cps/templates/detail.html
View file @
94ad93eb
...
...
@@ -174,7 +174,7 @@
{{ c.name }}:
{% for column in entry['custom_column_' ~ c.id] %}
{% if c.datatype == 'rating' %}
{{
'%d' % (column.value / 2) }}{% if ((column.value /2) % 1) != 0 %}{{ '.%d' % (((column.value /2) % 1)*10) }} {% endif %
}
{{
(column.value / 2)|formatfloat }
}
{% else %}
{% if c.datatype == 'bool' %}
{% if column.value == true %}
...
...
@@ -184,11 +184,15 @@
{% endif %}
{% else %}
{% if c.datatype == 'float' %}
{{ '%d' % (column.value) }}{% if (column.value % 1) != 0 %}{{ '.%d' % ((column.value % 1)*100) }} {% endif %}
{{ column.value|formatfloat(2) }}
{% else %}
{% if c.datatype == 'series' %}
{{ '%s [%s]' % (column.value, column.extra|formatfloat(2)) }}
{% else %}
{{ column.value }}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
...
...
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