コード例 #1
0
    def update(self, *args, **kwargs):
        if self.model.ACTIVATABLE_FIELD_NAME in kwargs:
            # Fetch the instances that are about to be updated if they have an activatable flag. This
            # is because their activatable flag may be changed in the subsequent update, causing us
            # to potentially lose what this original query referenced
            new_active_state_kwargs = {
                self.model.ACTIVATABLE_FIELD_NAME:
                kwargs.get(self.model.ACTIVATABLE_FIELD_NAME)
            }
            changed_instance_ids = list(
                self.exclude(**new_active_state_kwargs).values_list('id',
                                                                    flat=True))
            updated_instance_ids = list(self.values_list('id', flat=True))

        ret_val = super(ActivatableQuerySet, self).update(*args, **kwargs)

        if self.model.ACTIVATABLE_FIELD_NAME in kwargs and updated_instance_ids:
            # send the instances that were updated to the activation signals
            model_activations_changed.send(
                self.model,
                instance_ids=changed_instance_ids,
                is_active=kwargs[self.model.ACTIVATABLE_FIELD_NAME])
            model_activations_updated.send(
                self.model,
                instance_ids=updated_instance_ids,
                is_active=kwargs[self.model.ACTIVATABLE_FIELD_NAME])
        return ret_val
コード例 #2
0
    def save(self, *args, **kwargs):
        """
        A custom save method that handles figuring out when something is activated or deactivated.
        """
        is_active_changed = (
            self.id is None or self.__class__.objects.filter(id=self.id).exclude(is_active=self.is_active).exists())

        ret_val = super(BaseActivatableModel, self).save(*args, **kwargs)

        # Emit the signal for when the is_active flag is changed
        if is_active_changed:
            model_activations_changed.send(self.__class__, instances=[self], is_active=self.is_active)

        return ret_val
コード例 #3
0
    def save(self, *args, **kwargs):
        """
        A custom save method that handles figuring out when something is activated or deactivated.
        """
        current_activable_value = getattr(self, self.ACTIVATABLE_FIELD_NAME)
        is_active_changed = self.id is None or self.__original_activatable_value != current_activable_value
        self.__original_activatable_value = current_activable_value

        ret_val = super(BaseActivatableModel, self).save(*args, **kwargs)

        # Emit the signal for when the is_active flag is changed
        if is_active_changed:
            model_activations_changed.send(self.__class__, instance_ids=[self.id], is_active=current_activable_value)

        return ret_val
コード例 #4
0
    def update(self, *args, **kwargs):
        if self.model.ACTIVATABLE_FIELD_NAME in kwargs:
            # Fetch the instances that are about to be updated if they have an activatable flag. This
            # is because their activatable flag may be changed in the subsequent update, causing us
            # to potentially lose what this original query referenced
            updated_instance_ids = list(self.values_list('id', flat=True))

        ret_val = super(ActivatableQuerySet, self).update(*args, **kwargs)

        if self.model.ACTIVATABLE_FIELD_NAME in kwargs and updated_instance_ids:
            # Refetch the instances that were updated and send them to the activation signal
            model_activations_changed.send(
                self.model, instance_ids=updated_instance_ids,
                is_active=kwargs[self.model.ACTIVATABLE_FIELD_NAME])
        return ret_val
コード例 #5
0
    def save(self, *args, **kwargs):
        """
        A custom save method that handles figuring out when something is activated or deactivated.
        """
        current_activable_value = getattr(self, self.ACTIVATABLE_FIELD_NAME)
        is_active_changed = self.id is None or self.__original_activatable_value != current_activable_value
        self.__original_activatable_value = current_activable_value

        ret_val = super(BaseActivatableModel, self).save(*args, **kwargs)

        # Emit the signals for when the is_active flag is changed
        if is_active_changed:
            model_activations_changed.send(self.__class__, instance_ids=[self.id], is_active=current_activable_value)
        if self.activatable_field_updated:
            model_activations_updated.send(self.__class__, instance_ids=[self.id], is_active=current_activable_value)

        return ret_val
コード例 #6
0
 def update(self, *args, **kwargs):
     ret_val = super(ActivatableQuerySet, self).update(*args, **kwargs)
     if 'is_active' in kwargs:
         model_activations_changed.send(self.model, instances=list(self), is_active=kwargs['is_active'])
     return ret_val