diff --git a/organizations/management/commands/transfer_contact_data.py b/organizations/management/commands/transfer_contact_data.py new file mode 100644 index 0000000000000000000000000000000000000000..cacf5c73a215b10060bac0893967302af265093a --- /dev/null +++ b/organizations/management/commands/transfer_contact_data.py @@ -0,0 +1,37 @@ +__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + + +import datetime + +from django.core.management.base import BaseCommand +from django.utils import timezone + +from partners.models import Partner + +from organizations.models import Contact, ContactRole + + +class Command(BaseCommand): + help = ('For Partners, transfer the data of partners.Contact instances ' + 'to organizations.Contact and ContactRole instances.') + + def handle(self, *args, **kwargs): + for partner in Partner.objects.all(): + for oldcontact in partner.contact_set.all(): + contact = Contact( + user=oldcontact.user, + title=oldcontact.title, + activation_key=oldcontact.activation_key, + key_expires=oldcontact.key_expires + ) + contact.save() + contactrole = ContactRole( + contact=contact, + organization=partner.organization, + kind=oldcontact.kind, + date_from=timezone.now(), + date_until=timezone.now() + datetime.timedelta(days=3650) + ) + contactrole.save() + oldcontact.delete() diff --git a/organizations/models.py b/organizations/models.py index 75f1e5833e587aecfedfb374f7d063660f3cbeab..146b37936cf4620751ae02b5ceda69865e4f6054 100644 --- a/organizations/models.py +++ b/organizations/models.py @@ -259,8 +259,8 @@ class Contact(models.Model): class ContactRole(models.Model): """ - A ContactRole instance links a Contact to an Organization, for a specific period of - time, and for a specific period in time. + A ContactRole instance links a Contact to an Organization, for a specific set of roles + and for a specific period in time. """ contact = models.ForeignKey('organizations.Contact', on_delete=models.CASCADE, related_name='roles') @@ -268,3 +268,12 @@ class ContactRole(models.Model): kind = ChoiceArrayField(models.CharField(max_length=4, choices=ROLE_KINDS)) date_from = models.DateField() date_until = models.DateField() + + @property + def get_kind_display(self): + """ + Due to a lack of support to use get_FOO_display in a ArrayField, one has to create + one 'manually'. + """ + choices = dict(ROLE_KINDS) + return ', '.join([choices[value] for index, value in enumerate(self.kind)]) diff --git a/organizations/templates/organizations/_organization_card.html b/organizations/templates/organizations/_organization_card.html index 8986814da202aba702763e6cc1a5582117b97f93..3f7c7df31ef06b35c13b1d2957ea9de63b4a7435 100644 --- a/organizations/templates/organizations/_organization_card.html +++ b/organizations/templates/organizations/_organization_card.html @@ -190,6 +190,12 @@ $(document).ready(function($) { {% if perms.scipost.can_manage_organizations %} <h3>Contacts (with explicit role)</h3> <table class="table"> + <tr> + <th>Name</th> + <th>Kind</th> + <th>Date from</th> + <th>Date until</th> + </tr> {% for contactrole in org.contactrole_set.all %} <tr> <td>{{ contactrole.contact }}</td> @@ -210,7 +216,7 @@ $(document).ready(function($) { </tr> {% empty %} <tr> - <td>>No contact person defined</td> + <td>No contact person defined</td> </tr> {% endfor %} </table>