def migrate_campaigns_to_production(all_notifications): for n in all_notifications: campaign = json.loads(n.history) definition = BASE_IMPORT.copy() definition["campaign"] = [campaign] n.org_dest.import_app(definition, n.created_by) n.mark_migrated() c = Campaign.objects.filter(name = n.item_name, org = n.org_dest, group__name =campaign["group"]["name"]).last() Campaign.restore_flows(c) EventFire.update_campaign_events(c)
def migrate_events_to_production(all_notifications): for n in all_notifications: #Check if campaign exist item = json.loads(n.history) c = Campaign.objects.filter(org = n.org_dest, name = item["name"], group__name = item["group"]["name"] ).last() if c : c.is_archived=False c.modified_by=n.created_by c.modified_on=timezone.now() c.save() for event_spec in item["events"]: #check if our event is in campaign e = c.events.filter(offset = event_spec ["offset"], unit = event_spec["unit"], relative_to__key =event_spec["relative_to"]["key"], flow__name = event_spec["flow"]["name"], event_type =event_spec["event_type"]) if not e: create_event(event_spec, n, c) print("Se creo el evento") else: print ("Evento ya existente") else: definition = BASE_IMPORT.copy() definition["campaign"] = item definition["flows"] =json.dumps(FlowRevision.objects.filter(flow__name=item.item_name).last().definition) n.org_dest.import_app(definition, n.created_by) c = Campaign.objects.filter(name = item["name"], org = n.org_dest, group__name =item["group"]["name"]).last() print(c) print (item) print (n.org_dest) Campaign.restore_flows(c) print("Se creo toda la campania") EventFire.update_campaign_events(c) n.mark_migrated()