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
70419865
Commit
70419865
authored
Apr 20, 2016
by
Cervinko Cera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom columns unfinished
parent
202cbc26
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
29 deletions
+93
-29
__init__.py
cps/__init__.py
+0
-1
db.py
cps/db.py
+15
-9
edit_book.html
cps/templates/edit_book.html
+33
-10
web.py
cps/web.py
+45
-9
No files found.
cps/__init__.py
View file @
70419865
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
cps/db.py
View file @
70419865
...
@@ -7,6 +7,7 @@ from sqlalchemy.orm import *
...
@@ -7,6 +7,7 @@ from sqlalchemy.orm import *
import
os
import
os
from
cps
import
config
from
cps
import
config
import
re
import
re
import
ast
#calibre sort stuff
#calibre sort stuff
title_pat
=
re
.
compile
(
config
.
TITLE_REGEX
,
re
.
IGNORECASE
)
title_pat
=
re
.
compile
(
config
.
TITLE_REGEX
,
re
.
IGNORECASE
)
...
@@ -49,11 +50,12 @@ books_languages_link = Table('books_languages_link', Base.metadata,
...
@@ -49,11 +50,12 @@ books_languages_link = Table('books_languages_link', Base.metadata,
Column
(
'lang_code'
,
Integer
,
ForeignKey
(
'languages.id'
),
primary_key
=
True
)
Column
(
'lang_code'
,
Integer
,
ForeignKey
(
'languages.id'
),
primary_key
=
True
)
)
)
cc
=
conn
.
execute
(
"SELECT id FROM custom_columns"
)
cc
=
conn
.
execute
(
"SELECT id
, datatype
FROM custom_columns"
)
cc_ids
=
[]
cc_ids
=
[]
cc_exceptions
=
[
'bool'
,
'datetime'
,
'int'
,
'comments'
,
'float'
,
]
books_custom_column_links
=
{}
books_custom_column_links
=
{}
for
row
in
cc
:
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
,
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
(
'book'
,
Integer
,
ForeignKey
(
'books.id'
),
primary_key
=
True
),
Column
(
'value'
,
Integer
,
ForeignKey
(
'custom_column_'
+
str
(
row
.
id
)
+
'.id'
),
primary_key
=
True
)
Column
(
'value'
,
Integer
,
ForeignKey
(
'custom_column_'
+
str
(
row
.
id
)
+
'.id'
),
primary_key
=
True
)
...
@@ -218,6 +220,10 @@ class Custom_Columns(Base):
...
@@ -218,6 +220,10 @@ class Custom_Columns(Base):
is_multiple
=
Column
(
Boolean
)
is_multiple
=
Column
(
Boolean
)
normalized
=
Column
(
Boolean
)
normalized
=
Column
(
Boolean
)
def
get_display_dict
(
self
):
display_dict
=
ast
.
literal_eval
(
self
.
display
)
return
display_dict
#Base.metadata.create_all(engine)
#Base.metadata.create_all(engine)
Session
=
sessionmaker
()
Session
=
sessionmaker
()
Session
.
configure
(
bind
=
engine
)
Session
.
configure
(
bind
=
engine
)
...
...
cps/templates/edit_book.html
View file @
70419865
...
@@ -47,18 +47,41 @@
...
@@ -47,18 +47,41 @@
{% for c in cc %}
{% for c in cc %}
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"{{ 'custom_column_' ~ c.id }}"
>
{{ c.name }}
</label>
<label
for=
"{{ 'custom_column_' ~ c.id }}"
>
{{ c.name }}
</label>
<input
type=
"text"
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id}} "
id=
"{{ 'custom_column_' ~ c.id }}"
{% if c.datatype in ['text', '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 %}
{%
if
book
['
custom_column_
'
~
c
.
id
]|
length
>
0 %}
{% for column in book['custom_column_' ~ c.id] %}
{% for column in book['custom_column_' ~ c.id] %}
value="{{ column.value }} {% if not loop.last %}, {% endif %}
value="{{ column.value }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}>
{% endfor %}
{% endif %}
"
{% if c.datatype == 'enumeration' %}
<select
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
>
<option></option>
{% for opt in c.get_display_dict().enum_values %}
<option
{%
if
book
['
custom_column_
'
~
c
.
id
]|
length
>
0 %}
{% if book['custom_column_' ~ c.id][0].value == opt %}selected="selected"{% endif %}
{% endif %}
{% endif %}
>
>{{ opt }}
</option>
<br
/>
{% endfor %}
{% endfor %}
</select>
{% endif %}
{% if c.datatype == ('rating' or 'float' or 'int') %}
<input
type=
"number"
{%
if
c
.
datatype =
=
'
rating
'%}
min=
"1"
max=
"5"
{%
endif
%}
{%
if
c
.
datatype
!=
'
float
'
%}
step=
"1"
{%
endif
%}
class=
"form-control"
name=
"{{ 'custom_column_' ~ c.id }}"
id=
"{{ 'custom_column_' ~ c.id }}"
{%
if
book
['
custom_column_
'
~
c
.
id
]|
length
>
0 %}
{% for column in book['custom_column_' ~ c.id] %}
value="{{ column.value }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}>
{% endif %}
</div>
</div>
</p>
{% endfor %}
{% endif %}
{% endif %}
...
...
cps/web.py
View file @
70419865
...
@@ -316,7 +316,9 @@ def discover(page):
...
@@ -316,7 +316,9 @@ def discover(page):
@
app
.
route
(
"/book/<int:id>"
)
@
app
.
route
(
"/book/<int:id>"
)
def
show_book
(
id
):
def
show_book
(
id
):
entries
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
id
)
.
first
()
entries
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
id
)
.
first
()
cc
=
db
.
session
.
query
(
db
.
Custom_Columns
)
.
all
()
cc
=
db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
all
()
for
c
in
cc
:
print
c
.
name
#print entries.custom_column_1
#print entries.custom_column_1
#helper.get_custom_columns(entries.id)
#helper.get_custom_columns(entries.id)
book_in_shelfs
=
[]
book_in_shelfs
=
[]
...
@@ -697,7 +699,9 @@ def edit_user(user_id):
...
@@ -697,7 +699,9 @@ def edit_user(user_id):
def
edit_book
(
book_id
):
def
edit_book
(
book_id
):
## create the function for sorting...
## create the function for sorting...
db
.
session
.
connection
()
.
connection
.
connection
.
create_function
(
"title_sort"
,
1
,
db
.
title_sort
)
db
.
session
.
connection
()
.
connection
.
connection
.
create_function
(
"title_sort"
,
1
,
db
.
title_sort
)
cc
=
db
.
session
.
query
(
db
.
Custom_Columns
)
.
all
()
cc
=
db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
all
()
for
c
in
cc
:
print
c
.
name
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
first
()
author_names
=
[]
author_names
=
[]
for
author
in
book
.
authors
:
for
author
in
book
.
authors
:
...
@@ -744,12 +748,12 @@ def edit_book(book_id):
...
@@ -744,12 +748,12 @@ def edit_book(book_id):
if
len
(
add_authors
)
>
0
:
if
len
(
add_authors
)
>
0
:
for
add_author
in
add_authors
:
for
add_author
in
add_authors
:
# check if an author with that name exists
# check if an author with that name exists
t_author
=
db
.
session
.
query
(
db
.
Authors
)
.
filter
(
db
.
Authors
.
name
==
add_author
)
.
first
()
;
t_author
=
db
.
session
.
query
(
db
.
Authors
)
.
filter
(
db
.
Authors
.
name
==
add_author
)
.
first
()
# if no author is found add it
# if no author is found add it
if
t_author
==
None
:
if
t_author
==
None
:
new_author
=
db
.
Authors
(
add_author
,
add_author
,
""
)
new_author
=
db
.
Authors
(
add_author
,
add_author
,
""
)
db
.
session
.
add
(
new_author
)
db
.
session
.
add
(
new_author
)
t_author
=
db
.
session
.
query
(
db
.
Authors
)
.
filter
(
db
.
Authors
.
name
==
add_author
)
.
first
()
;
t_author
=
db
.
session
.
query
(
db
.
Authors
)
.
filter
(
db
.
Authors
.
name
==
add_author
)
.
first
()
# add author to book
# add author to book
book
.
authors
.
append
(
t_author
)
book
.
authors
.
append
(
t_author
)
if
author0_before_edit
!=
book
.
authors
[
0
]
.
name
:
if
author0_before_edit
!=
book
.
authors
[
0
]
.
name
:
...
@@ -803,12 +807,12 @@ def edit_book(book_id):
...
@@ -803,12 +807,12 @@ def edit_book(book_id):
if
len
(
add_tags
)
>
0
:
if
len
(
add_tags
)
>
0
:
for
add_tag
in
add_tags
:
for
add_tag
in
add_tags
:
# check if a tag with that name exists
# check if a tag with that name exists
new_tag
=
db
.
session
.
query
(
db
.
Tags
)
.
filter
(
db
.
Tags
.
name
==
add_tag
)
.
first
()
;
new_tag
=
db
.
session
.
query
(
db
.
Tags
)
.
filter
(
db
.
Tags
.
name
==
add_tag
)
.
first
()
# if no tag is found add it
# if no tag is found add it
if
new_tag
==
None
:
if
new_tag
==
None
:
new_tag
=
db
.
Tags
(
add_tag
)
new_tag
=
db
.
Tags
(
add_tag
)
db
.
session
.
add
(
new_tag
)
db
.
session
.
add
(
new_tag
)
new_tag
=
db
.
session
.
query
(
db
.
Tags
)
.
filter
(
db
.
Tags
.
name
==
add_tag
)
.
first
()
;
new_tag
=
db
.
session
.
query
(
db
.
Tags
)
.
filter
(
db
.
Tags
.
name
==
add_tag
)
.
first
()
# add tag to book
# add tag to book
book
.
tags
.
append
(
new_tag
)
book
.
tags
.
append
(
new_tag
)
...
@@ -826,6 +830,38 @@ def edit_book(book_id):
...
@@ -826,6 +830,38 @@ def edit_book(book_id):
else
:
else
:
new_rating
=
db
.
Ratings
(
rating
=
int
(
to_save
[
"rating"
]
.
strip
()))
new_rating
=
db
.
Ratings
(
rating
=
int
(
to_save
[
"rating"
]
.
strip
()))
book
.
ratings
[
0
]
=
new_rating
book
.
ratings
[
0
]
=
new_rating
for
c
in
cc
:
cc_string
=
"custom_column_"
+
str
(
c
.
id
)
if
len
(
getattr
(
book
,
cc_string
))
>
0
:
cc_db_value
=
getattr
(
book
,
cc_string
)[
0
]
.
value
else
:
cc_db_value
=
None
if
to_save
[
cc_string
]
.
strip
():
if
to_save
[
cc_string
]
.
strip
()
!=
cc_db_value
:
if
cc_db_value
!=
None
:
#remove old cc_val
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
if
len
(
del_cc
.
books
)
==
0
:
db
.
session
.
delete
(
del_cc
)
cc_class
=
db
.
cc_classes
[
c
.
id
]
new_cc
=
db
.
session
.
query
(
cc_class
)
.
filter
(
cc_class
.
value
==
to_save
[
cc_string
]
.
strip
())
.
first
()
# if no cc val is found add it
if
new_cc
==
None
:
new_cc
=
cc_class
(
value
=
to_save
[
cc_string
]
.
strip
())
db
.
session
.
add
(
new_cc
)
new_cc
=
db
.
session
.
query
(
cc_class
)
.
filter
(
cc_class
.
value
==
to_save
[
cc_string
]
.
strip
())
.
first
()
# add cc value to book
getattr
(
book
,
cc_string
)
.
append
(
new_cc
)
else
:
if
cc_db_value
!=
None
:
#remove old cc_val
del_cc
=
getattr
(
book
,
cc_string
)[
0
]
getattr
(
book
,
cc_string
)
.
remove
(
del_cc
)
if
len
(
del_cc
.
books
)
==
0
:
db
.
session
.
delete
(
del_cc
)
db
.
session
.
commit
()
db
.
session
.
commit
()
author_names
=
[]
author_names
=
[]
for
author
in
book
.
authors
:
for
author
in
book
.
authors
:
...
@@ -905,5 +941,5 @@ def upload():
...
@@ -905,5 +941,5 @@ def upload():
author_names
=
[]
author_names
=
[]
for
author
in
db_book
.
authors
:
for
author
in
db_book
.
authors
:
author_names
.
append
(
author
.
name
)
author_names
.
append
(
author
.
name
)
cc
=
db
.
session
.
query
(
db
.
Custom_Columns
)
.
filter
(
db
.
Custom_Columns
.
datatype
.
notin_
(
db
.
cc_exceptions
))
.
all
()
return
render_template
(
'edit_book.html'
,
book
=
db_book
,
authors
=
author_names
)
return
render_template
(
'edit_book.html'
,
book
=
db_book
,
authors
=
author_names
,
cc
=
cc
)
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