Connect up post_save, post_delete signals for models.
768575
def _connect_signals():
    """"""
    for index in settings.get_index_names():
        for model in settings.get_index_models(index):
            _connect_model_signals(model)
399844
def on_post_save(sender, **kwargs):
    
    if not invalidate:
        return
    if kwargs.get("raw", False):
        return
    if sender is MigrationRecorder.Migration:
        return
    if issubclass(sender, Model):
        obj = kwargs["instance"]
        if isinstance(obj, Model):
            # get_for_model itself is cached
            try:
                ct = ContentType.objects.get_for_model(sender)
            except RuntimeError:
                # This happens when ultracache is being used by another product
                # during a test run.
                return

            if kwargs.get("created", False):
                # Expire cache keys that contain objects of this content type
                key = "ucache-ct-%s" % ct.id
                to_delete = cache.get(key, [])
                if to_delete:
                    try:
                        cache.delete_many(to_delete)
                    except NotImplementedError:
                        for k in to_delete:
                            cache.delete(k)
                cache.delete(key)

                # Purge paths in reverse caching proxy that contain objects of
                # this content type.
                key = "ucache-ct-pth-%s" % ct.id
                if purger is not None:
                    for li in cache.get(key, []):
                        purger(li[0], li[1])
                cache.delete(key)

            else:
                # Expire cache keys
                key = "ucache-%s-%s" % (ct.id, obj.pk)
                to_delete = cache.get(key, [])
                if to_delete:
                    try:
                        cache.delete_many(to_delete)
                    except NotImplementedError:
                        for k in to_delete:
                            cache.delete(k)
                cache.delete(key)

                # Purge paths in reverse caching proxy
                key = "ucache-pth-%s-%s" % (ct.id, obj.pk)
                if purger is not None:
                    for li in cache.get(key, []):
                        purger(li[0], li[1])
                cache.delete(key)
866905
def register_signals(self):
        """"""
        for index in self.indexes:
            if index.object_type:
                self._connect_signal(index)
1124610
def _flush_data(self):
        
        if self._data and self._data.modified:
            hookenv.relation_set(self.relation_id, dict(self.to_publish.data))
239232
def disconnect_entry_signals():
    
    post_save.disconnect(
        sender=Entry,
        dispatch_uid=ENTRY_PS_PING_DIRECTORIES)
    post_save.disconnect(
        sender=Entry,
        dispatch_uid=ENTRY_PS_PING_EXTERNAL_URLS)
    post_save.disconnect(
        sender=Entry,
        dispatch_uid=ENTRY_PS_FLUSH_SIMILAR_CACHE)
    post_delete.disconnect(
        sender=Entry,
        dispatch_uid=ENTRY_PD_FLUSH_SIMILAR_CACHE)
87619
def save():
    
    from .models import ModuleInfo

    logger = logging.getLogger(__name__)
    logger.info("Saving changes")

    # Save + restart
    for module in modules():
        if module.enabled:
            if module.changed:
                module.save()
                module.restart()
                module.commit()
            else:
                logger.debug('Not saving unchanged module: %s' %
                             module.verbose_name)
        else:
            logger.debug('Not saving disabled module: %s' %
                         module.verbose_name)

    # Commit
    ModuleInfo.commit()

    logger.info("Changes saved")
1228868
public function save()
    {
        foreach ($this->getChanged() as $relation) {
            $this->sync($relation, $this->values->get($relation), $this->delete);
        }
    }
1293135
def save_model(self, request, obj, form, change):
        """"""
        obj._history_user = request.user
        super(SimpleHistoryAdmin, self).save_model(request, obj, form, change)
42416
def update_post_relations(user, topic, deleting=False):
    
    if deleting:
        user.post_count = user.post_count - 1
    else:
        user.post_count += 1
    user.save(update_fields=['post_count'])

    topic.modified     = datetime.now()
    topic.modified_int = time.time()
    topic.save(update_fields=['modified', 'modified_int'])
1301277
public static function bootRevisionable()
    {
        static::updating(function ($model) {
            $model->preSave();
        });
        
        static::updated(function ($model) {
            $model->postSave();
        });
        
        static::created(function ($model) {
            $model->postCreate();
        });
        
        static::deleted(function ($model) {
            $model->preSave();
            $model->postDelete();
        });
    }
