Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/dashboard/campus/events_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
37 changes: 37 additions & 0 deletions mu_celery/alumni_cron.py
Original file line number Diff line number Diff line change
@@ -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,
}
5 changes: 4 additions & 1 deletion mulearnbackend/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down