Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
38130f3a
Commit
38130f3a
authored
Oct 30, 2020
by
Arief Pratama
Browse files
Add default book cover
parent
05ee0d76
Pipeline
#59997
passed with stages
in 27 minutes and 31 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/services.py
View file @
38130f3a
import
datetime
import
os
import
random
import
shutil
from
functools
import
cmp_to_key
from
django.contrib
import
messages
...
...
@@ -377,6 +378,8 @@ class UploadMateriService:
@
staticmethod
def
upload_materi_excel
(
categories
,
excel
,
request
,
row
):
default_cover
=
'book-cover-placeholder.png'
for
i
in
range
(
row
):
materi
=
Materi
(
title
=
excel
[
"Title"
][
i
],
...
...
@@ -385,11 +388,22 @@ class UploadMateriService:
descriptions
=
excel
[
"Description"
][
i
],
uploader
=
request
.
user
,
)
materi
.
cover
.
name
=
default_cover
materi
.
content
.
name
=
default_cover
# Check if file exists in /media
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
default_cover
)):
shutil
.
copy
(
os
.
path
.
join
(
'app'
,
'static'
,
'images'
,
default_cover
),
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
default_cover
))
materi
.
save
()
for
c
in
excel
[
"Categories"
][
i
].
split
(
","
):
materi
.
categories
.
add
(
categories
.
get
(
name
=
c
))
class
EditProfileService
:
@
staticmethod
...
...
app/static/images/book-cover-placeholder.png
0 → 100644
View file @
38130f3a
4.42 KB
app/tests.py
View file @
38130f3a
...
...
@@ -1303,7 +1303,12 @@ class UploadExcelPageTest(TestCase):
response
=
self
.
client
.
post
(
"/unggah_excel/"
,
{
'excel'
:
fp
})
title
=
data_frame
[
'Title'
][
0
]
self
.
assertTrue
(
Materi
.
objects
.
get
(
title
=
title
))
materi
=
Materi
.
objects
.
get
(
title
=
title
)
default_path
=
'book-cover-placeholder.png'
self
.
assertTrue
(
materi
)
self
.
assertEquals
(
materi
.
cover
.
name
,
default_path
)
self
.
assertTrue
(
os
.
path
.
exists
(
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
default_path
)))
def
test_upload_excel_download_template
(
self
):
self
.
client
.
login
(
email
=
"kontributor@gov.id"
,
...
...
@@ -1314,6 +1319,8 @@ class UploadExcelPageTest(TestCase):
self
.
assertEquals
(
response
[
'Content-Type'
],
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
self
.
assertEquals
(
response
[
'Content-Disposition'
],
'attachment; filename=template.xlsx'
)
class
DashboardKontributorViewTest
(
TestCase
):
...
...
Write
Preview
Supports
Markdown
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