diff --git a/scipost_django/organizations/forms.py b/scipost_django/organizations/forms.py index 24761f39d83e7701731a4d89babb523e0a2b88d6..cd4681405aaf1420fe562169b6d2da587a7b93f9 100644 --- a/scipost_django/organizations/forms.py +++ b/scipost_django/organizations/forms.py @@ -165,6 +165,21 @@ class ContactPersonForm(forms.ModelForm): class Meta: model = ContactPerson fields = "__all__" + widgets = { + "date_deprecated": forms.DateInput(attrs={"type": "date"}), + } + + def clean(self): + cleaned_data = super().clean() + date_deprecated = cleaned_data.get("date_deprecated") + status = cleaned_data.get("status") + + if status == ContactPerson.STATUS_DEPRECATED and not date_deprecated: + self.add_error("date_deprecated", "A deprecation date is required.") + elif status != ContactPerson.STATUS_DEPRECATED and date_deprecated: + self.add_error("status", "Status must be set to 'Deprecated'.") + + return cleaned_data def clean_email(self): """ @@ -219,6 +234,12 @@ class NewContactForm(ContactForm): first_name = forms.CharField() last_name = forms.CharField() email = forms.CharField() + status = forms.ChoiceField( + choices=ContactPerson.STATUS_CHOICES, initial=ContactPerson.STATUS_UNKNOWN + ) + date_deprecated = forms.DateField( + required=False, widget=forms.DateInput(attrs={"type": "date"}) + ) existing_user = None def __init__(self, *args, **kwargs): diff --git a/scipost_django/organizations/migrations/0022_contactperson_date_deprecated_contactperson_status.py b/scipost_django/organizations/migrations/0022_contactperson_date_deprecated_contactperson_status.py new file mode 100644 index 0000000000000000000000000000000000000000..90fb986366c47061122fdc6f773d20be38063823 --- /dev/null +++ b/scipost_django/organizations/migrations/0022_contactperson_date_deprecated_contactperson_status.py @@ -0,0 +1,30 @@ +# Generated by Django 4.2.15 on 2024-10-08 12:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("organizations", "0021_enable_unaccent"), + ] + + operations = [ + migrations.AddField( + model_name="contactperson", + name="date_deprecated", + field=models.DateField(blank=True, null=True), + ), + migrations.AddField( + model_name="contactperson", + name="status", + field=models.CharField( + choices=[ + ("unknown", "Unknown"), + ("active", "Active"), + ("deprecated", "Deprecated"), + ], + default="unknown", + max_length=16, + ), + ), + ] diff --git a/scipost_django/organizations/models.py b/scipost_django/organizations/models.py index fc5f3be249fe87f4b7ed1b848cf49919e11c2753..78d7971b6eff30a76a56c55c1874b7d114a2a65a 100644 --- a/scipost_django/organizations/models.py +++ b/scipost_django/organizations/models.py @@ -693,6 +693,15 @@ class ContactPerson(models.Model): Instances can be promoted to Contact instances, which possess login credentials. """ + STATUS_UNKNOWN = "unknown" + STATUS_ACTIVE = "active" + STATUS_DEPRECATED = "deprecated" + STATUS_CHOICES = ( + (STATUS_UNKNOWN, "Unknown"), + (STATUS_ACTIVE, "Active"), + (STATUS_DEPRECATED, "Deprecated"), + ) + organization = models.ForeignKey( "organizations.Organization", on_delete=models.CASCADE ) @@ -701,6 +710,10 @@ class ContactPerson(models.Model): last_name = models.CharField(max_length=64) email = models.EmailField() role = models.CharField(max_length=128) + status = models.CharField( + max_length=16, choices=STATUS_CHOICES, default=STATUS_UNKNOWN + ) + date_deprecated = models.DateField(blank=True, null=True) class Meta: ordering = ["last_name", "first_name", "organization"] diff --git a/scipost_django/organizations/templates/organizations/_organization_card.html b/scipost_django/organizations/templates/organizations/_organization_card.html index e1715d7c7e19dd32386e328a24f76826b303d303..00f9598b7a8f161311c94281c391336f24381f63 100644 --- a/scipost_django/organizations/templates/organizations/_organization_card.html +++ b/scipost_django/organizations/templates/organizations/_organization_card.html @@ -769,12 +769,27 @@ {% endif %} <table class="table"> + <tr> + <th>Name</th> + <th>Email</th> + <th>Role</th> + <th>Status</th> + + {% if perms.scipost.can_manage_organizations or "can_view_org_contacts" in user_org_perms %} + <th>Actions</th> + {% endif %} + </tr> {% for contactperson in org.contactperson_set.all %} <tr> <td>{{ contactperson }}</td> <td>{{ contactperson.email }}</td> <td>{{ contactperson.role }}</td> + <td>{{ contactperson.get_status_display }} + {% if contactperson.status == 'deprecated' %} + <div class="text-muted">{{ contactperson.date_deprecated|date:"Y-m-d" }}</div> + {% endif %} + </td> {% if perms.scipost.can_manage_organizations or "can_view_org_contacts" in user_org_perms %} <td>