Fakultas Ilmu Komputer UI

Commit 38130f3a authored by Arief Pratama's avatar Arief Pratama
Browse files

Add default book cover

parent 05ee0d76
Pipeline #59997 passed with stages
in 27 minutes and 31 seconds
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
......
......@@ -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):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment