Skip to content

Commit

Permalink
Merge pull request #648 from NASA-IMPACT/647-generate-deployment-noti…
Browse files Browse the repository at this point in the history
…fier-message-for-slack

Generate deployment notifier message for slack
  • Loading branch information
code-geek authored Mar 7, 2024
2 parents b2a6911 + 812fa56 commit 4029520
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions sde_collections/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@
from .tasks import import_candidate_urls_from_api


@admin.action(description="Generate deployment message")
def generate_deployment_message(modeladmin, request, queryset):
# generate deployment message
response = HttpResponse(content_type="text/txt")

message_start = """:rocket: Production Deployment Update :rocket:
Hello Team,
I'm pleased to announce that we have successfully moved several key collections
to our production environment as part of our latest deployment! :tada:\n
Collections Now Live in Prod:\n"""

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

message_end = """
If you find something needs changing, please let us know.
Dev Team"""

response.content = f"{message_start}\n{message_middle}\n{message_end}"

return response


@admin.action(description="Download candidate URLs as csv")
def download_candidate_urls_as_csv(modeladmin, request, queryset):
response = HttpResponse(content_type="text/csv")
Expand All @@ -17,10 +46,14 @@ 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 @@ -104,7 +137,9 @@ 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 @@ -114,7 +149,9 @@ 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 @@ -195,6 +232,7 @@ class CollectionAdmin(admin.ModelAdmin, ExportCsvMixin, UpdateConfigMixin):
list_filter = ("division", "curation_status", "workflow_status", "turned_on")
search_fields = ("name", "url", "config_folder")
actions = [
generate_deployment_message,
"export_as_csv",
"update_config",
download_candidate_urls_as_csv,
Expand Down

0 comments on commit 4029520

Please sign in to comment.