Python reversion.models.Version() Examples

The following are 30 code examples of reversion.models.Version(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module reversion.models , or try the search function .
Example #1
Source File: xversion.py    From ImitationTmall_Django with GNU General Public License v3.0 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and unicode(related_version.field_dict[fk_name]) == unicode(object_id)])
        return related_versions 
Example #2
Source File: xversion.py    From CTF_AWD_Platform with MIT License 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions 
Example #3
Source File: xversion.py    From devops with MIT License 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and unicode(related_version.field_dict[fk_name]) == unicode(object_id)])
        return related_versions 
Example #4
Source File: xversion.py    From imoocc with GNU General Public License v2.0 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions 
Example #5
Source File: xversion.py    From myblog with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions 
Example #6
Source File: xversion.py    From online with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions 
Example #7
Source File: xversion.py    From django_OA with GNU General Public License v3.0 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions 
Example #8
Source File: xversion.py    From weibo-analysis-system with MIT License 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions 
Example #9
Source File: model_anonymizers.py    From django-GDPR with MIT License 6 votes vote down vote up
def update_obj(self, obj: Model, legal_reason: Optional[LegalReason] = None,
                   purpose: Optional["AbstractPurpose"] = None,
                   fields: Union[Fields, FieldMatrix] = '__ALL__',
                   base_encryption_key: Optional[str] = None,
                   anonymization: bool = True):
        parsed_fields: Fields = Fields(fields, obj.__class__) if not isinstance(fields, Fields) else fields

        if self.DELETE_FIELD_NAME in parsed_fields.local_fields and anonymization is True:
            self.update_related_fields(parsed_fields, obj, legal_reason, purpose, anonymization)

            obj.__class__.objects.filter(pk=obj.pk).delete()

            if self.anonymize_reversion(obj):
                from reversion.models import Version
                from gdpr.utils import get_reversion_versions
                get_reversion_versions(obj).delete()

        elif self.DELETE_FIELD_NAME in parsed_fields.local_fields:
            parsed_fields.local_fields = [i for i in parsed_fields.local_fields if i != self.DELETE_FIELD_NAME]
            super().update_obj(obj, legal_reason, purpose, parsed_fields, base_encryption_key, anonymization)
        else:
            super().update_obj(obj, legal_reason, purpose, parsed_fields, base_encryption_key, anonymization) 
Example #10
Source File: xversion.py    From Dailyfresh-B2C with Apache License 2.0 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions 
Example #11
Source File: xversion.py    From StormOnline with Apache License 2.0 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions 
Example #12
Source File: xversion.py    From Mxonline3 with Apache License 2.0 6 votes vote down vote up
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions 
Example #13
Source File: xversion.py    From imoocc with GNU General Public License v2.0 5 votes vote down vote up
def get_context(self):
        context = super(RecoverListView, self).get_context()
        opts = self.opts
        deleted = self._order_version_queryset(Version.objects.get_deleted(self.model))
        context.update({
            "opts": opts,
            "app_label": opts.app_label,
            "model_name": capfirst(opts.verbose_name),
            "title": _("Recover deleted %(name)s") % {"name": force_text(opts.verbose_name_plural)},
            "deleted": deleted,
            "changelist_url": self.model_admin_url("changelist"),
        })
        return context 
Example #14
Source File: xversion.py    From imoocc with GNU General Public License v2.0 5 votes vote down vote up
def get_context(self):
        context = super(RevisionListView, self).get_context()

        opts = self.opts
        action_list = [
            {
                "revision": version.revision,
                "url": self.model_admin_url('revision', quote(version.object_id), version.id),
                "version": version
            }
            for version
            in self._reversion_order_version_queryset(Version.objects.get_for_object_reference(
                self.model,
                self.obj.pk,
            ).select_related("revision__user"))
        ]
        context.update({
            'title': _('Change history: %s') % force_text(self.obj),
            'action_list': action_list,
            'model_name': capfirst(force_text(opts.verbose_name_plural)),
            'object': self.obj,
            'app_label': opts.app_label,
            "changelist_url": self.model_admin_url("changelist"),
            "update_url": self.model_admin_url("change", self.obj.pk),
            'opts': opts,
        })
        return context 