762434
def post_save(sender, instance, created, **kwargs):
    
    # Only create order model instances for
    # those modules specified in settings.
    model_label = '.'.join([sender._meta.app_label, sender._meta.object_name])
    labels = resolve_labels(model_label)

    order_field_names = is_orderable(model_label)
    if order_field_names:
        orderitem_set = getattr(
            instance,
            resolve_order_item_related_set_name(labels)
        )
        if not orderitem_set.all():
            fields = {}
            for order_field_name in order_field_names:
                fields[order_field_name] = 1
            orderitem_set.model.objects.create(item=instance, **fields)
            sanitize_order(orderitem_set.model)
1132212
def after_model_change(self, form, User, is_created):
        """"""
        if is_created and form.notification.data is True:
            send_reset_password_instructions(User)
1273442
public function postSave()
    {

        // check if the model already exists
        if ((!isset($this->revisionEnabled) || $this->revisionEnabled) && $this->updating) {
            // if it does, it means we're updating

            $changes_to_record = $this->changedRevisionableFields();

            $revisions = array();

            foreach ($changes_to_record as $key => $change) {
                $revisions[] = array(
                    'revisionable_type'     => $this->getMorphClass(),
                    'revisionable_id'       => $this->getKey(),
                    'key'                   => $key,
                    'old_value'             => array_get($this->originalData, $key),
                    'new_value'             => $this->updatedData[$key],
                    'user_id'               => $this->getSystemUserId(),
                    'created_at'            => new \DateTime(),
                    'updated_at'            => new \DateTime(),
                );
            }

            if (count($revisions) > 0) {
                $revision = static::newModel();
                \DB::table($revision->getTable())->insert($revisions);
            }
        }
    }
640451
def register_signals(self):
        """"""
        from .receivers import OAIServerUpdater
        # Register Record signals to update OAI informations
        self.update_function = OAIServerUpdater()
        records_signals.before_record_insert.connect(self.update_function,
                                                     weak=False)
        records_signals.before_record_update.connect(self.update_function,
                                                     weak=False)
        if self.app.config['OAISERVER_REGISTER_SET_SIGNALS']:
            self.register_signals_oaiset()
170201
def base_definition_post_delete(sender, instance, **kwargs):
    
    if hasattr(instance._state, '_deletion'):
        # Make sure to flatten abstract bases since Django
        # migrations can't deal with them.
        model = popattr(instance._state, '_deletion')
        for field in instance.base._meta.fields:
            perform_ddl('remove_field', model, field)
487883
public function addSaveHooks($post_id)
    {
        global $post;
        $class = get_called_class();
        $old_entry = new $class;
        $old_entry->load($post_id);

        // Make sure we have the right post type
        // Without this, you'll get weird cross-polination errors across post types
        if (!is_object($post) || $post->post_type !== $this->getPostType()) {
            return;
        }

        // Check autosave
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return $post_id;
        }
        
        // Check that a post_type is defined. It's not in the case of a delete.
        if (!array_key_exists('post_type', $_POST)) {
            return $post_id;
        }
        
        // Check perms
        $check = ($_POST['post_type'] === 'page') ? 'edit_page' : 'edit_post';
        if (!current_user_can($check, $post_id)) {
            return $post_id;
        }

        // Get fields to assign
        $updated_entry = new $class;
        $field_keys = array_merge(static::getCoreFieldKeys(), $this->getMetaFieldKeys());

        // Assign vars
        foreach ($_POST as $k => $v) {
            if (in_array($k, $field_keys)) {
                $updated_entry->set($k, $v);
            }
        }

        return $updated_entry->save(true);
    }
170408
def save_model(self, request, obj, form, change):
        
        super(DisplayableAdmin, self).save_model(request, obj, form, change)
        if settings.USE_MODELTRANSLATION:
            lang = get_language()
            for code in OrderedDict(settings.LANGUAGES):
                if code != lang:  # Already done
                    try:
                        activate(code)
                    except:
                        pass
                    else:
                        obj.save()
            activate(lang)