Skip to content

Commit

Permalink
Add is_active field to DataPrepWorkspace model
Browse files Browse the repository at this point in the history
Update the migration. Show the is_active field in the table. Show
the is_active status on the detail page. Add the field to the
workspace data form.
  • Loading branch information
amstilp committed Nov 9, 2023
1 parent 5fd7a5b commit 64c8331
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions primed/miscellaneous_workspaces/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class Meta:
"workspace",
"target_workspace",
"requested_by",
"is_active",
)
# widgets = {
# "studies": autocomplete.ModelSelect2Multiple(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.19 on 2023-11-07 18:52
# Generated by Django 3.2.19 on 2023-11-09 22:11

from django.conf import settings
from django.db import migrations, models
Expand All @@ -10,7 +10,7 @@
class Migration(migrations.Migration):

dependencies = [
('anvil_consortium_manager', '0013_alter_anvilprojectmanageraccess_options'),
('anvil_consortium_manager', '0015_add_new_permissions'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('miscellaneous_workspaces', '0007_openaccessworkspace_data_url'),
]
Expand All @@ -22,6 +22,7 @@ class Migration(migrations.Migration):
('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
('is_active', models.BooleanField(default=True, help_text='Indicator of whether this workspace is currently being used for data preparation.')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
Expand All @@ -45,6 +46,7 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
('is_active', models.BooleanField(default=True, help_text='Indicator of whether this workspace is currently being used for data preparation.')),
('requested_by', models.ForeignKey(help_text='The user who requested creation.', on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
('target_workspace', models.ForeignKey(help_text='The workspace for which data is being prepared or updated.', on_delete=django.db.models.deletion.PROTECT, related_name='data_prep_workspaces', to='anvil_consortium_manager.workspace')),
('workspace', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='anvil_consortium_manager.workspace')),
Expand Down
4 changes: 4 additions & 0 deletions primed/miscellaneous_workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class DataPrepWorkspace(RequesterModel, TimeStampedModel, BaseWorkspaceData):
related_name="data_prep_workspaces",
help_text="The workspace for which data is being prepared or updated.",
)
is_active = models.BooleanField(
default=True,
help_text="Indicator of whether this workspace is currently being used to prepare data.",
)

def clean(self):
if hasattr(self, "target_workspace"):
Expand Down
9 changes: 8 additions & 1 deletion primed/miscellaneous_workspaces/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import django_tables2 as tables
from anvil_consortium_manager.models import Workspace

from primed.primed_anvil.tables import WorkspaceSharedWithConsortiumColumn
from primed.primed_anvil.tables import (
BooleanIconColumn,
WorkspaceSharedWithConsortiumColumn,
)


class OpenAccessWorkspaceTable(tables.Table):
Expand Down Expand Up @@ -50,11 +53,15 @@ class DataPrepWorkspaceTable(tables.Table):
dataprepworkspace__target_workspace__name = tables.columns.Column(
linkify=True, verbose_name="Target workspace"
)
dataprepworkspace__is_active = BooleanIconColumn(
verbose_name="Active?", show_false_icon=True
)

class Meta:
model = Workspace
fields = (
"name",
"dataprepworkspace__target_workspace__name",
"dataprepworkspace__is_active",
)
order_by = ("name",)
16 changes: 16 additions & 0 deletions primed/miscellaneous_workspaces/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,22 @@ def test_status_code_with_user_permission(self):
# Includes link to target workspace.
self.assertContains(response, obj.target_workspace.get_absolute_url())

def test_template_active(self):
"""Returns successful response code."""
obj = factories.DataPrepWorkspaceFactory.create()
self.client.force_login(self.user)
response = self.client.get(obj.workspace.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Active")

def test_template_inactive(self):
"""Returns successful response code."""
obj = factories.DataPrepWorkspaceFactory.create(is_active=False)
self.client.force_login(self.user)
response = self.client.get(obj.workspace.get_absolute_url())
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Inactive")


class DataPrepWorkspaceCreateTest(AnVILAPIMockTestMixin, TestCase):
"""Tests of the WorkspaceCreate view from ACM with this app's DataPrepWorkspace model."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@
<dt class="col-sm-2">Target type</dt><dd class="col-sm-10">
{{ object.dataprepworkspace.target_workspace.workspace_type }}
</dd>
<dt class="col-sm-2">Status</dt><dd class="col-sm-10">
{% if object.dataprepworkspace.is_active %}
Active <i class="bi bi-check-circle-fill bi-align-center px-2" style="color: green;"></i>
{% else %}
Inactive <i class="bi bi-x-circle-fill bi-align-center px-2" style="color: red;"></i>
{% endif %}
</dd>
</dl>
{% endblock workspace_data %}

0 comments on commit 64c8331

Please sign in to comment.