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

Generate deployment notifier message for slack #648

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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