Exemple #1
0
 def update(self, cohort: Cohort, validated_data: Dict, *args: Any,
            **kwargs: Any) -> Cohort:  # type: ignore
     cohort.name = validated_data.get("name", cohort.name)
     cohort.groups = validated_data.get("groups", cohort.groups)
     cohort.deleted = validated_data.get("deleted", cohort.deleted)
     cohort.is_calculating = True
     cohort.save()
     calculate_cohort.delay(cohort_id=cohort.pk)
     return cohort
Exemple #2
0
    def update(self, cohort: Cohort, validated_data: Dict, *args: Any,
               **kwargs: Any) -> Cohort:  # type: ignore
        request = self.context["request"]
        cohort.name = validated_data.get("name", cohort.name)
        cohort.description = validated_data.get("description",
                                                cohort.description)
        cohort.groups = validated_data.get("groups", cohort.groups)
        cohort.is_static = validated_data.get("is_static", cohort.is_static)
        deleted_state = validated_data.get("deleted", None)

        is_deletion_change = deleted_state is not None and cohort.deleted != deleted_state
        if is_deletion_change:
            cohort.deleted = deleted_state

        if not cohort.is_static and not is_deletion_change:
            cohort.is_calculating = True
        cohort.save()

        if not deleted_state:
            if cohort.is_static:
                # You can't update a static cohort using the trend/stickiness thing
                if request.FILES.get("csv"):
                    self._calculate_static_by_csv(request.FILES["csv"], cohort)
            else:
                # Increment based on pending versions
                pending_version = get_and_update_pending_version(cohort)

                calculate_cohort_ch.delay(cohort.id, pending_version)

        report_user_action(
            request.user,
            "cohort updated",
            {
                **cohort.get_analytics_metadata(), "updated_by_creator":
                request.user == cohort.created_by
            },
        )

        return cohort
Exemple #3
0
    def update(self, cohort: Cohort, validated_data: Dict, *args: Any,
               **kwargs: Any) -> Cohort:  # type: ignore
        request = self.context["request"]
        cohort.name = validated_data.get("name", cohort.name)
        cohort.description = validated_data.get("description",
                                                cohort.description)
        cohort.groups = validated_data.get("groups", cohort.groups)
        cohort.is_static = validated_data.get("is_static", cohort.is_static)
        deleted_state = validated_data.get("deleted", None)

        is_deletion_change = deleted_state is not None and cohort.deleted != deleted_state
        if is_deletion_change:
            cohort.deleted = deleted_state

        if not cohort.is_static and not is_deletion_change:
            cohort.is_calculating = True
        cohort.save()

        if not deleted_state:
            if cohort.is_static:
                # You can't update a static cohort using the trend/stickiness thing
                if request.FILES.get("csv"):
                    self._calculate_static_by_csv(request.FILES["csv"], cohort)
            else:
                if is_clickhouse_enabled():
                    calculate_cohort_ch.delay(cohort.id)
                else:
                    calculate_cohort.delay(cohort.id)

        posthoganalytics.capture(
            request.user.distinct_id,
            "cohort updated",
            {
                **cohort.get_analytics_metadata(), "updated_by_creator":
                request.user == cohort.created_by
            },
        )

        return cohort
Exemple #4
0
 def update(self, cohort: Cohort, validated_data: Dict, *args: Any,
            **kwargs: Any) -> Cohort:  # type: ignore
     request = self.context["request"]
     cohort.name = validated_data.get("name", cohort.name)
     cohort.groups = validated_data.get("groups", cohort.groups)
     cohort.deleted = validated_data.get("deleted", cohort.deleted)
     cohort.is_calculating = True
     cohort.save()
     posthoganalytics.capture(
         request.user.distinct_id,
         "cohort updated",
         {
             **cohort.get_analytics_metadata(), "updated_by_creator":
             request.user == cohort.created_by
         },
     )
     calculate_cohort.delay(cohort_id=cohort.pk)
     return cohort