Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2021
Kelas D
PT Gizi Sehat - Dietela
Dietela Backend
Commits
637cf487
Commit
637cf487
authored
Jun 29, 2021
by
Glenda Emanuella Sutanto
Browse files
Display last cart + create all_carts_are_expired attribute in user serializer
parent
56719bc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
authentication/serializers.py
View file @
637cf487
...
@@ -26,13 +26,21 @@ class UserAuthSerializer(serializers.ModelSerializer):
...
@@ -26,13 +26,21 @@ class UserAuthSerializer(serializers.ModelSerializer):
result
[
'transaction_status'
]
=
None
result
[
'transaction_status'
]
=
None
result
[
'cart_id'
]
=
None
result
[
'cart_id'
]
=
None
result
[
'all_carts_are_expired'
]
=
None
if
instance
.
cart
.
exists
():
if
instance
.
cart
.
exists
():
active_carts
=
instance
.
cart
.
filter
(
program_end_date__gte
=
datetime
.
date
.
today
())
result
[
'transaction_status'
]
=
instance
.
cart
.
last
().
transaction_status
if
len
(
active_carts
)
>
0
:
result
[
'cart_id'
]
=
instance
.
cart
.
last
().
id
last_active_cart
=
active_carts
.
order_by
(
'-id'
)[
0
]
result
[
'transaction_status'
]
=
last_active_cart
.
transaction_status
all_carts_are_expired
=
True
result
[
'cart_id'
]
=
last_active_cart
.
id
for
cart
in
instance
.
cart
.
all
():
if
cart
.
program_end_date
is
None
:
continue
if
cart
.
program_end_date
>=
datetime
.
date
.
today
():
all_carts_are_expired
=
False
break
result
[
'all_carts_are_expired'
]
=
all_carts_are_expired
result
[
'nutritionist'
]
=
None
result
[
'nutritionist'
]
=
None
...
...
authentication/tests.py
View file @
637cf487
import
json
import
json
import
datetime
from
unittest.mock
import
patch
from
unittest.mock
import
patch
from
rest_framework
import
status
from
rest_framework
import
status
from
rest_framework.test
import
APITestCase
from
rest_framework.test
import
APITestCase
...
@@ -99,7 +100,8 @@ class UserModelTests(APITestCase):
...
@@ -99,7 +100,8 @@ class UserModelTests(APITestCase):
cls
.
cart
=
Cart
.
objects
.
create
(
cls
.
cart
=
Cart
.
objects
.
create
(
program
=
cls
.
dietela_program
,
program
=
cls
.
dietela_program
,
nutritionist
=
cls
.
nutritionist
,
nutritionist
=
cls
.
nutritionist
,
user
=
cls
.
custom_user_1
user
=
cls
.
custom_user_1
,
program_end_date
=
datetime
.
date
(
2021
,
6
,
28
)
)
)
def
test_create_user
(
self
):
def
test_create_user
(
self
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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