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

Fix Flow Export #360

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions engage/orgs/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def ready(self):

from .views.manage_accounts import OrgManageAccountsOverrides
OrgManageAccountsOverrides.applyPatches()

from .views.export import ExportOverrides
ExportOverrides.applyPatches()
#enddef ready

#endclass AppConfig
43 changes: 43 additions & 0 deletions engage/orgs/views/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import itertools

from django.http import JsonResponse
from django.utils.text import slugify

from temba.campaigns.models import Campaign
from temba.flows.models import Flow
from temba.orgs.views import OrgCRUDL

from engage.utils.class_overrides import MonkeyPatcher


class ExportOverrides(MonkeyPatcher):
patch_class = OrgCRUDL.Export

def post(self: type(OrgCRUDL.Export), request, *args, **kwargs):
org = self.get_object()

flow_ids = [elt for elt in self.request.POST.getlist("flows") if elt]
campaign_ids = [elt for elt in self.request.POST.getlist("campaigns") if elt]

# fetch the selected flows and campaigns
flows = Flow.objects.filter(id__in=flow_ids, org=org, is_active=True)
campaigns = Campaign.objects.filter(id__in=campaign_ids, org=org, is_active=True)

components = set(itertools.chain(flows, campaigns))

# add triggers for the selected flows
for flow in flows:
components.update(flow.triggers.filter(is_active=True, is_archived=False))

export = org.export_definitions(request.branding["link"], components)

for f in export.get('flows', []):
f.pop('channels', None)
#endfor

response = JsonResponse(export, json_dumps_params=dict(indent=2))
response["Content-Disposition"] = "attachment; filename=%s.json" % slugify(org.name)
return response
#enddef post

#endclass ExportOverrides
Loading