add reason hover card

This commit is contained in:
2026-01-26 15:52:33 -03:00
parent 631087ac9b
commit 96a8ee8775
4 changed files with 62 additions and 24 deletions

View File

@@ -19,7 +19,7 @@ from layercake.dynamodb import (
TransactKey,
)
from layercake.strutils import md5_hash
from pydantic import UUID4, BaseModel, BeforeValidator, Field, FutureDate
from pydantic import UUID4, BaseModel, BeforeValidator, Field
from boto3clients import dynamodb_client
from config import (
@@ -42,6 +42,9 @@ class DeduplicationConflictError(Exception): ...
class EnrollmentConflictError(Exception): ...
class DeadlineExceededError(Exception): ...
class User(BaseModel):
id: str
name: str
@@ -200,9 +203,12 @@ def _get_courses(ids: set[str]) -> tuple[Course, ...]:
def _friendly_reason(reason: str) -> str:
if reason == 'DeduplicationConflictError':
return 'DEDUPLICATION'
return 'CONFLICT'
reasons = {
'DeduplicationConflictError': 'DEDUPLICATION',
'DeadlineExceededError': 'DEADLINE',
}
return reasons.get(reason, 'CONFLICT')
CreatedBy = TypedDict('CreatedBy', {'user_id': str, 'name': str})
@@ -341,6 +347,9 @@ def _enroll_later(enrollment: Enrollment, context: Context) -> None:
scheduled_for = _date_to_midnight(enrollment.scheduled_for) # type: ignore
lock_hash = md5_hash(f'{user.id}{course.id}')
if now_ > scheduled_for:
raise DeadlineExceededError('Deadline exceeded')
with dyn.transact_writer(table_name=ENROLLMENT_TABLE) as transact:
pk = f'SCHEDULED#ORG#{org.id}'
sk = f'{scheduled_for.isoformat()}#{lock_hash}'