Skip to content

Commit 6aaae06

Browse files
authored
Merge pull request #177 from PotLock/testnet
add status field
2 parents 087d462 + 6a4907e commit 6aaae06

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

campaigns/serializers.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,39 @@ class Meta:
4141
"owner",
4242
"recipient",
4343
"token",
44-
"is_active",
44+
"status",
4545
]
4646

4747
owner = AccountSerializer()
4848
recipient = AccountSerializer()
4949
token = TokenSerializer()
50-
is_active = serializers.SerializerMethodField()
50+
status = serializers.SerializerMethodField()
5151

52-
def get_is_active(self, obj):
52+
def get_status(self, obj):
5353
"""
54-
Check if campaign is active based on:
55-
1. Campaign has started (start_at <= current_time)
56-
2. Campaign hasn't ended yet (end_at > current_time or end_at is None)
57-
3. Campaign hasn't reached max amount (net_raised_amount < max_amount or max_amount is None)
54+
Get campaign status: active, ended, or upcoming
5855
"""
56+
from django.utils import timezone
5957

6058
now = timezone.now()
6159

6260
if obj.start_at > now:
63-
return False
61+
return "upcoming"
6462

6563
if obj.end_at is not None and obj.end_at <= now:
66-
return False
64+
return "ended"
6765

6866
if obj.max_amount is not None:
6967
try:
7068
net_raised = int(obj.net_raised_amount)
7169
max_amount = int(obj.max_amount)
7270
if net_raised >= max_amount:
73-
return False
71+
return "ended"
7472
except (ValueError, TypeError):
7573
# If we can't parse the amounts, assume not maxed out
7674
pass
7775

78-
return True
76+
return "active"
7977

8078

8179

@@ -135,7 +133,7 @@ class Meta:
135133
"referral_fee_basis_points": 500,
136134
"creator_fee_basis_points": 250,
137135
"allow_fee_avoidance": False,
138-
"is_active": True,
136+
"status": "active",
139137
"owner": SIMPLE_ACCOUNT_EXAMPLE,
140138
"recipient": SIMPLE_ACCOUNT_EXAMPLE,
141139
"token": SIMPLE_TOKEN_EXAMPLE,

0 commit comments

Comments
 (0)