SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 5c51aebd authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add management method to transfer contact data

parent 76d74c6a
No related branches found
No related tags found
No related merge requests found
__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()
...@@ -259,8 +259,8 @@ class Contact(models.Model): ...@@ -259,8 +259,8 @@ class Contact(models.Model):
class ContactRole(models.Model): class ContactRole(models.Model):
""" """
A ContactRole instance links a Contact to an Organization, for a specific period of A ContactRole instance links a Contact to an Organization, for a specific set of roles
time, and for a specific period in time. and for a specific period in time.
""" """
contact = models.ForeignKey('organizations.Contact', on_delete=models.CASCADE, contact = models.ForeignKey('organizations.Contact', on_delete=models.CASCADE,
related_name='roles') related_name='roles')
...@@ -268,3 +268,12 @@ class ContactRole(models.Model): ...@@ -268,3 +268,12 @@ class ContactRole(models.Model):
kind = ChoiceArrayField(models.CharField(max_length=4, choices=ROLE_KINDS)) kind = ChoiceArrayField(models.CharField(max_length=4, choices=ROLE_KINDS))
date_from = models.DateField() date_from = models.DateField()
date_until = 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)])
...@@ -190,6 +190,12 @@ $(document).ready(function($) { ...@@ -190,6 +190,12 @@ $(document).ready(function($) {
{% if perms.scipost.can_manage_organizations %} {% if perms.scipost.can_manage_organizations %}
<h3>Contacts (with explicit role)</h3> <h3>Contacts (with explicit role)</h3>
<table class="table"> <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 %} {% for contactrole in org.contactrole_set.all %}
<tr> <tr>
<td>{{ contactrole.contact }}</td> <td>{{ contactrole.contact }}</td>
...@@ -210,7 +216,7 @@ $(document).ready(function($) { ...@@ -210,7 +216,7 @@ $(document).ready(function($) {
</tr> </tr>
{% empty %} {% empty %}
<tr> <tr>
<td>>No contact person defined</td> <td>No contact person defined</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
......
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