#!/usr/bin/env python """ Alert when there are Form Entries with status = PENDING """ from breathecode.marketing.models import FormEntry from django.db.models import Q from breathecode.utils import ScriptNotification pending_leads = FormEntry.objects.filter(storage_status="PENDING").filter(Q(academy__id=academy.id) | Q(location=academy.slug)) if len(pending_leads) > 0: raise ScriptNotification(f"Warning there are {len(pending_leads)} pending form entries", status='MINOR') print("No pending leads")
#!/usr/bin/env python """ Checks if ending date has passed and cohort status is not ended """ from breathecode.utils import ScriptNotification from breathecode.admissions.models import Cohort from django.utils import timezone to_fix_cohort_stage = Cohort.objects.filter(ending_date__lt=timezone.now(), academy__id=academy.id)\ .exclude(stage='ENDED').values_list('name', flat=True) if len(to_fix_cohort_stage) > 0: to_fix_cohort_name = ("\n").join( ["- " + cohort_name for cohort_name in to_fix_cohort_stage]) raise ScriptNotification( f"These cohorts ended but their stage is different that ENDED: \n {to_fix_cohort_name}", status='MINOR') else: print("Everything up to date")
#!/usr/bin/env python """ Alert me when something is missing with the Slack integration """ from breathecode.notify.models import SlackTeam from breathecode.authenticate.models import CredentialsSlack from django.db.models import Q from breathecode.utils import ScriptNotification slack = SlackTeam.objects.filter(academy__id=academy.id).first() if slack is None: raise ScriptNotification("No slack integration has been found", status='MINOR') owner_credentials = CredentialsSlack.objects.filter(user__id=slack.owner.id).first() if owner_credentials is None: raise ScriptNotification("The academy slack integration is not finished, the team owner needs to connect with slack", status='MINOR')
cohorts = Cohort.objects.filter(academy__id=academy.id).exclude( ending_date__lt=timezone.now(), kickoff_date__gt=timezone.now()) cohorts_with_pending_surveys = [] if not cohorts: print("No cohorts found") for cohort in cohorts: lastest_survey = Survey.objects.filter( cohort__id=cohort.id).order_by('sent_at').first() if lastest_survey is None: cohorts_with_pending_surveys.append(cohort.name) else: num_weeks = calculate_weeks(lastest_survey.sent_at.date(), datetime.now().date()) if num_weeks > 4: cohorts_with_pending_surveys.append(cohort.name) if len(cohorts_with_pending_surveys) > 0: cohort_names = ("\n").join( ["- " + cohort_name for cohort_name in cohorts_with_pending_surveys]) raise ScriptNotification( f"There are {str(len(cohorts_with_pending_surveys))} surveys pending to be sent on theese cohorts: \n {cohort_names}", status='MINOR') print("No reminders")
#!/usr/bin/env python """ Checks for cohort users with status active on ended cohort """ from breathecode.utils import ScriptNotification from breathecode.admissions.models import CohortUser from django.utils import timezone active_user_on_ended_cohort = CohortUser.objects.filter( cohort__stage="ENDED", educational_status="ACTIVE", cohort__academy__id=academy.id).exclude(cohort__never_ends=True) active_user_on_ended_cohort_list = [ "- " + item.user.first_name + " " + item.user.last_name + " (" + item.user.email + ") => " + item.cohort.name for item in active_user_on_ended_cohort ] active_user_on_ended_cohort_list_names = ( "\n").join(active_user_on_ended_cohort_list) if len(active_user_on_ended_cohort_list): raise ScriptNotification( f"This users: {active_user_on_ended_cohort_list_names} are active on ended cohorts", slug='ended-cohort-had-active-users') print("Everything up to date")
#!/usr/bin/env python """ Checks for cohort users with status active on ended cohort """ from breathecode.utils import ScriptNotification from breathecode.admissions.models import CohortUser from django.utils import timezone active_user_on_ended_cohort = CohortUser.objects.filter( cohort__stage="ENDED", educational_status="ACTIVE", cohort__academy__id=academy.id) active_user_on_ended_cohort_list = [ "- " + item.user.first_name + " " + item.user.last_name + " (" + item.user.email + ") => " + item.cohort.name for item in active_user_on_ended_cohort ] active_user_on_ended_cohort_list_names = ( "\n").join(active_user_on_ended_cohort_list) if len(active_user_on_ended_cohort_list): raise ScriptNotification( f"This users: {active_user_on_ended_cohort_list_names} are active on ended cohorts" ) print("Everything up to date")