Example #1
0
def get_lock_for_content(content):
    """Check if a lock exists, if so return it
    """
    try:
        versionables.for_content(content)
    except KeyError:
        return None
    try:
        version = Version.objects.select_related('versionlock').get_for_content(content)
        return version.versionlock
    except ObjectDoesNotExist:
        return None
Example #2
0
 def setUp(self):
     versionable = versionables.for_content(PageContent)
     self.version_admin = VersionAdmin(
         versionable.version_model_proxy, admin.AdminSite()
     )
     self.mock_request = MockRequest()
     self.mock_request.user = self.user
     super().setUp()
Example #3
0
def get_versionable_for_content(content):
    try:
        from djangocms_versioning import versionables
    except ImportError:
        return
    try:
        return versionables.for_content(content)
    except KeyError:
        return
def proxy_model(obj, content_model):
    """
    Get the proxy model from a

    :param obj: A registered versionable object
    :param content_model: A registered content model
    """
    versionable = versionables.for_content(content_model)
    obj_ = deepcopy(obj)
    obj_.__class__ = versionable.version_model_proxy
    return obj_
def get_versionable_for_content(content):
    """Returns a VersionableItem for a given content object (or content model).

    Returns None if given object is not versioned, or versioning is not installed.
    """
    try:
        from djangocms_versioning import versionables
    except ImportError:
        return
    try:
        return versionables.for_content(content)
    except KeyError:
        pass
Example #6
0
    def inner(self, request):
        urls = ("cms_pagecontent_get_tree",)
        queryset = func(self, request)
        if request.resolver_match.url_name in urls:
            versionable = versionables.for_content(queryset.model)

            # TODO: Improve the grouping filters to use anything defined in the
            #       apps versioning config extra_grouping_fields
            grouping_filters = {}
            if 'language' in versionable.extra_grouping_fields:
                grouping_filters['language'] = get_language_from_request(request)

            return queryset.filter(pk__in=versionable.distinct_groupers(**grouping_filters))
        return queryset
Example #7
0
def emit_content_change(obj, sender=None, created=False):
    """
    Sends a content object state change signal if obj class is registered by
    internalsearch.
    Helper function to be used in apps that integrates with internalsearch.
    """
    try:
        get_internalsearch_model_config(obj.__class__)
    except (IndexError, LookupError):
        # Internal search is not install or model is not registered with internal search
        return

    if created:
        try:
            # if versioning installed mark other versions in group as not the latest version
            versioning_extension = apps.get_app_config(
                "djangocms_versioning").cms_extension
            from djangocms_versioning import versionables
        except (ImportError, LookupError):
            versioning_extension = None

        if versioning_extension and versioning_extension.is_content_model_versioned(
                obj.__class__):
            versionable = versionables.for_content(obj)
            content_objects = versionable.for_content_grouping_values(obj)
            for content_obj in content_objects:
                if content_obj.pk != obj.pk:
                    content_object_state_change.send(
                        sender=sender or obj.__class__,
                        content_object=content_obj,
                        created=False,
                    )

    content_object_state_change.send(sender=sender or obj.__class__,
                                     content_object=obj,
                                     created=True)
Example #8
0
def proxy_model(obj):
    content_model = obj.content_type.model_class()
    versionable = versionables.for_content(content_model)
    obj_ = deepcopy(obj)
    obj_.__class__ = versionable.version_model_proxy
    return obj_
Example #9
0
def proxy_model(obj):
    versionable = versionables.for_content(PageContent)
    obj_ = deepcopy(obj)
    obj_.__class__ = versionable.version_model_proxy
    return obj_