Esempio n. 1
0
    def handle_noargs(self, **options):
        from django.db.models.loading import get_models

        models = get_models(include_deferred=True)
        for model in models:
            if issubclass(model, VersionsModel):
                instance_count = model.objects.count()
                model_name = '%s.%s' % (model._meta.app_label, model._meta.module_name)
                print 'Creating baseline revisions for %s `%s` objects.' % (
                    instance_count,
                    model_name,
                    )

                for instance in model.objects.iterator():
                    with revision:
                        revision.message = 'Baseline creation of model data for `%s` objects.' % model_name
                        revision.stage(instance)
Esempio n. 2
0
    def commit(self):
        if self._versions_status == VERSIONS_STATUS_STAGED_DELETE:
            self._versions_status = VERSIONS_STATUS_DELETED
        elif self._versions_status == VERSIONS_STATUS_STAGED_EDITS:
            self._versions_status = VERSIONS_STATUS_PUBLISHED

        # We don't want to call our main save method, because we want to delay
        # staging the state of this model until we set the state of all unpublihsed manytomany edits.
        self._save_base()

        if self._versions_revision is None:
            data = revision.data(self)
        else:
            data = revision.version(self, rev=self._versions_revision)

        for name, ids in data['related'].items():
            try:
                field = self._meta.get_field_by_name(name)[0]
            except:
                pass
            else:
                if isinstance(field, related.ManyToManyField):
                    related_manager = getattr(self, name)
                    if issubclass(related_manager.model, VersionsModel):
                        existing_ids = set(
                            list(
                                related_manager.get_query_set(
                                    bypass=True,
                                    bypass_filter=True).values_list(
                                        'pk', flat=True)))
                    else:
                        existing_ids = set(
                            list(related_manager.values_list('pk', flat=True)))

                    if self in revision._state.pending_related_updates and name in revision._state.pending_related_updates[
                            self]:
                        updated_ids = revision._state.pending_related_updates[
                            self][name]
                    else:
                        updated_ids = ids

                    if existing_ids.symmetric_difference(updated_ids):
                        setattr(self, name, updated_ids)

        revision.stage(self)
Esempio n. 3
0
    def handle_noargs(self, **options):
        from django.db.models.loading import get_models

        models = get_models(include_deferred=True)
        for model in models:
            if issubclass(model, VersionsModel):
                instance_count = model.objects.count()
                model_name = '%s.%s' % (model._meta.app_label,
                                        model._meta.module_name)
                print 'Creating baseline revisions for %s `%s` objects.' % (
                    instance_count,
                    model_name,
                )

                for instance in model.objects.iterator():
                    with revision:
                        revision.message = 'Baseline creation of model data for `%s` objects.' % model_name
                        revision.stage(instance)
Esempio n. 4
0
    def commit(self):
        if self._versions_status == VERSIONS_STATUS_STAGED_DELETE:
            self._versions_status = VERSIONS_STATUS_DELETED
        elif self._versions_status == VERSIONS_STATUS_STAGED_EDITS:
            self._versions_status = VERSIONS_STATUS_PUBLISHED

        # We don't want to call our main save method, because we want to delay
        # staging the state of this model until we set the state of all unpublihsed manytomany edits.
        self._save_base()

        if self._versions_revision is None:
            data = revision.data(self)
        else:
            data = revision.version(self, rev=self._versions_revision)

        for name, ids in data['related'].items():
            try:
                field = self._meta.get_field_by_name(name)[0]
            except:
                pass
            else:
                if isinstance(field, related.ManyToManyField):
                    related_manager = getattr(self, name)
                    if issubclass(related_manager.model, VersionsModel):
                        existing_ids = set(list(related_manager.get_query_set(bypass=True, bypass_filter=True).values_list('pk', flat=True)))
                    else:
                        existing_ids = set(list(related_manager.values_list('pk', flat=True)))

                    if self in revision._state.pending_related_updates and name in revision._state.pending_related_updates[self]:
                        updated_ids = revision._state.pending_related_updates[self][name]
                    else:
                        updated_ids = ids

                    if existing_ids.symmetric_difference(updated_ids):
                        setattr(self, name, updated_ids)

        revision.stage(self)
Esempio n. 5
0
 def save(self, *args, **kwargs):
     if (self._should_create_placeholder() or self._versions_status in (VERSIONS_STATUS_PUBLISHED, VERSIONS_STATUS_DELETED)):
         self._save_base(*args, **kwargs)
     revision.stage(self)
Esempio n. 6
0
 def save(self, *args, **kwargs):
     if (self._should_create_placeholder() or self._versions_status
             in (VERSIONS_STATUS_PUBLISHED, VERSIONS_STATUS_DELETED)):
         self._save_base(*args, **kwargs)
     revision.stage(self)
Esempio n. 7
0
 def save(self, *args, **kwargs):
     if (self._get_pk_val() is None or self._versions_status in (VERSIONS_STATUS_PUBLISHED, VERSIONS_STATUS_DELETED)):
         self._save_base(*args, **kwargs)
     revision.stage(self)