diff --git a/api/dashboard/campus/events_views.py b/api/dashboard/campus/events_views.py index 7583519f5..c88b7bb38 100644 --- a/api/dashboard/campus/events_views.py +++ b/api/dashboard/campus/events_views.py @@ -453,6 +453,18 @@ def get(self, request): roles.add(f"{chapter.ig.code} CampusLead") roles.add(f"{chapter.ig.code} IGLead") + + ig_campus_lead_titles = [ + RoleType.IG_CAMPUS_LEAD_ROLE(code) + for code in InterestGroup.objects.values_list("code", flat=True) + ] + custom_execom_roles = Role.objects.filter( + is_execom_role=True + ).exclude( + title__in=ig_campus_lead_titles + ).values_list("title", flat=True) + roles.update(custom_execom_roles) + return CustomResponse(response={"data": sorted(list(roles))}).get_success_response() diff --git a/mu_celery/alumni_cron.py b/mu_celery/alumni_cron.py new file mode 100644 index 000000000..2ec12ddfd --- /dev/null +++ b/mu_celery/alumni_cron.py @@ -0,0 +1,37 @@ +from celery import shared_task +from django.db.models import Q +from django.utils.timezone import now + +from db.organization import UserOrganizationLink +from utils.types import OrganizationType + + +@shared_task +def update_alumni_status_cron(): + """Synchronize college alumni status with graduation year. + + A user is an alumnus only when their four-digit graduation year is before + the current year. This corrects both stale alumni and stale non-alumni + values, so it is safe to run repeatedly. + """ + current_year = str(now().year) + valid_college_links = UserOrganizationLink.objects.filter( + org__org_type=OrganizationType.COLLEGE.value, + graduation_year__regex=r"^[0-9]{4}$", + ) + + marked_alumni = valid_college_links.filter( + graduation_year__lt=current_year, + ).filter( + Q(is_alumni=False) | Q(is_alumni__isnull=True) + ).update(is_alumni=True) + + marked_student = valid_college_links.filter( + graduation_year__gte=current_year, + is_alumni=True, + ).update(is_alumni=False) + + return { + "marked_alumni": marked_alumni, + "marked_student": marked_student, + } diff --git a/mulearnbackend/celery.py b/mulearnbackend/celery.py index 02da45e98..b26689fc1 100644 --- a/mulearnbackend/celery.py +++ b/mulearnbackend/celery.py @@ -5,7 +5,10 @@ # Set the default Django settings module for the 'celery' program. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mulearnbackend.settings") -app = Celery("mulearnbackend") +app = Celery( + "mulearnbackend", + include=["mu_celery.alumni_cron"], +) # Using a string here means the worker doesn't have to serialize # the configuration object to child processes.