Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
5fb92e5b
Commit
5fb92e5b
authored
Oct 10, 2020
by
Reyhan Alhafizal Hamidi
Browse files
[
#50
] Fix codesmell from Share Materi via Google Drive
parent
68ae0470
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/tests.py
View file @
5fb92e5b
...
...
@@ -13,7 +13,8 @@ from django.core.files import File
from
django.core.exceptions
import
PermissionDenied
,
ValidationError
from
django.core.files.uploadedfile
import
SimpleUploadedFile
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.test
import
Client
,
RequestFactory
,
TestCase
,
TransactionTestCase
from
pytz
import
timezone
...
...
@@ -472,7 +473,6 @@ class DetailMateriTest(TestCase):
self
.
assertEqual
(
last_url
,
"/materi/%d/"
%
self
.
materi1
.
id
)
self
.
assertEqual
(
status_code
,
302
)
class
PostsViewTest
(
TestCase
):
@
classmethod
def
generate_posts_data
(
cls
,
user
):
...
...
app/views.py
View file @
5fb92e5b
...
...
@@ -7,7 +7,8 @@ from django.contrib import messages
from
django.contrib.auth.models
import
AnonymousUser
from
django.core.exceptions
import
PermissionDenied
,
ValidationError
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.shortcuts
import
get_object_or_404
,
redirect
from
django.template
import
loader
...
...
@@ -32,11 +33,11 @@ from authentication.models import User
import
django
import
pandas
as
pd
from
io
import
BytesIO
from
django.contrib
import
messages
from
pydrive.auth
import
GoogleAuth
from
pydrive.drive
import
GoogleDrive
from
pydrive.auth
import
AuthenticationRejected
def
permission_denied
(
request
,
exception
,
template_name
=
"error_403.html"
):
return
defaults
.
permission_denied
(
request
,
exception
,
template_name
)
...
...
@@ -855,10 +856,8 @@ def save_to_gdrive(request, pk):
path
=
materi
.
content
.
path
file_path
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
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
:
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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