Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/change example workspace to resource workspace #534

Merged
merged 8 commits into from
Apr 25, 2024
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: isort

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
rev: 7.0.0
hooks:
- id: flake8
args: ['--config=setup.cfg']
Expand Down
2 changes: 1 addition & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
# Specify the path to the service account to use for managing access on AnVIL.
ANVIL_API_SERVICE_ACCOUNT_FILE = env("ANVIL_API_SERVICE_ACCOUNT_FILE")
ANVIL_WORKSPACE_ADAPTERS = [
"gregor_django.gregor_anvil.adapters.ExampleWorkspaceAdapter",
"gregor_django.gregor_anvil.adapters.ResourceWorkspaceAdapter",
"gregor_django.gregor_anvil.adapters.TemplateWorkspaceAdapter",
"gregor_django.gregor_anvil.adapters.UploadWorkspaceAdapter",
"gregor_django.gregor_anvil.adapters.PartnerUploadWorkspaceAdapter",
Expand Down
18 changes: 8 additions & 10 deletions gregor_django/gregor_anvil/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,16 @@ class PartnerUploadWorkspaceAdapter(BaseWorkspaceAdapter):
workspace_detail_template_name = "gregor_anvil/partneruploadworkspace_detail.html"


class ExampleWorkspaceAdapter(BaseWorkspaceAdapter):
"""Adapter for ExampleWorkspaces."""
class ResourceWorkspaceAdapter(BaseWorkspaceAdapter):
"""Adapter for ResourceWorkspaces."""

type = "example"
name = "Example workspace"
description = (
"Workspaces that contain examples of using AnVIL, working with data, etc."
)
type = "resource"
name = "Resource workspace"
description = "Workspaces that contain general Consortium resources (e.g., examples of using AnVIL, working with data, etc.)" # noqa: E501
list_table_class = tables.DefaultWorkspaceTable
workspace_data_model = models.ExampleWorkspace
workspace_data_form_class = forms.ExampleWorkspaceForm
workspace_detail_template_name = "anvil_consortium_manager/workspace_detail.html"
workspace_data_model = models.ResourceWorkspace
workspace_data_form_class = forms.ResourceWorkspaceForm
workspace_detail_template_name = "gregor_anvil/resourceworkspace_detail.html"
workspace_form_class = WorkspaceForm


Expand Down
6 changes: 3 additions & 3 deletions gregor_django/gregor_anvil/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class PartnerUploadWorkspaceAdmin(SimpleHistoryAdmin):
)


@admin.register(models.ExampleWorkspace)
class ExampleWorkspaceAdmin(SimpleHistoryAdmin):
"""Admin class for the ExampleWorkspace model."""
@admin.register(models.ResourceWorkspace)
class ResourceWorkspaceAdmin(SimpleHistoryAdmin):
"""Admin class for the ResourceWorkspace model."""

list_display = (
"id",
Expand Down
11 changes: 7 additions & 4 deletions gregor_django/gregor_anvil/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ class Meta:
}


class ExampleWorkspaceForm(forms.ModelForm):
"""Form for a ExampleWorkspace object."""
class ResourceWorkspaceForm(forms.ModelForm):
"""Form for a ResourceWorkspace object."""

class Meta:
model = models.ExampleWorkspace
fields = ("workspace",)
model = models.ResourceWorkspace
fields = (
"workspace",
"brief_description",
)


class TemplateWorkspaceForm(forms.ModelForm):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.11 on 2024-04-25 22:06

from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("anvil_consortium_manager", "0015_add_new_permissions"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("gregor_anvil", "0020_alter_exchangeworkspace_research_center"),
]