Example #15
Source File: populate_assetversions.py    From kpi with GNU Affero General Public License v3.0 5 votes vote down vote up
def _replace_deployment_ids(_AssetVersion, _Asset):
    # this needs to be run in a migration after all of the AssetVersions have been created
    # from the reversion.models.Version instances
    a_ids = set(_AssetVersion.objects.filter(deployed=True
                                             ).values_list('asset_id', flat=True
                                                           ))
    ids_not_counted = []
    a_ids_len = len(a_ids)
    a_ids_done = 0
    with disable_auto_field_update(_Asset, 'date_modified'):
        start_time = time.time()
        for a_id in a_ids:
            # `only()` saves about 8/1000s per iteration
            asset = _Asset.objects.only('_deployment_data').get(id=a_id)
            version_id = asset._deployment_data['version']
            if isinstance(version_id, int):
                try:
                    # `only()` saves about 5/1000s per iteration
                    uid = asset.asset_versions.only('uid').get(
                        _reversion_version_id=version_id).uid
                    if 'version_uid' not in asset._deployment_data or \
                            asset._deployment_data['version_uid'] != uid:
                        asset._deployment_data['version_uid'] = uid
                        # `update()` saves about 7/1000s per iteration
                        _Asset.objects.filter(id=asset.id).update(
                            _deployment_data=asset._deployment_data)
                except ObjectDoesNotExist as e:
                    ids_not_counted.append(version_id)
            a_ids_done += 1
            if a_ids_done % 100 == 0:
                elapsed = time.time() - start_time
                print('Completed {}/{} ({}%); est\'d time left: {}s'.format(
                    a_ids_done,
                    a_ids_len,
                    a_ids_done * float(100) / a_ids_len,
                    elapsed / a_ids_done * (a_ids_len - a_ids_done)
                ))

    if len(ids_not_counted) > 0:
        print('DeploymentIDs not found: '
              '{}'.format(json.dumps(ids_not_counted))) 
Example #16
Source File: populate_assetversions.py    From kpi with GNU Affero General Public License v3.0 5 votes vote down vote up
def handle(self, *args, **options):
        kw = {}
        if options['filter_users_str']:
            kw['filter_usernames'] = options['filter_users_str'].split(',')
        populate_assetversions(Asset, AssetVersion, Version, **kw) 
Example #17
Source File: xversion.py    From imoocc with GNU General Public License v2.0 5 votes vote down vote up
def init_request(self, object_id, version_id):
        self.detail = self.get_model_view(
            DetailAdminView, self.model, object_id)
        self.org_obj = self.detail.obj
        self.version = get_object_or_404(
            Version, pk=version_id, object_id=smart_text(self.org_obj.pk))

        self.prepare_form() 
Example #18
Source File: xversion.py    From imoocc with GNU General Public License v2.0 5 votes vote down vote up
def init_request(self, version_id):
        if not self.has_change_permission() and not self.has_add_permission():
            raise PermissionDenied

        self.version = get_object_or_404(Version, pk=version_id)
        self.org_obj = self.version._object_version.object

        self.prepare_form() 
Example #19
Source File: xversion.py    From devops with MIT License 5 votes vote down vote up
def init_request(self, object_id, version_id):
        self.detail = self.get_model_view(
            DetailAdminView, self.model, object_id)
        self.org_obj = self.detail.obj
        self.version = get_object_or_404(
            Version, pk=version_id, object_id=unicode(self.org_obj.pk))

        self.prepare_form() 
Example #20
Source File: xversion.py    From StormOnline with Apache License 2.0 5 votes vote down vote up
def get_context(self):
        context = super(RevisionListView, self).get_context()

        opts = self.opts
        action_list = [
            {
                "revision": version.revision,
                "url": self.model_admin_url('revision', quote(version.object_id), version.id),
                "version": version
            }
            for version
            in self._reversion_order_version_queryset(Version.objects.get_for_object_reference(
                self.model,
                self.obj.pk,
            ).select_related("revision__user"))
        ]
        context.update({
            'title': _('Change history: %s') % force_text(self.obj),
            'action_list': action_list,
            'model_name': capfirst(force_text(opts.verbose_name_plural)),
            'object': self.obj,
            'app_label': opts.app_label,
            "changelist_url": self.model_admin_url("changelist"),
            "update_url": self.model_admin_url("change", self.obj.pk),
            'opts': opts,
        })
        return context 
Example #21
Source File: xversion.py    From Mxonline3 with Apache License 2.0 5 votes vote down vote up
def init_request(self, version_id):
        if not self.has_change_permission() and not self.has_add_permission():
            raise PermissionDenied

        self.version = get_object_or_404(Version, pk=version_id)
        self.org_obj = self.version._object_version.object

        self.prepare_form() 
