@ -1,7 +1,10 @@
import arrow
from io import BytesIO
from io import BytesIO
from PIL import Image
from PIL import Image
from os . path import splitext
from os . path import splitext
from datetime import timedelta
from datetime import timedelta
from paymentwall import Pingback
from django . contrib . auth import login
from django . contrib . auth import login
from django . core . exceptions import ValidationError
from django . core . exceptions import ValidationError
@ -18,8 +21,9 @@ from django.utils.timezone import now
from apps . auth . tokens import verification_email_token
from apps . auth . tokens import verification_email_token
from apps . course . models import Course
from apps . course . models import Course
from apps . payment . models import AuthorBalance , CoursePayment
from apps . notification . utils import send_email
from apps . notification . utils import send_email
from apps . school . models import SchoolSchedule
from apps . payment . models import AuthorBalance , CoursePayment , SchoolPayment
from . forms import UserEditForm , WithdrawalForm
from . forms import UserEditForm , WithdrawalForm
@ -52,8 +56,31 @@ class UserView(DetailView):
author = self . object , status = Course . DRAFT
author = self . object , status = Course . DRAFT
)
)
context [ ' paid ' ] = Course . objects . filter (
context [ ' paid ' ] = Course . objects . filter (
payments__in = CoursePayment . objects . filter ( user = self . object ) ,
payments__in = CoursePayment . objects . filter (
user = self . object ,
status__in = [
Pingback . PINGBACK_TYPE_REGULAR ,
Pingback . PINGBACK_TYPE_GOODWILL ,
Pingback . PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED ,
] ,
) ,
) . distinct ( )
) . distinct ( )
school_payment = SchoolPayment . objects . filter (
user = self . object ,
date_start__lte = now ( ) ,
date_end__gt = now ( ) ,
status__in = [
Pingback . PINGBACK_TYPE_REGULAR ,
Pingback . PINGBACK_TYPE_GOODWILL ,
Pingback . PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED ,
] ,
) . last ( )
context [ ' school_payment ' ] = school_payment
if school_payment and school_payment . date_end :
context [ ' school_days_left ' ] = ( school_payment . date_end - now ( ) . date ( ) ) . days
context [ ' school_schedules ' ] = SchoolSchedule . objects . filter (
weekday__in = school_payment . weekdays if school_payment else [ ] ,
)
return context
return context