Fakultas Ilmu Komputer UI

Commit 2cceb480 authored by Glenda Emanuella Sutanto's avatar Glenda Emanuella Sutanto
Browse files

Merge branch 'display-last-active-cart-in-user' into 'staging'

Displayed last active cart in user auth serializer

See merge request !80
parents a52663a9 fb02ae4b
Pipeline #82962 passed with stages
in 15 minutes and 38 seconds
import datetime
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from rest_framework import serializers, exceptions from rest_framework import serializers, exceptions
from dj_rest_auth.serializers import LoginSerializer from dj_rest_auth.serializers import LoginSerializer
...@@ -23,12 +24,15 @@ class UserAuthSerializer(serializers.ModelSerializer): ...@@ -23,12 +24,15 @@ class UserAuthSerializer(serializers.ModelSerializer):
if instance.is_staff: if instance.is_staff:
result['role'] = 'admin' result['role'] = 'admin'
result['transaction_status'] = None
result['cart_id'] = None
if instance.cart.exists(): if instance.cart.exists():
result['transaction_status'] = instance.cart.last().transaction_status active_carts = instance.cart.filter(program_end_date__gte=datetime.date.today())
result['cart_id'] = instance.cart.last().id if len(active_carts) > 0:
else: last_active_cart = active_carts.order_by('-id')[0]
result['transaction_status'] = None result['transaction_status'] = last_active_cart.transaction_status
result['cart_id'] = None result['cart_id'] = last_active_cart.id
return result return result
......
Markdown is supported
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