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
26f314d3
Commit
26f314d3
authored
May 22, 2017
by
nanu-c
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support int custom fields
parent
5f4d8398
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
9 deletions
+37
-9
db.py
cps/db.py
+9
-2
book_edit.html
cps/templates/book_edit.html
+12
-7
web.py
cps/web.py
+16
-0
No files found.
cps/db.py
View file @
26f314d3
...
...
@@ -11,7 +11,7 @@ from ub import config
import
ub
session
=
None
cc_exceptions
=
[
'datetime'
,
'
int'
,
'
comments'
,
'float'
,
'composite'
,
'series'
]
cc_exceptions
=
[
'datetime'
,
'comments'
,
'float'
,
'composite'
,
'series'
]
cc_classes
=
None
engine
=
None
...
...
@@ -335,11 +335,18 @@ def setup_db():
primary_key
=
True
)
)
cc_ids
.
append
([
row
.
id
,
row
.
datatype
])
import
sys
print
>>
sys
.
stderr
,
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
)}
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
)}
else
:
ccdict
=
{
'__tablename__'
:
'custom_column_'
+
str
(
row
.
id
),
'id'
:
Column
(
Integer
,
primary_key
=
True
),
...
...
@@ -347,7 +354,7 @@ def setup_db():
cc_classes
[
row
.
id
]
=
type
(
'Custom_Column_'
+
str
(
row
.
id
),
(
Base
,),
ccdict
)
for
cc_id
in
cc_ids
:
if
cc_id
[
1
]
==
'bool'
:
if
(
cc_id
[
1
]
==
'bool'
)
or
(
cc_id
[
1
]
==
'int'
)
:
setattr
(
Books
,
'custom_column_'
+
str
(
cc_id
[
0
]),
relationship
(
cc_classes
[
cc_id
[
0
]],
primaryjoin
=
(
Books
.
id
==
cc_classes
[
cc_id
[
0
]]
.
book
),
...
...
cps/templates/book_edit.html
View file @
26f314d3
...
...
@@ -68,6 +68,11 @@
<option
value=
"False"
{%
if
book
['
custom_column_
'
~
c
.
id
]|
length
>
0 %}{% if book['custom_column_' ~ c.id][0].value ==false %}selected{% endif %}{% endif %}>{{_('No')}}
</option>
</select>
{% endif %}
{% if c.datatype == 'int' %}
<input
type=
"number"
step=
"1"
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
value=
"{{ book['custom_column_' ~ c.id][0].value }}"
>
{% endif %}
{% if c.datatype in ['text', 'series'] and not c.is_multiple %}
<input
type=
"text"
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
{%
if
book
['
custom_column_
'
~
c
.
id
]|
length
>
0 %}
...
...
cps/web.py
View file @
26f314d3
...
...
@@ -2589,6 +2589,22 @@ def edit_book(book_id):
cc_class
=
db
.
cc_classes
[
c
.
id
]
new_cc
=
cc_class
(
value
=
to_save
[
cc_string
],
book
=
book_id
)
db
.
session
.
add
(
new_cc
)
elif
c
.
datatype
==
'int'
:
if
to_save
[
cc_string
]
==
'None'
:
to_save
[
cc_string
]
=
None
if
to_save
[
cc_string
]
!=
cc_db_value
:
if
cc_db_value
is
not
None
:
if
to_save
[
cc_string
]
is
not
None
:
setattr
(
getattr
(
book
,
cc_string
)[
0
],
'value'
,
to_save
[
cc_string
])
else
:
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
db
.
session
.
delete
(
del_cc
)
else
:
cc_class
=
db
.
cc_classes
[
c
.
id
]
new_cc
=
cc_class
(
value
=
to_save
[
cc_string
],
book
=
book_id
)
db
.
session
.
add
(
new_cc
)
else
:
if
c
.
datatype
==
'rating'
:
to_save
[
cc_string
]
=
str
(
int
(
float
(
to_save
[
cc_string
])
*
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