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
71f8ce61
Commit
71f8ce61
authored
Oct 30, 2020
by
Arief Pratama
Browse files
Merge branch '2006560831-40-fix' into 'master'
[
#40
] Add default book cover See merge request
!75
parents
05ee0d76
38130f3a
Pipeline
#59998
passed with stages
in 30 minutes and 40 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/services.py
View file @
71f8ce61
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 @
71f8ce61
4.42 KB
app/tests.py
View file @
71f8ce61
...
...
@@ -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