Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hu/ent 9452 #559

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 3 additions & 0 deletions docs/decisions/0022-spend-limits-constraint.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0022 Constraint on `spend-limit` based on total deposits
********************************************

2 changes: 2 additions & 0 deletions enterprise_access/apps/content_assignments/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class AssignmentAutomaticExpiredReason:

NUM_DAYS_BEFORE_AUTO_EXPIRATION = 90

START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS = 14

RETIRED_EMAIL_ADDRESS_FORMAT = 'retired_user{}@retired.invalid'

BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
25 changes: 20 additions & 5 deletions enterprise_access/apps/content_assignments/tasks.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""
Tasks for content_assignments app.
"""

import datetime
import logging

from braze.exceptions import BrazeBadRequestError
from celery import shared_task
from dateutil import parser
from django.apps import apps
from django.conf import settings
from pytz import UTC

from enterprise_access.apps.api_client.braze_client import ENTERPRISE_BRAZE_ALIAS_LABEL, BrazeApiClient
from enterprise_access.apps.api_client.lms_client import LmsApiClient
Expand All @@ -21,7 +23,11 @@
from enterprise_access.tasks import LoggedTaskWithRetry
from enterprise_access.utils import get_automatic_expiration_date_and_reason, localized_utcnow

from .constants import BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT, LearnerContentAssignmentStateChoices
from .constants import (
BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT,
START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS,
LearnerContentAssignmentStateChoices
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -199,9 +205,18 @@ def get_enrollment_deadline(self):
return get_human_readable_date(self._enrollment_deadline_raw())

def get_start_date(self):
return get_human_readable_date(
self.course_metadata.get('normalized_metadata', {}).get('start_date')
)
"""
Checks if the start_date is before today's date offset by the
START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS value and returns today's date
If not, pass through the formatted start date.
"""
start_date = self.course_metadata.get('normalized_metadata', {}).get('start_date')
start_date_datetime = parser.parse(start_date)
now = datetime.datetime.now()
offset_date_from_today = now - datetime.timedelta(days=START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS)
if start_date_datetime < offset_date_from_today.replace(tzinfo=UTC):
return get_human_readable_date(now.strftime(BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT))
return get_human_readable_date(start_date)

def get_action_required_by_timestamp(self):
"""
Expand Down
Loading