From 38ca8cb6e95f14fcd2f23c1946d085b9344574ad Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Sat, 22 Sep 2018 15:49:03 +0200 Subject: [PATCH] Move from organization fields to org fields --- funders/migrations/0009_funder_org.py | 22 +++++++++++++ .../migrations/0010_repopulate_funder_orgs.py | 26 +++++++++++++++ .../0011_remove_funder_organization.py | 19 +++++++++++ funders/models.py | 2 +- journals/forms.py | 10 +++--- .../migrations/0038_auto_20180922_1505.py | 27 +++++++++++++++ journals/migrations/0039_repopulate_orgs.py | 33 +++++++++++++++++++ .../migrations/0040_auto_20180922_1544.py | 28 ++++++++++++++++ journals/models.py | 8 ++--- partners/forms.py | 2 +- partners/migrations/0014_partner_org.py | 22 +++++++++++++ .../0015_repopulate_partner_orgs.py | 26 +++++++++++++++ .../0016_remove_partner_organization.py | 19 +++++++++++ partners/models.py | 2 +- .../0006_repopulate_petsign_orgs.py | 1 - 15 files changed, 234 insertions(+), 13 deletions(-) create mode 100644 funders/migrations/0009_funder_org.py create mode 100644 funders/migrations/0010_repopulate_funder_orgs.py create mode 100644 funders/migrations/0011_remove_funder_organization.py create mode 100644 journals/migrations/0038_auto_20180922_1505.py create mode 100644 journals/migrations/0039_repopulate_orgs.py create mode 100644 journals/migrations/0040_auto_20180922_1544.py create mode 100644 partners/migrations/0014_partner_org.py create mode 100644 partners/migrations/0015_repopulate_partner_orgs.py create mode 100644 partners/migrations/0016_remove_partner_organization.py diff --git a/funders/migrations/0009_funder_org.py b/funders/migrations/0009_funder_org.py new file mode 100644 index 000000000..a195dcae2 --- /dev/null +++ b/funders/migrations/0009_funder_org.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-22 13:05 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organizations', '0002_populate_from_partners_org'), + ('funders', '0008_auto_20180715_0521'), + ] + + operations = [ + migrations.AddField( + model_name='funder', + name='org', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='organizations.Organization'), + ), + ] diff --git a/funders/migrations/0010_repopulate_funder_orgs.py b/funders/migrations/0010_repopulate_funder_orgs.py new file mode 100644 index 000000000..e8cba9d1e --- /dev/null +++ b/funders/migrations/0010_repopulate_funder_orgs.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-22 13:11 +from __future__ import unicode_literals + +from django.db import migrations + + +def repopulate_organization_field(apps, schema_editor): + Funder = apps.get_model('funders', 'Funder') + Organization = apps.get_model('organizations', 'Organization') + + for funder in Funder.objects.all(): + funder.org = Organization.objects.get(name=funder.organization.name) + funder.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('funders', '0009_funder_org'), + ] + + operations = [ + migrations.RunPython(repopulate_organization_field, + reverse_code=migrations.RunPython.noop), + ] diff --git a/funders/migrations/0011_remove_funder_organization.py b/funders/migrations/0011_remove_funder_organization.py new file mode 100644 index 000000000..27ad906b0 --- /dev/null +++ b/funders/migrations/0011_remove_funder_organization.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-22 13:44 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('funders', '0010_repopulate_funder_orgs'), + ] + + operations = [ + migrations.RemoveField( + model_name='funder', + name='organization', + ), + ] diff --git a/funders/models.py b/funders/models.py index 563940566..0fa4d8ef5 100644 --- a/funders/models.py +++ b/funders/models.py @@ -23,7 +23,7 @@ class Funder(models.Model): name = models.CharField(max_length=256) acronym = models.CharField(max_length=32, blank=True) identifier = models.CharField(max_length=200, unique=True) - organization = models.ForeignKey('partners.Organization', on_delete=models.CASCADE, + org = models.ForeignKey('organizations.Organization', on_delete=models.CASCADE, blank=True, null=True) objects = FunderQuerySet.as_manager() diff --git a/journals/forms.py b/journals/forms.py index 5eb705372..6facc6eeb 100644 --- a/journals/forms.py +++ b/journals/forms.py @@ -29,7 +29,7 @@ from .signals import notify_manuscript_published from funders.models import Grant, Funder from journals.models import Journal from mails.utils import DirectMailUtil -from partners.models import Organization +from organizations.models import Organization from production.constants import PROOFS_PUBLISHED from production.models import ProductionEvent from production.signals import notify_stream_status_change @@ -125,7 +125,7 @@ PublicationAuthorOrderingFormSet = modelformset_factory( class AuthorsTableOrganizationSelectForm(forms.ModelForm): - organization = AutoCompleteSelectField('organization_lookup') + org = AutoCompleteSelectField('organization_lookup') class Meta: model = PublicationAuthorsTable @@ -697,12 +697,12 @@ class PublicationPublishForm(RequestFormMixin, forms.ModelForm): class SetOrgPubFractionForm(forms.ModelForm): class Meta: model = OrgPubFraction - fields = ['organization', 'publication', 'fraction'] + fields = ['org', 'publication', 'fraction'] def __init__(self, *args, **kwargs): super(SetOrgPubFractionForm, self).__init__(*args, **kwargs) if self.instance.id: - self.fields['organization'].disabled = True + self.fields['org'].disabled = True self.fields['publication'].widget = forms.HiddenInput() @@ -721,6 +721,6 @@ class BaseOrgPubFractionsFormSet(BaseModelFormSet): OrgPubFractionsFormSet = modelformset_factory(OrgPubFraction, - fields=('publication', 'organization', 'fraction'), + fields=('publication', 'org', 'fraction'), formset=BaseOrgPubFractionsFormSet, form=SetOrgPubFractionForm, extra=0) diff --git a/journals/migrations/0038_auto_20180922_1505.py b/journals/migrations/0038_auto_20180922_1505.py new file mode 100644 index 000000000..288d60faf --- /dev/null +++ b/journals/migrations/0038_auto_20180922_1505.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-22 13:05 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organizations', '0002_populate_from_partners_org'), + ('journals', '0037_publication_pubfractions_confirmed_by_authors'), + ] + + operations = [ + migrations.AddField( + model_name='orgpubfraction', + name='org', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='pubfractions', to='organizations.Organization'), + ), + migrations.AddField( + model_name='publicationauthorstable', + name='affs', + field=models.ManyToManyField(blank=True, to='organizations.Organization'), + ), + ] diff --git a/journals/migrations/0039_repopulate_orgs.py b/journals/migrations/0039_repopulate_orgs.py new file mode 100644 index 000000000..cfdd1c8c6 --- /dev/null +++ b/journals/migrations/0039_repopulate_orgs.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-22 13:14 +from __future__ import unicode_literals + +from django.db import migrations + + +def repopulate_organization_field(apps, schema_editor): + OrgPubFraction = apps.get_model('journals', 'OrgPubFraction') + PublicationAuthorsTable = apps.get_model('journals', 'PublicationAuthorsTable') + Organization = apps.get_model('organizations', 'Organization') + + for frac in OrgPubFraction.objects.all(): + frac.org = Organization.objects.get(name=frac.organization.name) + frac.save() + + for tbl in PublicationAuthorsTable.objects.all(): + for aff in tbl.affiliations.all(): + org = Organization.objects.get(name=aff.name) + tbl.affs.add(org) + tbl.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('journals', '0038_auto_20180922_1505'), + ] + + operations = [ + migrations.RunPython(repopulate_organization_field, + reverse_code=migrations.RunPython.noop), + ] diff --git a/journals/migrations/0040_auto_20180922_1544.py b/journals/migrations/0040_auto_20180922_1544.py new file mode 100644 index 000000000..1283556bf --- /dev/null +++ b/journals/migrations/0040_auto_20180922_1544.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-22 13:44 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('organizations', '0002_populate_from_partners_org'), + ('journals', '0039_repopulate_orgs'), + ] + + operations = [ + migrations.RemoveField( + model_name='publicationauthorstable', + name='affiliations', + ), + migrations.RemoveField( + model_name='orgpubfraction', + name='organization', + ), + migrations.AlterUniqueTogether( + name='orgpubfraction', + unique_together=set([('org', 'publication')]), + ), + ] diff --git a/journals/models.py b/journals/models.py index 45e29146c..ea538baea 100644 --- a/journals/models.py +++ b/journals/models.py @@ -41,7 +41,7 @@ class PublicationAuthorsTable(models.Model): unregistered_author = models.ForeignKey('journals.UnregisteredAuthor', null=True, blank=True, related_name='+') contributor = models.ForeignKey('scipost.Contributor', null=True, blank=True, related_name='+') - affiliations = models.ManyToManyField('partners.Organization', blank=True) + affs = models.ManyToManyField('organizations.Organization', blank=True) order = models.PositiveSmallIntegerField() class Meta: @@ -619,14 +619,14 @@ class OrgPubFraction(models.Model): To be set (ideally) during production phase, based on information provided by the authors. """ - organization = models.ForeignKey('partners.Organization', on_delete=models.CASCADE, - related_name='pubfractions') + org = models.ForeignKey('organizations.Organization', on_delete=models.CASCADE, + related_name='pubfractions', blank=True, null=True) publication = models.ForeignKey('journals.Publication', on_delete=models.CASCADE, related_name='pubfractions') fraction = models.DecimalField(max_digits=4, decimal_places=3) class Meta: - unique_together = (('organization', 'publication'),) + unique_together = (('org', 'publication'),) class Deposit(models.Model): diff --git a/partners/forms.py b/partners/forms.py index f4a94bd97..02345d6c3 100644 --- a/partners/forms.py +++ b/partners/forms.py @@ -149,7 +149,7 @@ class PartnerForm(forms.ModelForm): model = Partner fields = ( 'institution', - 'organization', + 'org', 'status', 'main_contact' ) diff --git a/partners/migrations/0014_partner_org.py b/partners/migrations/0014_partner_org.py new file mode 100644 index 000000000..4f098b2e0 --- /dev/null +++ b/partners/migrations/0014_partner_org.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-22 13:05 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organizations', '0002_populate_from_partners_org'), + ('partners', '0013_auto_20180715_0938'), + ] + + operations = [ + migrations.AddField( + model_name='partner', + name='org', + field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='organizations.Organization'), + ), + ] diff --git a/partners/migrations/0015_repopulate_partner_orgs.py b/partners/migrations/0015_repopulate_partner_orgs.py new file mode 100644 index 000000000..d64f0d5bd --- /dev/null +++ b/partners/migrations/0015_repopulate_partner_orgs.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-22 13:05 +from __future__ import unicode_literals + +from django.db import migrations + + +def repopulate_organization_field(apps, schema_editor): + Partner = apps.get_model('partners', 'Partner') + Organization = apps.get_model('organizations', 'Organization') + + for partner in Partner.objects.all(): + partner.org = Organization.objects.get(name=partner.organization.name) + partner.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('partners', '0014_partner_org'), + ] + + operations = [ + migrations.RunPython(repopulate_organization_field, + reverse_code=migrations.RunPython.noop), + ] diff --git a/partners/migrations/0016_remove_partner_organization.py b/partners/migrations/0016_remove_partner_organization.py new file mode 100644 index 000000000..971aa4b28 --- /dev/null +++ b/partners/migrations/0016_remove_partner_organization.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-09-22 13:44 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('partners', '0015_repopulate_partner_orgs'), + ] + + operations = [ + migrations.RemoveField( + model_name='partner', + name='organization', + ), + ] diff --git a/partners/models.py b/partners/models.py index 78de4764b..38e0f7264 100644 --- a/partners/models.py +++ b/partners/models.py @@ -358,7 +358,7 @@ class Partner(models.Model): """ institution = models.ForeignKey('partners.Institution', on_delete=models.CASCADE, blank=True, null=True) - organization = models.OneToOneField('partners.Organization', on_delete=models.CASCADE, + org = models.OneToOneField('organizations.Organization', on_delete=models.CASCADE, blank=True, null=True) status = models.CharField(max_length=16, choices=PARTNER_STATUS, default=PARTNER_INITIATED) main_contact = models.ForeignKey('partners.Contact', on_delete=models.SET_NULL, diff --git a/petitions/migrations/0006_repopulate_petsign_orgs.py b/petitions/migrations/0006_repopulate_petsign_orgs.py index a82629b89..8231d634e 100644 --- a/petitions/migrations/0006_repopulate_petsign_orgs.py +++ b/petitions/migrations/0006_repopulate_petsign_orgs.py @@ -8,7 +8,6 @@ from django.db import migrations def repopulate_organization_field(apps, schema_editor): PetitionSignatory = apps.get_model('petitions', 'PetitionSignatory') Organization = apps.get_model('organizations', 'Organization') - PartnersOrganization = apps.get_model('partners', 'Organization') for petsign in PetitionSignatory.objects.all(): if petsign.organization_tbd: -- GitLab