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
f87800d1
Commit
f87800d1
authored
Sep 16, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'meta/upload_new_format_of_existing_book'
parents
7acf4d40
8937599b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
2 deletions
+57
-2
style.css
cps/static/css/style.css
+6
-0
edit_books.js
cps/static/js/edit_books.js
+8
-0
book_edit.html
cps/templates/book_edit.html
+10
-2
messages.po
cps/translations/es/LC_MESSAGES/messages.po
+4
-0
web.py
cps/web.py
+29
-0
No files found.
cps/static/css/style.css
View file @
f87800d1
...
@@ -90,3 +90,9 @@ input.pill:not(:checked) + label .glyphicon {
...
@@ -90,3 +90,9 @@ input.pill:not(:checked) + label .glyphicon {
#meta-info
img
{
max-height
:
150px
;
max-width
:
100px
;
cursor
:
pointer
;
}
#meta-info
img
{
max-height
:
150px
;
max-width
:
100px
;
cursor
:
pointer
;
}
.padded-bottom
{
margin-bottom
:
15px
;
}
.padded-bottom
{
margin-bottom
:
15px
;
}
.upload-format-input-text
{
display
:
initial
;}
#btn-upload-format
{
display
:
none
;}
.upload-format-input-text
{
display
:
initial
;}
#btn-upload-format
{
display
:
none
;}
cps/static/js/edit_books.js
View file @
f87800d1
...
@@ -205,3 +205,11 @@ $("#search").on("change input.typeahead:selected", function() {
...
@@ -205,3 +205,11 @@ $("#search").on("change input.typeahead:selected", function() {
});
});
});
});
});
});
$
(
"#btn-upload-format"
).
on
(
"change"
,
function
()
{
var
filename
=
$
(
this
).
val
();
if
(
filename
.
substring
(
3
,
11
)
===
"fakepath"
)
{
filename
=
filename
.
substring
(
12
);
}
// Remove c:\fake at beginning from localhost chrome
$
(
"#upload-format"
).
html
(
filename
);
});
cps/templates/book_edit.html
View file @
f87800d1
{% extends "layout.html" %}
{% extends "layout.html" %}
{% block body %}
{% block body %}
{% if book %}
{% if book %}
<form
role=
"form"
action=
"{{ url_for('edit_book', book_id=book.id) }}"
method=
"post"
>
<form
role=
"form"
action=
"{{ url_for('edit_book', book_id=book.id) }}"
method=
"post"
enctype=
"multipart/form-data"
>
<div
class=
"col-sm-3 col-lg-3 col-xs-12"
>
<div
class=
"col-sm-3 col-lg-3 col-xs-12"
>
<div
class=
"cover"
>
<div
class=
"cover"
>
...
@@ -115,7 +115,15 @@
...
@@ -115,7 +115,15 @@
</div>
</div>
{% endfor %}
{% endfor %}
{% endif %}
{% endif %}
{% if g.user.role_upload() or g.user.role_admin()%}
{% if g.allow_upload %}
<div
role=
"group"
aria-label=
"Upload new book format"
>
<label
class=
"btn btn-default btn-file"
for=
"btn-upload-format"
>
{{ _('Upload format') }}
</label>
<div
class=
"upload-format-input-text"
id=
"upload-format"
></div>
<input
id=
"btn-upload-format"
name=
"btn-upload-format"
type=
"file"
>
</div>
{% endif %}
{% endif %}
<div
class=
"checkbox"
>
<div
class=
"checkbox"
>
<label>
<label>
...
...
cps/translations/es/LC_MESSAGES/messages.po
View file @
f87800d1
...
@@ -475,6 +475,10 @@ msgstr "Descarga"
...
@@ -475,6 +475,10 @@ msgstr "Descarga"
msgid "Upload"
msgid "Upload"
msgstr "Subir archivo"
msgstr "Subir archivo"
#: cps/templates/detail.html:14
msgid "Upload format"
msgstr "Subir formato"
#: cps/templates/admin.html:15
#: cps/templates/admin.html:15
msgid "Edit"
msgid "Edit"
msgstr "Editar"
msgstr "Editar"
...
...
cps/web.py
View file @
f87800d1
...
@@ -2746,6 +2746,35 @@ def edit_book(book_id):
...
@@ -2746,6 +2746,35 @@ def edit_book(book_id):
# Update book
# Update book
edited_books_id
=
set
()
edited_books_id
=
set
()
# Check and handle Uploaded file
if
'btn-upload-format'
in
request
.
files
and
'.'
in
request
.
files
[
'btn-upload-format'
]
.
filename
:
requested_file
=
request
.
files
[
'btn-upload-format'
]
file_ext
=
requested_file
.
filename
.
rsplit
(
'.'
,
1
)[
-
1
]
.
lower
()
if
file_ext
not
in
ALLOWED_EXTENSIONS
:
flash
(
_
(
'File extension "
%
s" is not allowed to be uploaded to this server'
%
file_ext
),
category
=
"error"
)
return
redirect
(
url_for
(
'index'
))
file_name
=
book
.
path
.
rsplit
(
'/'
,
1
)[
-
1
]
filepath
=
config
.
config_calibre_dir
+
os
.
sep
+
book
.
path
filepath
=
os
.
path
.
normpath
(
filepath
)
saved_filename
=
filepath
+
os
.
sep
+
file_name
+
'.'
+
file_ext
try
:
requested_file
.
save
(
saved_filename
)
except
OSError
:
flash
(
_
(
u"Failed to store file
%
s."
%
saved_filename
),
category
=
"error"
)
return
redirect
(
url_for
(
'index'
))
file_size
=
os
.
path
.
getsize
(
saved_filename
)
is_format
=
db
.
session
.
query
(
db
.
Data
)
.
filter
(
db
.
Data
.
book
==
book_id
)
.
filter
(
db
.
Data
.
format
==
file_ext
.
upper
())
.
first
()
if
is_format
:
# Format entry already exists, no need to update the database
pass
else
:
db_format
=
db
.
Data
(
book_id
,
file_ext
.
upper
(),
file_size
,
file_name
)
db
.
session
.
add
(
db_format
)
to_save
=
request
.
form
.
to_dict
()
to_save
=
request
.
form
.
to_dict
()
if
book
.
title
!=
to_save
[
"book_title"
]:
if
book
.
title
!=
to_save
[
"book_title"
]:
book
.
title
=
to_save
[
"book_title"
]
book
.
title
=
to_save
[
"book_title"
]
...
...
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