|
|
|
@ -1,13 +1,16 @@ |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
|
|
|
|
from django.contrib.contenttypes.models import ContentType |
|
|
|
from django.contrib.staticfiles.storage import staticfiles_storage |
|
|
|
from django.contrib.staticfiles.storage import staticfiles_storage |
|
|
|
from django.utils.timezone import now |
|
|
|
from django.utils.timezone import now |
|
|
|
|
|
|
|
from django.db.models import Max |
|
|
|
|
|
|
|
|
|
|
|
from apps.notification.models import UserNotification |
|
|
|
from apps.notification.models import UserNotification |
|
|
|
from apps.notification.utils import send_email |
|
|
|
from apps.notification.utils import send_email |
|
|
|
from apps.payment.models import SchoolPayment |
|
|
|
from apps.payment.models import SchoolPayment, CoursePayment, Payment |
|
|
|
from project.celery import app |
|
|
|
from project.celery import app |
|
|
|
|
|
|
|
from project.utils.db import format_sql, execute_sql |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User = get_user_model() |
|
|
|
User = get_user_model() |
|
|
|
@ -58,3 +61,31 @@ def send_certificates(email=None, date=None, dry_run=False): |
|
|
|
file.close() |
|
|
|
file.close() |
|
|
|
un.certificate_last_email = now() |
|
|
|
un.certificate_last_email = now() |
|
|
|
un.save() |
|
|
|
un.save() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.task |
|
|
|
|
|
|
|
def sendgrid(): |
|
|
|
|
|
|
|
ct_course = ContentType.objects.get_for_model(CoursePayment).id |
|
|
|
|
|
|
|
ct_school = ContentType.objects.get_for_model(SchoolPayment).id |
|
|
|
|
|
|
|
course_payments_sql = ''' |
|
|
|
|
|
|
|
select {p.user}, max({p.created_at}) from {p} where {p}.polymorphic_ctype_id = {ct} group by {p.user} |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
course_payments = {p[0]: p[1] for p in execute_sql(format_sql(course_payments_sql, p=Payment, ct=ct_course))} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
school_payments_sql = ''' |
|
|
|
|
|
|
|
select {p.user}, max({p.created_at}) from {p} where {p}.polymorphic_ctype_id = {ct} group by {p.user} |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
school_payments = {p[0]: p[1] for p in execute_sql(format_sql(school_payments_sql, p=Payment, ct=ct_school))} |
|
|
|
|
|
|
|
users = list(User.objects.filter(role=User.USER_ROLE)) |
|
|
|
|
|
|
|
data = [] |
|
|
|
|
|
|
|
for user in users: |
|
|
|
|
|
|
|
data.append({ |
|
|
|
|
|
|
|
'name': user.get_full_name(), |
|
|
|
|
|
|
|
'email': user.email, |
|
|
|
|
|
|
|
'last_login': user.last_login, |
|
|
|
|
|
|
|
'last_course_purchase': course_payments.get(user.id), |
|
|
|
|
|
|
|
'last_school_purchase': school_payments.get(user.id), |
|
|
|
|
|
|
|
'gender': user.gender, |
|
|
|
|
|
|
|
'birthday': user.birthday, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
print(data) |
|
|
|
|