SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 772a17ea authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add status fields to contact person

parent a1d58577
No related branches found
No related tags found
No related merge requests found
...@@ -165,6 +165,21 @@ class ContactPersonForm(forms.ModelForm): ...@@ -165,6 +165,21 @@ class ContactPersonForm(forms.ModelForm):
class Meta: class Meta:
model = ContactPerson model = ContactPerson
fields = "__all__" 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): def clean_email(self):
""" """
...@@ -219,6 +234,12 @@ class NewContactForm(ContactForm): ...@@ -219,6 +234,12 @@ class NewContactForm(ContactForm):
first_name = forms.CharField() first_name = forms.CharField()
last_name = forms.CharField() last_name = forms.CharField()
email = 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 existing_user = None
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
......
# 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,
),
),
]
...@@ -693,6 +693,15 @@ class ContactPerson(models.Model): ...@@ -693,6 +693,15 @@ class ContactPerson(models.Model):
Instances can be promoted to Contact instances, which possess login credentials. 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( organization = models.ForeignKey(
"organizations.Organization", on_delete=models.CASCADE "organizations.Organization", on_delete=models.CASCADE
) )
...@@ -701,6 +710,10 @@ class ContactPerson(models.Model): ...@@ -701,6 +710,10 @@ class ContactPerson(models.Model):
last_name = models.CharField(max_length=64) last_name = models.CharField(max_length=64)
email = models.EmailField() email = models.EmailField()
role = models.CharField(max_length=128) 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: class Meta:
ordering = ["last_name", "first_name", "organization"] ordering = ["last_name", "first_name", "organization"]
......
...@@ -769,12 +769,27 @@ ...@@ -769,12 +769,27 @@
{% endif %} {% endif %}
<table class="table"> <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 %} {% for contactperson in org.contactperson_set.all %}
<tr> <tr>
<td>{{ contactperson }}</td> <td>{{ contactperson }}</td>
<td>{{ contactperson.email }}</td> <td>{{ contactperson.email }}</td>
<td>{{ contactperson.role }}</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 %} {% if perms.scipost.can_manage_organizations or "can_view_org_contacts" in user_org_perms %}
<td> <td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment