|
1 | 1 | from django.conf import settings |
| 2 | +from django.contrib.auth import get_user_model |
2 | 3 | from django.db import models |
3 | 4 | from django.shortcuts import redirect |
4 | 5 | from django.urls import reverse |
|
26 | 27 |
|
27 | 28 | from ..workflows import DRAFT_STATE, WORKFLOWS |
28 | 29 |
|
| 30 | +User = get_user_model() |
| 31 | + |
29 | 32 | REVIEW_GROUPS = [ |
30 | 33 | STAFF_GROUP_NAME, |
31 | 34 | REVIEWER_GROUP_NAME, |
@@ -200,3 +203,50 @@ def send_mail(self, submission): |
200 | 203 | ] |
201 | 204 |
|
202 | 205 | email_tab = ObjectList(email_confirmation_panels, heading=_("Confirmation email")) |
| 206 | + |
| 207 | + |
| 208 | +class SubmissionCoApplicantRole(models.Model): |
| 209 | + code = models.CharField(max_length=50, unique=True) |
| 210 | + name = models.CharField(max_length=100) |
| 211 | + description = models.TextField(blank=True) |
| 212 | + |
| 213 | + def __str__(self): |
| 214 | + return self.name |
| 215 | + |
| 216 | + |
| 217 | +class SubmissionCoApplicantInviteStatus(models.TextChoices): |
| 218 | + PENDING = "pending", "Pending" |
| 219 | + ACCEPTED = "accepted", "Accepted" |
| 220 | + REJECTED = "rejected", "Rejected" |
| 221 | + EXPIRED = "expired", "Expired" |
| 222 | + |
| 223 | + |
| 224 | +class SubmissionCoApplicant(models.Model): |
| 225 | + submission = models.ForeignKey( |
| 226 | + "funds.ApplicationSubmission", |
| 227 | + on_delete=models.CASCADE, |
| 228 | + related_name="co-applicants", |
| 229 | + ) |
| 230 | + user = models.ForeignKey( |
| 231 | + User, on_delete=models.CASCADE, related_name="co-applicants" |
| 232 | + ) |
| 233 | + role = models.ManyToManyField( |
| 234 | + SubmissionCoApplicantRole, related_name="co-applicants" |
| 235 | + ) |
| 236 | + |
| 237 | + status = models.CharField( |
| 238 | + max_length=20, |
| 239 | + choices=SubmissionCoApplicantInviteStatus.choices, |
| 240 | + default=SubmissionCoApplicantInviteStatus.PENDING, |
| 241 | + ) |
| 242 | + # invited_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True, related_name="co-applicant_invites") |
| 243 | + invited_on = models.DateTimeField(auto_now_add=True) |
| 244 | + responded_on = models.DateTimeField(null=True, blank=True) |
| 245 | + |
| 246 | + class Meta: |
| 247 | + unique_together = ("submission", "user") |
| 248 | + |
| 249 | + def __str__(self): |
| 250 | + return ( |
| 251 | + f"{self.user} invited to {self.submission} as {self.role} ({self.status})" |
| 252 | + ) |
0 commit comments