profile edit
This commit is contained in:
@@ -142,6 +142,7 @@ class ProfileSerializer(serializers.ModelSerializer):
|
||||
principal_type_name = serializers.SerializerMethodField(read_only=True)
|
||||
has_active_subscription = serializers.SerializerMethodField(read_only=True)
|
||||
has_preferences = serializers.SerializerMethodField(read_only=True)
|
||||
register_complete = serializers.BooleanField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = IAmPrincipal
|
||||
@@ -162,6 +163,7 @@ class ProfileSerializer(serializers.ModelSerializer):
|
||||
"facebook_profile",
|
||||
"instagram_profile",
|
||||
"website",
|
||||
"is_active",
|
||||
]
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
@@ -198,21 +200,33 @@ class ProfileSerializer(serializers.ModelSerializer):
|
||||
today = timezone.now().date()
|
||||
|
||||
# Attempt to find the active subscription with the furthest grace_period_end_date
|
||||
latest_subscription = PrincipalSubscription.objects.filter(
|
||||
principal=obj,
|
||||
is_paid=True,
|
||||
cancelled=False,
|
||||
deleted=False,
|
||||
active=True,
|
||||
status=SubscriptionStatus.ACTIVE,
|
||||
).order_by('-grace_period_end_date').first() # Order by descending grace_period_end_date and take the first
|
||||
latest_subscription = (
|
||||
PrincipalSubscription.objects.filter(
|
||||
principal=obj,
|
||||
is_paid=True,
|
||||
cancelled=False,
|
||||
deleted=False,
|
||||
active=True,
|
||||
status=SubscriptionStatus.ACTIVE,
|
||||
)
|
||||
.order_by("-grace_period_end_date")
|
||||
.first()
|
||||
) # Order by descending grace_period_end_date and take the first
|
||||
|
||||
if latest_subscription:
|
||||
# Check if we're within the grace period
|
||||
if today <= latest_subscription.grace_period_end_date:
|
||||
subscription_status['has_active_subscription'] = today <= latest_subscription.end_date
|
||||
subscription_status['in_grace_period'] = latest_subscription.end_date < today <= latest_subscription.grace_period_end_date
|
||||
subscription_status['grace_period_end_date'] = latest_subscription.grace_period_end_date
|
||||
subscription_status["has_active_subscription"] = (
|
||||
today <= latest_subscription.end_date
|
||||
)
|
||||
subscription_status["in_grace_period"] = (
|
||||
latest_subscription.end_date
|
||||
< today
|
||||
<= latest_subscription.grace_period_end_date
|
||||
)
|
||||
subscription_status["grace_period_end_date"] = (
|
||||
latest_subscription.grace_period_end_date
|
||||
)
|
||||
|
||||
return subscription_status
|
||||
|
||||
|
||||
Reference in New Issue
Block a user