operations = [
migrations.RenameModel(
old_name="HistoricalExampleWorkspace",
new_name="HistoricalResourceWorkspace",
),
migrations.RenameModel(
old_name="ExampleWorkspace",
new_name="ResourceWorkspace",
),
migrations.AlterModelOptions(
name="historicalresourceworkspace",
options={
"get_latest_by": ("history_date", "history_id"),
"ordering": ("-history_date", "-history_id"),
"verbose_name": "historical resource workspace",
"verbose_name_plural": "historical resource workspaces",
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.11 on 2024-04-25 22:17


from django.db import migrations


def workspace_type_example_to_resource(apps, schema_editor):
"""Change the workspace type from "example" to "resource"."""
Workspace = apps.get_model("anvil_consortium_manager", "Workspace")

for row in Workspace.objects.filter(workspace_type="example"):
row.workspace_type = "resource"
row.save(update_fields=["workspace_type"])


def workspace_type_resource_to_example(apps, schema_editor):
"""Change the workspace type from "resource" to "example"."""
Workspace = apps.get_model("anvil_consortium_manager", "Workspace")

for row in Workspace.objects.filter(workspace_type="resource"):
row.workspace_type = "example"
row.save(update_fields=["workspace_type"])


class Migration(migrations.Migration):

dependencies = [
('gregor_anvil', '0021_rename_exampleworkspace_to_resourceworkspace'),
]

operations = [
migrations.RunPython(workspace_type_example_to_resource, reverse_code=workspace_type_resource_to_example),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.11 on 2024-04-25 23:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("gregor_anvil", "0022_update_exampleworkspace_workspace_type_field"),
]

operations = [
migrations.AddField(
model_name="historicalresourceworkspace",
name="brief_description",
field=models.TextField(default=""),
preserve_default=False,
),
migrations.AddField(
model_name="resourceworkspace",
name="brief_description",
field=models.TextField(default=""),
preserve_default=False,
),
]
6 changes: 4 additions & 2 deletions gregor_django/gregor_anvil/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ class Meta:
]


class ExampleWorkspace(TimeStampedModel, BaseWorkspaceData):
"""A model to track example workspaces."""
class ResourceWorkspace(TimeStampedModel, BaseWorkspaceData):
"""A model to track resource workspaces."""

brief_description = models.TextField()


class TemplateWorkspace(TimeStampedModel, BaseWorkspaceData):
Expand Down
9 changes: 5 additions & 4 deletions gregor_django/gregor_anvil/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,17 @@ class Meta:
model = models.PartnerUploadWorkspace


class ExampleWorkspaceFactory(DjangoModelFactory):
"""A factory for the ExampleWorkspace model."""
class ResourceWorkspaceFactory(DjangoModelFactory):
"""A factory for the ResourceWorkspace model."""

workspace = SubFactory(
WorkspaceFactory,
workspace_type="example",
workspace_type="resource",
)
brief_description = Faker("sentence")

class Meta:
model = models.ExampleWorkspace
model = models.ResourceWorkspace


class TemplateWorkspaceFactory(DjangoModelFactory):
Expand Down
21 changes: 18 additions & 3 deletions gregor_django/gregor_anvil/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ def test_invalid_duplicate_object(self):
self.assertIn("already exists", non_field_errors[0])


class ExampleWorkspaceFormTest(TestCase):
class ResourceWorkspaceFormTest(TestCase):

form_class = forms.ExampleWorkspaceForm
form_class = forms.ResourceWorkspaceForm

def setUp(self):
"""Create a workspace for use in the form."""
Expand All @@ -292,20 +292,35 @@ def test_valid(self):
"""Form is valid with necessary input."""
form_data = {
"workspace": self.workspace,
"brief_description": "Test use",
}
form = self.form_class(data=form_data)
self.assertTrue(form.is_valid())

def test_invalid_missing_workspace(self):
"""Form is invalid when missing workspace."""
form_data = {}
form_data = {
"brief_description": "Test use",
}
form = self.form_class(data=form_data)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn("workspace", form.errors)
self.assertEqual(len(form.errors["workspace"]), 1)
self.assertIn("required", form.errors["workspace"][0])

def test_invalid_missing_intended_use(self):
"""Form is invalid when missing intended_use."""
form_data = {
"workspace": self.workspace,
}
form = self.form_class(data=form_data)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertIn("brief_description", form.errors)
self.assertEqual(len(form.errors["brief_description"]), 1)
self.assertIn("required", form.errors["brief_description"][0])


class TemplateWorkspaceFormTest(TestCase):

Expand Down
Loading
Loading