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
ppl-fasilkom-ui
PPL Sosial
pilar
pilar-backend
Commits
17708af1
Commit
17708af1
authored
Apr 02, 2021
by
Ilma Ainur Rohma
Committed by
Azhar Difa Arnanda
Apr 02, 2021
Browse files
#2
: PBI 3 Menghapus Donation
parent
8a8b9ca8
Changes
4
Hide whitespace changes
Inline
Side-by-side
api/tests.py
View file @
17708af1
import
decimal
from
os
import
name
import
tempfile
from
unittest
import
mock
import
datetime
...
...
@@ -1634,6 +1635,21 @@ class ProgramDonationTest(rest_framework_test.APITestCase):
url_args
=
[
program_donation
.
id
]
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_403_FORBIDDEN
)
def
test_delete_by_program
(
self
):
program
=
models
.
Program
.
objects
.
create
(
**
seeds
.
PROGRAM_DATA
)
donation
=
models
.
ProgramDonation
.
objects
.
create
(
**
dict
(
seeds
.
PROGRAM_DONATION_CASH_DATA
,
user
=
self
.
user
,
program
=
program
))
response
=
request
(
'DELETE'
,
'donation-by-program'
,
http_authorization
=
self
.
superuser_http_authorization
,
url_args
=
[
program
.
id
]
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
self
.
assertEqual
(
models
.
ProgramDonation
.
objects
.
count
(),
0
)
class
ChoicesViewsTest
(
rest_framework_test
.
APITestCase
):
...
...
api/urls.py
View file @
17708af1
...
...
@@ -30,6 +30,7 @@ urlpatterns = [
name
=
'cart-cancel-transaction'
),
urls
.
path
(
'donation/create/'
,
api_views
.
DonationCreate
.
as_view
(),
name
=
'donation-create'
),
urls
.
path
(
'donation/delete-by-p/<str:pid>'
,
api_views
.
delete_donation_by_program
,
name
=
'donation-by-program'
),
urls
.
path
(
'donation/reupload-proof-of-bank-transfer/'
,
api_views
.
DonationReuploadProofOfBankTransfer
.
as_view
(),
...
...
api/views.py
View file @
17708af1
from
django
import
http
,
shortcuts
from
django.contrib
import
auth
from
django.db
import
transaction
as
db_transaction
,
utils
as
db_utils
...
...
@@ -12,7 +11,8 @@ from rest_framework import (
permissions
as
rest_framework_permissions
,
response
,
status
,
views
as
rest_framework_views
)
from
rest_framework.authtoken
import
serializers
as
authtoken_serializers
from
rest_framework.decorators
import
api_view
from
django.views.decorators.csrf
import
csrf_exempt
from
api
import
(
constants
,
exceptions
as
api_exceptions
,
filters
as
api_filters
,
models
,
paginations
,
permissions
as
api_permissions
,
reports_writer
,
schemas
,
serializers
as
api_serializers
,
...
...
@@ -844,6 +844,14 @@ class ProgramDonationList(generics.ListAPIView):
return
queryset
.
filter
(
user
=
self
.
request
.
user
)
return
queryset
@
api_view
([
'DELETE'
])
@
csrf_exempt
def
delete_donation_by_program
(
request
,
pid
):
if
((
request
.
user
)
and
(
request
.
user
.
is_staff
)):
program
=
models
.
Program
.
objects
.
get
(
id
=
pid
)
donation
=
models
.
ProgramDonation
.
objects
.
filter
(
program
=
program
)
donation
.
delete
()
return
response
.
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
class
ProgramDonationListCSH
(
generics
.
ListAPIView
):
filter_backends
=
[
...
...
wait-for-it.sh
100644 → 100755
View file @
17708af1
File mode changed from 100644 to 100755
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