Commit a3df1073 by Harry Rein

Display logic on the programs page.

parent b5910892
import uuid as uuid_tools import uuid as uuid_tools
from datetime import datetime, timedelta from datetime import datetime, timedelta
from util.date_utils import strftime_localized
import pytz import pytz
import time
from django.conf import settings from django.conf import settings
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.db import models from django.db import models
...@@ -215,10 +217,20 @@ class CourseEntitlement(TimeStampedModel): ...@@ -215,10 +217,20 @@ class CourseEntitlement(TimeStampedModel):
def to_dict(self): def to_dict(self):
""" Convert entitlement to dictionary representation. """ """ Convert entitlement to dictionary representation. """
entitlement_expiration_date, entitlement_expired_at = None, None
if self.get_days_until_expiration() < settings.ENTITLEMENT_EXPIRED_ALERT_PERIOD:
entitlement_expiration_date = strftime_localized(
datetime.now(tz=pytz.UTC) + timedelta(days=self.get_days_until_expiration()),
'SHORT_DATE'
)
entitlement_expired_at = strftime_localized(
self.expired_at_datetime, 'SHORT_DATE') if self.expired_at_datetime else None
return { return {
'uuid': str(self.uuid), 'uuid': str(self.uuid),
'course_uuid': str(self.course_uuid), 'course_uuid': str(self.course_uuid),
'expired_at': self.expired_at 'expired_at': entitlement_expired_at,
'expiration_date': entitlement_expiration_date
} }
@classmethod @classmethod
......
...@@ -90,7 +90,9 @@ ...@@ -90,7 +90,9 @@
entitlementUUID: this.entitlement.uuid, entitlementUUID: this.entitlement.uuid,
currentSessionId: this.model.get('course_run_key'), currentSessionId: this.model.get('course_run_key'),
enrollUrl: this.model.get('enroll_url'), enrollUrl: this.model.get('enroll_url'),
courseHomeUrl: this.model.get('course_url') courseHomeUrl: this.model.get('course_url'),
expiredAt: this.entitlement.expired_at,
daysUntilExpiration: this.entitlement.days_util_expiration
}); });
} }
......
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
} }
.change-session { .change-session {
@include margin(0, 0, $baseline/4, $baseline/4); @include margin(0, 0, 0, $baseline/4);
padding: 0; padding: 0;
font-size: $font-size-sm; font-size: $font-size-sm;
......
...@@ -475,7 +475,8 @@ ...@@ -475,7 +475,8 @@
} }
} }
.run-period { .run-period,
.info-expires-at {
color: palette(grayscale, base); color: palette(grayscale, base);
font-size: 0.9375em; font-size: 0.9375em;
} }
...@@ -505,7 +506,6 @@ ...@@ -505,7 +506,6 @@
vertical-align: top; vertical-align: top;
padding: 0 10px 0 0; padding: 0 10px 0 0;
float: left; float: left;
width: calc(100% - 205px);
} }
} }
......
...@@ -17,12 +17,28 @@ ...@@ -17,12 +17,28 @@
<% } %> <% } %>
<% if (dateString && !is_unfulfilled_entitlement) { %> <% if (dateString && !is_unfulfilled_entitlement) { %>
<span class="run-period"><%- dateString %></span> <span class="run-period"><%- dateString %></span>
<% if (user_entitlement && !is_unfulfilled_entitlement) { %> <% if (user_entitlement && !user_entitlement.expired_at && !is_unfulfilled_entitlement) { %>
<button class="change-session btn-link" aria-controls="change-session-<%-user_entitlement.uuid%>"> <%- gettext('Change Session')%></button> <button class="change-session btn-link" aria-controls="change-session-<%-user_entitlement.uuid%>"> <%- gettext('Change Session')%></button>
<% } %> <% } %>
<% } %> <% } %>
</div> </div>
</div> <% if (user_entitlement && user_entitlement.expiration_date) { %>
<div class="info-expires-at">
<% if (is_unfulfilled_entitlement) { %>
<% if (user_entitlement.expired_at) { %>
<%- StringUtils.interpolate(gettext('You can no longer select a session as of {expiration_date}.'), {expiration_date: user_entitlement.expiration_date}) %>
<% } else { %>
<%- StringUtils.interpolate( gettext('You must select a session by {expiration_date} to access the course.'), {expiration_date: user_entitlement.expiration_date}) %>
<% } %>
<% } else { %>
<% if (user_entitlement.expired_at) { %>
<%- gettext('You can no longer change sessions.')%>
<% } else { %>
<%- StringUtils.interpolate(gettext('You can change sessions until {expiration_date}.'), {expiration_date: user_entitlement.expiration_date}) %>
<% } %>
<% } %>
</div>
<% } %>
<div class="course-actions"></div> <div class="course-actions"></div>
</div> </div>
<div class="course-certificate certificate-status"></div> <div class="course-certificate certificate-status"></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment