Fakultas Ilmu Komputer UI

Commit 51ab2d3e authored by Reyhan Alhafizal Hamidi's avatar Reyhan Alhafizal Hamidi
Browse files

Merge branch '1706040082-50' into 'master'

[#50] Fix codesmell from Share Materi via Google Drive

See merge request !44
parents 70f3b991 5fb92e5b
Pipeline #58170 passed with stages
in 24 minutes and 8 seconds
...@@ -13,7 +13,8 @@ from django.core.files import File ...@@ -13,7 +13,8 @@ from django.core.files import File
from django.core.exceptions import PermissionDenied, ValidationError from django.core.exceptions import PermissionDenied, ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.management import call_command from django.core.management import call_command
from django.urls import resolve, reverse from django.test import Client, TestCase, TransactionTestCase
from django.urls import resolve
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from django.test import Client, RequestFactory, TestCase, TransactionTestCase from django.test import Client, RequestFactory, TestCase, TransactionTestCase
from pytz import timezone from pytz import timezone
...@@ -479,7 +480,6 @@ class DetailMateriTest(TestCase): ...@@ -479,7 +480,6 @@ class DetailMateriTest(TestCase):
self.assertEqual(last_url, "/materi/%d/" % self.materi1.id) self.assertEqual(last_url, "/materi/%d/" % self.materi1.id)
self.assertEqual(status_code, 302) self.assertEqual(status_code, 302)
class PostsViewTest(TestCase): class PostsViewTest(TestCase):
@classmethod @classmethod
def generate_posts_data(cls, user): def generate_posts_data(cls, user):
......
...@@ -7,7 +7,8 @@ from django.contrib import messages ...@@ -7,7 +7,8 @@ from django.contrib import messages
from django.contrib.auth.models import AnonymousUser from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import PermissionDenied, ValidationError from django.core.exceptions import PermissionDenied, ValidationError
from django.db.models import Q, Count from django.db.models import Q, Count
from django.http import Http404, HttpResponse, HttpResponseRedirect, JsonResponse from django.http import (Http404, HttpResponse, HttpResponseRedirect,
JsonResponse)
from django.urls import reverse from django.urls import reverse
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.template import loader from django.template import loader
...@@ -32,11 +33,11 @@ from authentication.models import User ...@@ -32,11 +33,11 @@ from authentication.models import User
import django import django
import pandas as pd import pandas as pd
from io import BytesIO from io import BytesIO
from django.contrib import messages
from pydrive.auth import GoogleAuth from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive from pydrive.drive import GoogleDrive
from pydrive.auth import AuthenticationRejected from pydrive.auth import AuthenticationRejected
def permission_denied(request, exception, template_name="error_403.html"): def permission_denied(request, exception, template_name="error_403.html"):
return defaults.permission_denied(request, exception, template_name) return defaults.permission_denied(request, exception, template_name)
...@@ -858,10 +859,8 @@ def save_to_gdrive(request, pk): ...@@ -858,10 +859,8 @@ def save_to_gdrive(request, pk):
path = materi.content.path path = materi.content.path
file_path = os.path.join(settings.MEDIA_ROOT, path) file_path = os.path.join(settings.MEDIA_ROOT, path)
if os.path.exists(file_path): if os.path.exists(file_path):
with open(file_path, "rb") as fh: upload_to_gdrive(file_path, materi.title)
upload_to_gdrive(file_path, materi.title)
else: else:
raise Http404("File tidak dapat ditemukan.") raise Http404("File tidak dapat ditemukan.")
return HttpResponseRedirect(reverse("detail-materi", kwargs={"pk": pk})) return HttpResponseRedirect(reverse('detail-materi', kwargs={'pk': pk}))
\ No newline at end of file
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