Example #22
Source File: xversion.py    From devops with MIT License 5 votes vote down vote up
def init_request(self, version_id):
        if not self.has_change_permission() and not self.has_add_permission():
            raise PermissionDenied

        self.version = get_object_or_404(Version, pk=version_id)
        self.org_obj = self.version.object_version.object

        self.prepare_form() 
Example #23
Source File: xversion.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_context(self):
        context = super(RecoverListView, self).get_context()
        opts = self.opts
        deleted = self._order_version_queryset(Version.objects.get_deleted(self.model))
        context.update({
            "opts": opts,
            "app_label": opts.app_label,
            "model_name": capfirst(opts.verbose_name),
            "title": _("Recover deleted %(name)s") % {"name": force_text(opts.verbose_name_plural)},
            "deleted": deleted,
            "changelist_url": self.model_admin_url("changelist"),
        })
        return context 
Example #24
Source File: xversion.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_context(self):
        context = super(RevisionListView, self).get_context()

        opts = self.opts
        action_list = [
            {
                "revision": version.revision,
                "url": self.model_admin_url('revision', quote(version.object_id), version.id),
                "version": version
            }
            for version
            in self._reversion_order_version_queryset(Version.objects.get_for_object_reference(
                self.model,
                self.obj.pk,
            ).select_related("revision__user"))
        ]
        context.update({
            'title': _('Change history: %s') % force_text(self.obj),
            'action_list': action_list,
            'model_name': capfirst(force_text(opts.verbose_name_plural)),
            'object': self.obj,
            'app_label': opts.app_label,
            "changelist_url": self.model_admin_url("changelist"),
            "update_url": self.model_admin_url("change", self.obj.pk),
            'opts': opts,
        })
        return context 
Example #25
Source File: xversion.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def init_request(self, object_id, version_id):
        self.detail = self.get_model_view(
            DetailAdminView, self.model, object_id)
        self.org_obj = self.detail.obj
        self.version = get_object_or_404(
            Version, pk=version_id, object_id=smart_text(self.org_obj.pk))

        self.prepare_form() 
Example #26
Source File: xversion.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def init_request(self, version_id):
        if not self.has_change_permission() and not self.has_add_permission():
            raise PermissionDenied

        self.version = get_object_or_404(Version, pk=version_id)
        self.org_obj = self.version._object_version.object

        self.prepare_form() 
Example #27
Source File: xversion.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def get_context(self):
        context = super(RecoverListView, self).get_context()
        opts = self.opts
        deleted = self._order_version_queryset(Version.objects.get_deleted(self.model))
        context.update({
            "opts": opts,
            "app_label": opts.app_label,
            "model_name": capfirst(opts.verbose_name),
            "title": _("Recover deleted %(name)s") % {"name": force_text(opts.verbose_name_plural)},
            "deleted": deleted,
            "changelist_url": self.model_admin_url("changelist"),
        })
        return context 
Example #28
Source File: xversion.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def get_context(self):
        context = super(RevisionListView, self).get_context()

        opts = self.opts
        action_list = [
            {
                "revision": version.revision,
                "url": self.model_admin_url('revision', quote(version.object_id), version.id),
                "version": version
            }
            for version
            in self._reversion_order_version_queryset(Version.objects.get_for_object_reference(
                self.model,
                self.obj.pk,
            ).select_related("revision__user"))
        ]
        context.update({
            'title': _('Change history: %s') % force_text(self.obj),
            'action_list': action_list,
            'model_name': capfirst(force_text(opts.verbose_name_plural)),
            'object': self.obj,
            'app_label': opts.app_label,
            "changelist_url": self.model_admin_url("changelist"),
            "update_url": self.model_admin_url("change", self.obj.pk),
            'opts': opts,
        })
        return context 
Example #29
Source File: xversion.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def init_request(self, object_id, version_id):
        self.detail = self.get_model_view(
            DetailAdminView, self.model, object_id)
        self.org_obj = self.detail.obj
        self.version = get_object_or_404(
            Version, pk=version_id, object_id=smart_text(self.org_obj.pk))

        self.prepare_form() 
Example #30
Source File: xversion.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def init_request(self, version_id):
        if not self.has_change_permission() and not self.has_add_permission():
            raise PermissionDenied

        self.version = get_object_or_404(Version, pk=version_id)
        self.org_obj = self.version._object_version.object

        self.prepare_form()