Skip to content

Commit

Permalink
Merge pull request #724 from NASA-IMPACT/2208-add-dates-on-status-cha…
Browse files Browse the repository at this point in the history
…nge-on-the-webapp

2208 add dates on status change on the webapp
  • Loading branch information
bishwaspraveen authored May 15, 2024
2 parents 34ff8b0 + 0bf293a commit cf3a8e5
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 18 deletions.
30 changes: 13 additions & 17 deletions sde_collections/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.http import HttpResponse

from .models.candidate_url import CandidateURL
from .models.collection import Collection
from .models.collection import Collection, WorkflowStatusHistory
from .models.pattern import IncludePattern, TitlePattern
from .tasks import import_candidate_urls_from_api

Expand All @@ -22,10 +22,7 @@ def generate_deployment_message(modeladmin, request, queryset):
Collections Now Live in Prod:\n"""

message_middle = "\n\n".join(
[
f"- {collection.name} | {collection.server_url_prod}"
for collection in queryset.all()
]
[f"- {collection.name} | {collection.server_url_prod}" for collection in queryset.all()]
)

message_end = """
Expand All @@ -46,14 +43,10 @@ def download_candidate_urls_as_csv(modeladmin, request, queryset):
writer = csv.writer(response)

if len(queryset) > 1:
messages.add_message(
request, messages.ERROR, "You can only export one collection at a time."
)
messages.add_message(request, messages.ERROR, "You can only export one collection at a time.")
return

urls = CandidateURL.objects.filter(collection=queryset.first()).values_list(
"url", flat=True
)
urls = CandidateURL.objects.filter(collection=queryset.first()).values_list("url", flat=True)

# Write your headers here
writer.writerow(["candidate_url"])
Expand Down Expand Up @@ -137,9 +130,7 @@ def import_candidate_urls_secret_test(modeladmin, request, queryset):

@admin.action(description="Import candidate URLs from Secret Production")
def import_candidate_urls_secret_production(modeladmin, request, queryset):
import_candidate_urls_from_api_caller(
modeladmin, request, queryset, "secret_production"
)
import_candidate_urls_from_api_caller(modeladmin, request, queryset, "secret_production")


@admin.action(description="Import candidate URLs from Li's Server")
Expand All @@ -149,9 +140,7 @@ def import_candidate_urls_lis_server(modeladmin, request, queryset):

@admin.action(description="Import candidate URLs from LRM Dev Server")
def import_candidate_urls_lrm_dev_server(modeladmin, request, queryset):
import_candidate_urls_from_api_caller(
modeladmin, request, queryset, "lrm_dev_server"
)
import_candidate_urls_from_api_caller(modeladmin, request, queryset, "lrm_dev_server")


class ExportCsvMixin:
Expand Down Expand Up @@ -287,6 +276,13 @@ class TitlePatternAdmin(admin.ModelAdmin):
)


class WorkflowStatusHistoryAdmin(admin.ModelAdmin):
list_display = ("collection", "old_status", "new_status", "changed_at")
search_fields = ["collection__name"]
list_filter = ["new_status", "old_status"]


admin.site.register(WorkflowStatusHistory, WorkflowStatusHistoryAdmin)
admin.site.register(CandidateURL, CandidateURLAdmin)
admin.site.register(TitlePattern, TitlePatternAdmin)
admin.site.register(IncludePattern)
89 changes: 89 additions & 0 deletions sde_collections/migrations/0046_workflowstatushistory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Generated by Django 4.2.9 on 2024-05-14 20:00

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("sde_collections", "0045_alter_collection_workflow_status"),
]

operations = [
migrations.CreateModel(
name="WorkflowStatusHistory",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
(
"old_status",
models.IntegerField(
choices=[
(1, "Research in Progress"),
(2, "Ready for Engineering"),
(3, "Engineering in Progress"),
(4, "Ready for Curation"),
(5, "Curation in Progress"),
(6, "Curated"),
(7, "Quality Fixed"),
(8, "Secret Deployment Started"),
(9, "Secret Deployment Failed"),
(10, "Ready for LRM Quality Check"),
(11, "Ready for Quality Check"),
(12, "Quality Check Failed"),
(13, "Ready for Public Production"),
(14, "Perfect and on Production"),
(15, "Low Priority Problems on Production"),
(16, "High Priority Problems on Production, only for old sources"),
(17, "Code Merge Pending"),
]
),
),
(
"new_status",
models.IntegerField(
choices=[
(1, "Research in Progress"),
(2, "Ready for Engineering"),
(3, "Engineering in Progress"),
(4, "Ready for Curation"),
(5, "Curation in Progress"),
(6, "Curated"),
(7, "Quality Fixed"),
(8, "Secret Deployment Started"),
(9, "Secret Deployment Failed"),
(10, "Ready for LRM Quality Check"),
(11, "Ready for Quality Check"),
(12, "Quality Check Failed"),
(13, "Ready for Public Production"),
(14, "Perfect and on Production"),
(15, "Low Priority Problems on Production"),
(16, "High Priority Problems on Production, only for old sources"),
(17, "Code Merge Pending"),
]
),
),
("changed_at", models.DateTimeField(auto_now_add=True)),
(
"changed_by",
models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL
),
),
(
"collection",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="workflow_status_history",
to="sde_collections.collection",
),
),
],
options={
"verbose_name": "Workflow Status History",
"verbose_name_plural": "Workflow Status Histories",
},
),
]
23 changes: 22 additions & 1 deletion sde_collections/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,13 @@ def save(self, *args, **kwargs):
details = STATUS_CHANGE_NOTIFICATIONS[transition]
message = format_slack_message(self.name, details, self.id)
send_slack_message(message)

if "workflow_status" in self.tracker.changed():
WorkflowStatusHistory.objects.create(
collection=self,
old_status=self.tracker.previous("workflow_status"),
new_status=self.workflow_status,
changed_by=self.curated_by,
)
# Call the parent class's save method
super().save(*args, **kwargs)

Expand Down Expand Up @@ -511,3 +517,18 @@ def create_configs_on_status_change(sender, instance, created, **kwargs):
instance.create_indexer_config(overwrite=False)
elif instance.workflow_status == WorkflowStatusChoices.READY_FOR_PUBLIC_PROD:
instance.add_to_public_query()


class WorkflowStatusHistory(models.Model):
collection = models.ForeignKey("Collection", on_delete=models.CASCADE, related_name="workflow_status_history")
old_status = models.IntegerField(choices=WorkflowStatusChoices.choices)
new_status = models.IntegerField(choices=WorkflowStatusChoices.choices)
changed_by = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True, blank=True)
changed_at = models.DateTimeField(auto_now_add=True)

class Meta:
verbose_name = "Workflow Status History"
verbose_name_plural = "Workflow Status Histories"

def __str__(self):
return f"{self.collection.name} - {self.get_old_status_display()} to {self.get_new_status_display()}"

0 comments on commit cf3a8e5

Please sign in to comment.