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
21fa9386
Commit
21fa9386
authored
Nov 24, 2020
by
inez nabila
Browse files
fixing
parent
9fa68ac2
Changes
4
Hide whitespace changes
Inline
Side-by-side
api/migrations/0004_auto_20201124_1832.py
0 → 100644
View file @
21fa9386
# Generated by Django 3.0.7 on 2020-11-24 11:32
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0003_auto_20201122_1402'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'user'
,
name
=
'number_of_cash_donations'
,
),
migrations
.
RemoveField
(
model_name
=
'user'
,
name
=
'number_of_goods_donations'
,
),
migrations
.
RemoveField
(
model_name
=
'user'
,
name
=
'number_of_transactions'
,
),
]
api/models.py
View file @
21fa9386
...
...
@@ -40,15 +40,6 @@ class User(auth_models.AbstractUser):
verbose_name
=
_
(
'profile picture'
)
)
otp
=
db_models
.
CharField
(
blank
=
True
,
max_length
=
6
,
null
=
True
,
verbose_name
=
_
(
'OTP'
))
number_of_transactions
=
db_models
.
PositiveIntegerField
(
default
=
0
,
verbose_name
=
_
(
'number of transactions'
)
)
number_of_cash_donations
=
db_models
.
PositiveIntegerField
(
default
=
0
,
verbose_name
=
_
(
'number of cash donations'
)
)
number_of_goods_donations
=
db_models
.
PositiveIntegerField
(
default
=
0
,
verbose_name
=
_
(
'number of goods donations'
)
)
class
Meta
:
ordering
=
[
'username'
,
'id'
]
...
...
api/serializers.py
View file @
21fa9386
...
...
@@ -156,6 +156,9 @@ class ReportProgramDonationSerializer(serializers.Serializer): # pylint: disable
class
UserSerializer
(
serializers
.
ModelSerializer
):
total_transactions
=
serializers
.
SerializerMethodField
(
'get_total_transactions'
)
total_program_donations_goods
=
serializers
.
SerializerMethodField
(
'get_total_program_donations_goods'
)
total_program_donations_cash
=
serializers
.
SerializerMethodField
(
'get_total_program_donations_cash'
)
class
Meta
:
extra_kwargs
=
{
'password'
:
{
'write_only'
:
True
}}
...
...
@@ -171,13 +174,22 @@ class UserSerializer(serializers.ModelSerializer):
'urban_village'
,
'sub_district'
,
'profile_picture'
,
'
number_of
_transactions'
,
'
number_of_cash
_donations'
,
'
number_of_goods
_donations'
,
'
total
_transactions'
,
'
total_program
_donations
_goods
'
,
'
total_program
_donations
_cash
'
,
]
model
=
models
.
User
read_only_fields
=
[
'id'
]
def
get_total_transactions
(
self
,
obj
):
# pylint: disable=no-self-use
return
obj
.
transactions
.
filter
(
transaction_status
=
'005'
).
count
()
def
get_total_program_donations_goods
(
self
,
obj
):
# pylint: disable=no-self-use
return
obj
.
program_donations
.
filter
(
donation_type
=
'GDS'
).
filter
(
donation_status
=
'002'
).
count
()
def
get_total_program_donations_cash
(
self
,
obj
):
# pylint: disable=no-self-use
return
obj
.
program_donations
.
filter
(
donation_type
=
'CSH'
).
filter
(
donation_status
=
'002'
).
count
()
def
create
(
self
,
validated_data
):
password
=
validated_data
.
pop
(
'password'
,
None
)
instance
=
self
.
Meta
.
model
(
**
validated_data
)
...
...
api/views.py
View file @
21fa9386
...
...
@@ -260,7 +260,6 @@ class CartCompleteTransaction(rest_framework_views.APIView):
def
post
(
self
,
request
,
_format
=
None
):
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
user
=
request
.
user
transaction
=
shortcuts
.
get_object_or_404
(
models
.
Transaction
,
id
=
serializer
.
validated_data
[
'transaction'
],
...
...
@@ -271,8 +270,6 @@ class CartCompleteTransaction(rest_framework_views.APIView):
'Transaction cannot be completed unless the status is "Being shipped".'
))
transaction
.
transaction_status
=
'005'
user
.
number_of_transactions
+=
1
user
.
save
()
transaction
.
save
()
return
response
.
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
...
...
@@ -492,7 +489,7 @@ class UserList(generics.ListCreateAPIView):
ordering_fields
=
[
'username'
,
'full_name'
,
'phone_number'
,
'number_of_transactions'
,
'number_of_cash_donations'
,
'number_of_goods_donations'
]
]
pagination_class
=
paginations
.
SmallResultsSetPagination
permission_classes
=
[
rest_framework_permissions
.
IsAdminUser
]
queryset
=
models
.
User
.
objects
.
all
()
...
...
@@ -844,19 +841,12 @@ class ProgramDonationDetail(generics.RetrieveUpdateAPIView):
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
user
=
request
.
user
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
if
instance
.
donation_status
in
(
'002'
,
'003'
):
raise
rest_framework_exceptions
.
PermissionDenied
(
_
(
'Cannot update program donation because it has a completed or canceled status.'
))
if
serializer
.
validated_data
[
'donation_status'
]
==
'002'
:
if
instance
.
donation_type
==
'CSH'
:
user
.
number_of_cash_donations
+=
1
elif
instance
.
donation_type
==
'GDS'
:
user
.
number_of_goods_donations
+=
1
user
.
save
()
return
super
().
update
(
request
,
*
args
,
**
kwargs
)
# pylint: disable=no-member
...
...
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