Skip to content

Commit

Permalink
Removal coordinate set models (#546)
Browse files Browse the repository at this point in the history
* Added: Stub

* Created: Work-In-Progress Data Migration

* Fixed: Tests

* Flake8

* Version update
  • Loading branch information
deepio committed Sep 24, 2020
1 parent db9184a commit 6605967
Show file tree
Hide file tree
Showing 18 changed files with 392 additions and 349 deletions.
2 changes: 1 addition & 1 deletion rodan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# Get version: import rodan; rodan.__version__
# Version numbers also appear in the API.
__title__ = "Rodan"
__version__ = "1.2.0"
__version__ = "1.3.0"
__copyright__ = "Copyright 2011-2020 Distributed Digital Music Archives & Libraries Lab"
63 changes: 63 additions & 0 deletions rodan/migrations/0023_auto_20200915_1923.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-09-15 23:23
from __future__ import unicode_literals

from django.db import migrations
import jsonfield.fields


def forwards_func(apps, schema_editor):
"""
Auto-populate appearance data from coordinate data in coordinate set
"""
db_alias = schema_editor.connection.alias

wfj = apps.get_model("rodan", "WorkflowJob")
wfj_cs = apps.get_model("rodan", "WorkflowJobCoordinateSet")
wfjg = apps.get_model("rodan", "WorkflowJobGroup")
wfjg_cs = apps.get_model("rodan", "WorkflowJobGroupCoordinateSet")

# Django 2.2 has bulk_update, 1.11.29 does not.
for i in wfj_cs.objects.using(db_alias):
w = wfj.objects.filter(uuid=i.workflow_job.uuid).update(appearance=i.data)
for i in wfjg_cs.objects.using(db_alias):
w = wfjg.objects.filter(uuid=i.workflow_job_group.uuid).update(appearance=i.data)


class Migration(migrations.Migration):

dependencies = [
('rodan', '0022_auto_20200817_1511'),
]

operations = [
migrations.AddField(
model_name='workflowjob',
name='appearance',
field=jsonfield.fields.JSONField(blank=True, null=True),
),
migrations.AddField(
model_name='workflowjobgroup',
name='appearance',
field=jsonfield.fields.JSONField(blank=True, null=True),
),
migrations.RunPython(forwards_func),
migrations.AlterField(
model_name='workflowjob',
name='appearance',
field=jsonfield.fields.JSONField(default={b'x': 0.5, b'y': 0.5}),
preserve_default=True,
),
migrations.AlterField(
model_name='workflowjobgroup',
name='appearance',
field=jsonfield.fields.JSONField(default={b'x': 0.5, b'y': 0.5}),
preserve_default=True,
),
migrations.DeleteModel(
name='WorkflowJobCoordinateSet',
),
migrations.DeleteModel(
name='WorkflowJobGroupCoordinateSet',
),
]
10 changes: 3 additions & 7 deletions rodan/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
from rodan.models.resourcetype import ResourceType
from rodan.models.connection import Connection
from rodan.models.tempauthtoken import Tempauthtoken
from rodan.models.workflowjobcoordinateset import WorkflowJobCoordinateSet
from rodan.models.workflowjobgroupcoordinateset import WorkflowJobGroupCoordinateSet


if sys.version_info.major == 2:
Expand Down Expand Up @@ -351,8 +349,6 @@ def assign_perms_project(sender, instance, created, raw, using, update_fields, *
@receiver(post_save, sender=WorkflowJobGroup)
@receiver(post_save, sender=InputPort)
@receiver(post_save, sender=OutputPort)
@receiver(post_save, sender=WorkflowJobCoordinateSet)
@receiver(post_save, sender=WorkflowJobGroupCoordinateSet)
@receiver(post_save, sender=Connection)
@receiver(post_save, sender=RunJob)
@receiver(post_save, sender=ResultsPackage)
Expand All @@ -367,10 +363,10 @@ def assign_perms_others(sender, instance, created, raw, using, update_fields, **
project = instance.project
elif sender in (WorkflowJob, WorkflowJobGroup):
project = instance.workflow.project
elif sender in (InputPort, OutputPort, WorkflowJobCoordinateSet):
elif sender in (InputPort, OutputPort): # WorkflowJobCoordinateSet
project = instance.workflow_job.workflow.project
elif sender in (WorkflowJobGroupCoordinateSet, ):
project = instance.workflow_job_group.workflow.project
# elif sender in (WorkflowJobGroupCoordinateSet, ):
# project = instance.workflow_job_group.workflow.project
elif sender in (Connection, ):
project = instance.input_port.workflow_job.workflow.project
elif sender in (RunJob, ResultsPackage):
Expand Down
12 changes: 12 additions & 0 deletions rodan/models/workflowjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class WorkflowJob(models.Model):
- `name` -- user-defined name. Default: the same as `job_name`.
- `group` -- a nullable reference to the `WorkflowGroup` object.
- `appearance` -- a JSON field including:
`x` -- coordinate of the center position (% of the canvas size);
`y` -- `y` coordinate of the center position (% of the canvas size);
`width` -- relative width regarding the canvas size;
`height` -- relative height regarding the canvas size;
`color` (optional) -- CSS color code.
**Properties**
Expand Down Expand Up @@ -65,6 +71,12 @@ class Meta:
created = models.DateTimeField(auto_now_add=True, db_index=True)
updated = models.DateTimeField(auto_now=True, db_index=True)

# OneToOneField continuously errors and asks for unique=True when it is already present.
# For this reason, a ForeignKey is still used.
appearance = JSONField(
default={"x": 0.5, "y": 0.5},
)

def save(self, *args, **kwargs):
if not self.name:
self.name = self.job_name.split(".")[-1]
Expand Down
47 changes: 0 additions & 47 deletions rodan/models/workflowjobcoordinateset.py

This file was deleted.

12 changes: 11 additions & 1 deletion rodan/models/workflowjobgroup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
import uuid
from django.db import models
from jsonfield import JSONField


class WorkflowJobGroup(models.Model):
Expand All @@ -14,6 +15,12 @@ class WorkflowJobGroup(models.Model):
- `workflow` -- the `Workflow` that it belongs to.
- `origin` -- a nullable reference to the `Workflow` indicating where it comes
from.
- `appearance` -- a JSON field including:
`x` -- coordinate of the center position (% of the canvas size);
`y` -- `y` coordinate of the center position (% of the canvas size);
`width` -- relative width regarding the canvas size;
`height` -- relative height regarding the canvas size;
`color` (optional) -- CSS color code.
- `created`
- `updated`
Expand Down Expand Up @@ -43,6 +50,9 @@ class Meta:

created = models.DateTimeField(auto_now_add=True, db_index=True)
updated = models.DateTimeField(auto_now=True, db_index=True)
appearance = JSONField(
default={"x": 0.5, "y": 0.5},
)

def __unicode__(self):
return u"<WorkflowJobGroup {0}>".format(str(self.uuid))
50 changes: 0 additions & 50 deletions rodan/models/workflowjobgroupcoordinateset.py

This file was deleted.

Loading

0 comments on commit 6605967

Please sign in to comment.