Esempio 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)
            _EntryModel = get_model(app_label, 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
Esempio n. 2
0
def _register_anyurlfield_type():
    try:
        from any_urlfield.models import AnyUrlField
        from any_urlfield.forms.widgets import SimpleRawIdWidget
    except ImportError:
        pass
    else:
        AnyUrlField.register_model(FaqQuestion, widget=SimpleRawIdWidget(FaqQuestion))
Esempio n. 3
0
def _register_anyurlfield_type():
    try:
        from any_urlfield.models import AnyUrlField
        from any_urlfield.forms.widgets import SimpleRawIdWidget
    except ImportError:
        pass
    else:
        AnyUrlField.register_model(FaqQuestion, widget=SimpleRawIdWidget(FaqQuestion))
Esempio n. 4
0
def _register_cmsfield_url_type():
    try:
        from any_urlfield.models import AnyUrlField
    except ImportError:
        pass
    else:
        from django import forms
        from any_urlfield.forms.widgets import SimpleRawIdWidget
        AnyUrlField.register_model(Page, form_field=PageChoiceField(queryset=UrlNode.objects.published().non_polymorphic(), widget=SimpleRawIdWidget(Page)))
Esempio n. 5
0
def _register_cmsfield_url_type():
    try:
        from any_urlfield.models import AnyUrlField
    except ImportError:
        pass
    else:
        from django import forms
        from any_urlfield.forms.widgets import SimpleRawIdWidget
        AnyUrlField.register_model(Page, form_field=PageChoiceField(widget=SimpleRawIdWidget(Page)))
Esempio n. 6
0
def _register_cmsfield_url_type():
    try:
        from any_urlfield.models import AnyUrlField
    except ImportError:
        pass
    else:
        from django import forms
        from any_urlfield.forms.widgets import SimpleRawIdWidget
        AnyUrlField.register_model(
            Page, form_field=PageChoiceField(widget=SimpleRawIdWidget(Page)))
Esempio n. 7
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
Esempio n. 8
0
def _register_cmsfield_url_type():
    try:
        from any_urlfield.models import AnyUrlField
    except ImportError:
        pass
    else:
        import any_urlfield
        from distutils.version import StrictVersion
        from any_urlfield.forms.widgets import SimpleRawIdWidget

        if StrictVersion(any_urlfield.__version__) >= StrictVersion('2.0a1'):
            # Allow lambda parameter for late evaluation.
            AnyUrlField.register_model(Page, form_field=lambda: PageChoiceField(widget=SimpleRawIdWidget(Page)))
        else:
            # This will run a query at import time!
            AnyUrlField.register_model(Page, form_field=PageChoiceField(widget=SimpleRawIdWidget(Page)))
Esempio n. 9
0
def _register_cmsfield_url_type():
    try:
        from any_urlfield.models import AnyUrlField
    except ImportError:
        pass
    else:
        import any_urlfield
        from distutils.version import StrictVersion
        from any_urlfield.forms.widgets import SimpleRawIdWidget

        if StrictVersion(any_urlfield.__version__) >= StrictVersion('2.0a1'):
            # Allow lambda parameter for late evaluation.
            AnyUrlField.register_model(Page,
                                       form_field=lambda: PageChoiceField(
                                           widget=SimpleRawIdWidget(Page)))
        else:
            # This will run a query at import time!
            AnyUrlField.register_model(
                Page,
                form_field=PageChoiceField(widget=SimpleRawIdWidget(Page)))
Esempio n. 10
0
class PageModel(models.Model):
    """
    Example model to be linking to.
    """
    slug = models.SlugField()

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)

class RegPageModel(models.Model):
    slug = models.SlugField()

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)

AnyUrlField.register_model(RegPageModel)


class AnyUrlTests(TestCase):

    def test_registry(self):
        reg = UrlTypeRegistry()
        self.assertIsNotNone(reg['http'])
        self.assertIsNotNone(reg['https'])


    def test_from_model(self):
        page2 = RegPageModel.objects.create(pk=1, slug='foo2')
        v = AnyUrlValue.from_model(page2)

        self.assertEqual(v.url_type.prefix, 'any_urlfield.regpagemodel')   # app_label.modelname
Esempio n. 11
0
    def get_absolute_url(self):
        return str(self.url)


class PageModel(models.Model):
    """
    Example model to be linking to.
    """
    slug = models.SlugField()

    def __str__(self):
        return self.slug

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)


class RegPageModel(models.Model):
    slug = models.SlugField()

    def __str__(self):
        return self.slug

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)


AnyUrlField.register_model(RegPageModel,
                           widget=SimpleRawIdWidget(RegPageModel))
admin.site.register(RegPageModel)  # Needed for SimpleRawIdWidget to render
Esempio n. 12
0
    def get_absolute_url(self):
        return str(self.url)


class PageModel(models.Model):
    """
    Example model to be linking to.
    """
    slug = models.SlugField()

    def __str__(self):
        return self.slug

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)


class RegPageModel(models.Model):
    slug = models.SlugField()

    def __str__(self):
        return self.slug

    def get_absolute_url(self):
        return '/{0}/'.format(self.slug)


AnyUrlField.register_model(RegPageModel, widget=SimpleRawIdWidget(RegPageModel))
admin.site.register(RegPageModel)  # Needed for SimpleRawIdWidget to render