Exemple #1
0
        def form_valid(self, form):
            analytics.track(self.request.user.username, "temba.trigger_created", dict(type="schedule"))
            org = self.request.user.get_org()
            start_time = form.get_start_time(org.timezone)

            schedule = Schedule.create_schedule(
                org,
                self.request.user,
                start_time,
                form.cleaned_data.get("repeat_period"),
                repeat_days_of_week=form.cleaned_data.get("repeat_days_of_week"),
            )

            recipients = self.form.cleaned_data["omnibox"]

            trigger = Trigger.objects.create(
                flow=self.form.cleaned_data["flow"],
                org=self.request.user.get_org(),
                schedule=schedule,
                trigger_type=Trigger.TYPE_SCHEDULE,
                created_by=self.request.user,
                modified_by=self.request.user,
            )

            for group in recipients["groups"]:
                trigger.groups.add(group)

            for contact in recipients["contacts"]:
                trigger.contacts.add(contact)

            self.post_save(trigger)

            response = self.render_to_response(self.get_context_data(form=form))
            response["REDIRECT"] = self.get_success_url()
            return response
Exemple #2
0
        def get_create_kwargs(self, user, cleaned_data):
            start_time = cleaned_data["start_datetime"]
            repeat_period = cleaned_data["repeat_period"]
            repeat_days_of_week = cleaned_data["repeat_days_of_week"]

            schedule = Schedule.create_schedule(
                user.get_org(), user, start_time, repeat_period, repeat_days_of_week=repeat_days_of_week
            )

            return {"schedule": schedule, "contacts": cleaned_data["contacts"]}
Exemple #3
0
    def test_release(self):
        flow = self.create_flow()
        group = self.create_group("Trigger Group", [])

        trigger = Trigger.objects.create(
            org=self.org,
            flow=flow,
            trigger_type=Trigger.TYPE_SCHEDULE,
            created_by=self.admin,
            modified_by=self.admin,
            schedule=Schedule.create_schedule(self.org, self.admin, timezone.now(), Schedule.REPEAT_MONTHLY),
        )
        trigger.groups.add(group)

        trigger.release()

        # schedule should also have been deleted but obviously not group or flow
        self.assertEqual(Trigger.objects.count(), 0)
        self.assertEqual(Schedule.objects.count(), 0)
        self.assertEqual(ContactGroup.user_groups.count(), 1)
        self.assertEqual(Flow.objects.count(), 1)