|
27 | 27 | logger = logging.getLogger(__name__) |
28 | 28 |
|
29 | 29 |
|
| 30 | +class EnrollmentStatus(StrEnum): |
| 31 | + UNVERIFIED = "unverified" |
| 32 | + ACTIVE = "active" |
| 33 | + COMPLETED = "completed" |
| 34 | + DEACTIVATED = "deactivated" |
| 35 | + |
| 36 | + |
| 37 | +class DeactivationReason(StrEnum): |
| 38 | + CANCELED = "canceled" |
| 39 | + BLOCKED = "blocked" |
| 40 | + FAILED = "failed" |
| 41 | + INACTIVE = "inactive" |
| 42 | + |
| 43 | + |
| 44 | +class DeliveryStatus(StrEnum): |
| 45 | + SCHEDULED = "scheduled" |
| 46 | + PROCESSING = "processing" |
| 47 | + DELIVERED = "delivered" |
| 48 | + CANCELED = "canceled" |
| 49 | + BLOCKED = "blocked" |
| 50 | + |
| 51 | + |
30 | 52 | def is_domain_or_ip(value: str) -> None: |
31 | 53 | """ |
32 | 54 | Validate if the given value is a valid domain name or IP address. |
@@ -149,6 +171,29 @@ def delete( |
149 | 171 | ) |
150 | 172 | return super().delete(using, keep_parents) |
151 | 173 |
|
| 174 | + @property |
| 175 | + def enrollments_count(self) -> dict[str, int]: |
| 176 | + unverified_count = self.enrollment_set.filter( |
| 177 | + status=EnrollmentStatus.UNVERIFIED |
| 178 | + ).count() |
| 179 | + active_count = self.enrollment_set.filter( |
| 180 | + status=EnrollmentStatus.ACTIVE |
| 181 | + ).count() |
| 182 | + completed_count = self.enrollment_set.filter( |
| 183 | + status=EnrollmentStatus.COMPLETED |
| 184 | + ).count() |
| 185 | + deactivated_count = self.enrollment_set.filter( |
| 186 | + status=EnrollmentStatus.DEACTIVATED |
| 187 | + ).count() |
| 188 | + total_count = self.enrollment_set.count() |
| 189 | + return { |
| 190 | + EnrollmentStatus.UNVERIFIED: unverified_count, |
| 191 | + EnrollmentStatus.ACTIVE: active_count, |
| 192 | + EnrollmentStatus.COMPLETED: completed_count, |
| 193 | + EnrollmentStatus.DEACTIVATED: deactivated_count, |
| 194 | + "total": total_count, |
| 195 | + } |
| 196 | + |
152 | 197 |
|
153 | 198 | class Lesson(models.Model): |
154 | 199 | title = models.CharField(max_length=200) |
@@ -332,28 +377,6 @@ def save(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] |
332 | 377 | super().save(*args, **kwargs) |
333 | 378 |
|
334 | 379 |
|
335 | | -class EnrollmentStatus(StrEnum): |
336 | | - UNVERIFIED = "unverified" |
337 | | - ACTIVE = "active" |
338 | | - COMPLETED = "completed" |
339 | | - DEACTIVATED = "deactivated" |
340 | | - |
341 | | - |
342 | | -class DeactivationReason(StrEnum): |
343 | | - CANCELED = "canceled" |
344 | | - BLOCKED = "blocked" |
345 | | - FAILED = "failed" |
346 | | - INACTIVE = "inactive" |
347 | | - |
348 | | - |
349 | | -class DeliveryStatus(StrEnum): |
350 | | - SCHEDULED = "scheduled" |
351 | | - PROCESSING = "processing" |
352 | | - DELIVERED = "delivered" |
353 | | - CANCELED = "canceled" |
354 | | - BLOCKED = "blocked" |
355 | | - |
356 | | - |
357 | 380 | class Enrollment(models.Model): |
358 | 381 | state_transitions = { |
359 | 382 | EnrollmentStatus.UNVERIFIED: [ |
|
0 commit comments