def _forwards(apps, schema_editor):
    """
    Make sure that the MarkupItem model actually points
    to the correct proxy model, that implements the given language.
    """
    # Need to work on the actual models here.
    from django.contrib.contenttypes.models import ContentType

    from fluent_contents.plugins.markup.models import LANGUAGE_MODEL_CLASSES, MarkupItem

    ctype = ContentType.objects.get_for_model(MarkupItem)

    for language, proxy_model in LANGUAGE_MODEL_CLASSES.items():
        proxy_ctype = ContentType.objects.get_for_model(
            proxy_model, for_concrete_model=False)
        MarkupItem.objects.filter(
            polymorphic_ctype=ctype,
            language=language).update(polymorphic_ctype=proxy_ctype)
def _forwards(apps, schema_editor):
    """
    Make sure that the MarkupItem model actually points
    to the correct proxy model, that implements the given language.
    """
    # Need to work on the actual models here.
    from fluent_contents.plugins.markup.models import LANGUAGE_MODEL_CLASSES
    from fluent_contents.plugins.markup.models import MarkupItem
    from django.contrib.contenttypes.models import ContentType

    ctype = ContentType.objects.get_for_model(MarkupItem)

    for language, proxy_model in LANGUAGE_MODEL_CLASSES.items():
        proxy_ctype = ContentType.objects.get_for_model(proxy_model, for_concrete_model=False)
        MarkupItem.objects.filter(
            polymorphic_ctype=ctype, language=language
        ).update(
            polymorphic_ctype=proxy_ctype
        )
Esempio n. 3
0
    class Media:
        css = {'screen': ('fluent_contents/plugins/markup/markup_admin.css', )}

    def render(self, request, instance, **kwargs):
        try:
            html = backend.render_text(instance.text, instance.language)
        except Exception, e:
            html = self.render_error(e)

        # Included in a DIV, so the next item will be displayed below.
        return mark_safe('<div class="markup">' + html + '</div>\n')


# Dynamically create plugins for every language type.
# Allows adding them separately in the admin, while using the same database table.
for language, model in LANGUAGE_MODEL_CLASSES.iteritems():
    if language not in appsettings.FLUENT_MARKUP_LANGUAGES:
        continue

    form = type("{0}MarkupItemForm".format(language.capitalize()),
                (MarkupItemForm, ), {
                    'default_language': language,
                })

    classname = "{0}MarkupPlugin".format(language.capitalize())
    PluginClass = type(classname, (MarkupPluginBase, ), {
        'model': model,
        'form': form,
    })

    #globals()[classname] = PluginClass
        css = {'screen': ('fluent_contents/plugins/markup/markup_admin.css',)}


    def render(self, request, instance, **kwargs):
        try:
            html = backend.render_text(instance.text, instance.language)
        except Exception as e:
            html = self.render_error(e)

        # Included in a DIV, so the next item will be displayed below.
        return mark_safe('<div class="markup">' + html + '</div>\n')


# Dynamically create plugins for every language type.
# Allows adding them separately in the admin, while using the same database table.
for language, model in LANGUAGE_MODEL_CLASSES.items():
    if language not in appsettings.FLUENT_MARKUP_LANGUAGES:
        continue

    form = type("{0}MarkupItemForm".format(language.capitalize()), (MarkupItemForm,), {
        'default_language': language,
    })

    classname = "{0}MarkupPlugin".format(language.capitalize())
    PluginClass = type(classname, (MarkupPluginBase,), {
        'model': model,
        'form': form,
    })

    #globals()[classname] = PluginClass
    plugin_pool.register(PluginClass)