Ejemplo n.º 1
0
def get_entry_model():
    """
    Return the actual entry model that is in use.

    This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model.
    The model is automatically registered with *django-fluent-comments*
    and *django-any-urlfield* when it's installed.
    """
    global _EntryModel

    if _EntryModel is None:
        # This method is likely called the first time when the admin initializes, the sitemaps module is imported, or BaseBlogMixin is used.
        # Either way, it needs to happen after all apps have initialized, to make sure the model can be imported.
        if not appsettings.FLUENT_BLOGS_ENTRY_MODEL:
            _EntryModel = Entry
        else:
            app_label, model_name = appsettings.FLUENT_BLOGS_ENTRY_MODEL.rsplit(
                '.', 1)
            if django.VERSION < (1, 7):
                _EntryModel = get_model(app_label,
                                        model_name,
                                        only_installed=False)
            else:
                _EntryModel = get_model(app_label, model_name)

            if _EntryModel is None:
                raise ImportError(
                    "{app_label}.{model_name} could not be imported.".format(
                        app_label=app_label, model_name=model_name))

        # Auto-register with django-fluent-comments moderation
        if 'fluent_comments' in settings.INSTALLED_APPS and issubclass(
                _EntryModel, CommentsEntryMixin):
            from fluent_comments.moderation import moderate_model
            moderate_model(
                _EntryModel,
                publication_date_field='publication_date',
                enable_comments_field='enable_comments',
            )

        # Auto-register with django-any-urlfield
        if 'any_urlfield' in settings.INSTALLED_APPS:
            from any_urlfield.models import AnyUrlField
            from any_urlfield.forms.widgets import SimpleRawIdWidget
            AnyUrlField.register_model(_EntryModel,
                                       widget=SimpleRawIdWidget(_EntryModel))

    return _EntryModel
Ejemplo n.º 2
0
def get_entry_model():
    """
    Return the actual entry model that is in use.

    This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model.
    The model is automatically registered with *django-fluent-comments*
    and *django-any-urlfield* when it's installed.
    """
    global _EntryModel

    if _EntryModel is None:
        # This method is likely called the first time when the admin initializes, the sitemaps module is imported, or BaseBlogMixin is used.
        # Either way, it needs to happen after all apps have initialized, to make sure the model can be imported.
        if not appsettings.FLUENT_BLOGS_ENTRY_MODEL:
            _EntryModel = Entry
        else:
            app_label, model_name = appsettings.FLUENT_BLOGS_ENTRY_MODEL.rsplit('.', 1)
            if django.VERSION < (1, 7):
                _EntryModel = get_model(app_label, model_name, only_installed=False)
            else:
                _EntryModel = get_model(app_label, model_name)

            if _EntryModel is None:
                raise ImportError("{app_label}.{model_name} could not be imported.".format(app_label=app_label, model_name=model_name))

        # Auto-register with django-fluent-comments moderation
        if 'fluent_comments' in settings.INSTALLED_APPS and issubclass(_EntryModel, CommentsEntryMixin):
            from fluent_comments.moderation import moderate_model
            moderate_model(_EntryModel,
                publication_date_field='publication_date',
                enable_comments_field='enable_comments',
            )

        # Auto-register with django-any-urlfield
        if 'any_urlfield' in settings.INSTALLED_APPS:
            from any_urlfield.models import AnyUrlField
            from any_urlfield.forms.widgets import SimpleRawIdWidget
            AnyUrlField.register_model(_EntryModel, widget=SimpleRawIdWidget(_EntryModel))

    return _EntryModel
Ejemplo n.º 3
0
def get_category_model():
    """
    Return the category model to use.

    This function reads the :ref:`FLUENT_BLOGS_CATEGORY_MODEL` setting to find the model.
    """
    app_label, model_name = appsettings.FLUENT_BLOGS_CATEGORY_MODEL.rsplit('.', 1)
    try:
        return get_model(app_label, model_name)
    except Exception as e:  # ImportError/LookupError
        raise ImproperlyConfigured("Failed to import FLUENT_BLOGS_CATEGORY_MODEL '{0}': {1}".format(
            appsettings.FLUENT_BLOGS_CATEGORY_MODEL, str(e)
        ))
Ejemplo n.º 4
0
def get_category_model():
    """
    Return the category model to use.

    This function reads the :ref:`FLUENT_BLOGS_CATEGORY_MODEL` setting to find the model.
    """
    app_label, model_name = appsettings.FLUENT_BLOGS_CATEGORY_MODEL.rsplit(
        '.', 1)
    try:
        return get_model(app_label, model_name)
    except Exception as e:  # ImportError/LookupError
        raise ImproperlyConfigured(
            "Failed to import FLUENT_BLOGS_CATEGORY_MODEL '{0}': {1}".format(
                appsettings.FLUENT_BLOGS_CATEGORY_MODEL, str(e)))