Exemplo n.º 1
0
def get_template_placeholder_data(template):
    """
    Return the placeholders found in a template,
    wrapped in a :class:`~fluent_contents.models.containers.PlaceholderData` object.

    This function looks for the :class:`~fluent_contents.templatetags.fluent_contents_tags.PagePlaceholderNode` nodes
    in the template, using the :func:`~template_analyzer.djangoanalyzer.get_node_instances` function
    of `django-template-analyzer <https://github.com/edoburu/django-template-analyzer>`_.

    :param template:  The Template object, or nodelist to scan.
    :rtype: list of :class:`~fluent_contents.models.PlaceholderData`
    """
    # Find the instances.
    nodes = get_node_instances(template, PagePlaceholderNode)

    # Avoid duplicates, wrap in a class.
    names = set()
    result = []
    for pageplaceholdernode in nodes:
        data = PlaceholderData(
            slot=pageplaceholdernode.get_slot(),
            title=pageplaceholdernode.get_title(),
            role=pageplaceholdernode.get_role(),
            fallback_language=pageplaceholdernode.get_fallback_language(),
        )

        if data.slot not in names:
            result.append(data)
            names.add(data.slot)

    return result
Exemplo n.º 2
0
 def get_placeholder_data(self, request, obj):
     """
     Get placeholder data from layout.
     """
     if not obj or not obj.layout:
         data = [PlaceholderData(slot='main', role='m', title='Main')]
     else:
         data = obj.layout.get_placeholder_data()
     return data
    def get_placeholder_data(self, request, obj):
        """
        Return the data of the placeholder fields.
        """
        # Return all placeholder fields in the model.
        if not hasattr(self.model, '_meta_placeholder_fields'):
            return []

        data = []
        for name, field in self.model._meta_placeholder_fields.iteritems():
            assert isinstance(field, PlaceholderField)
            data.append(
                PlaceholderData(
                    slot=field.slot,
                    title=field.verbose_name.capitalize(),
                ))

        return data
Exemplo n.º 4
0
    def get_placeholder_data(self, request, obj):
        """
        Return the data of the placeholder fields.
        """
        # Return all placeholder fields in the model.
        if not hasattr(self.model, '_meta_placeholder_fields'):
            return []

        data = []
        for name, field in self.model._meta_placeholder_fields.iteritems():
            assert isinstance(field, PlaceholderField)
            data.append(PlaceholderData(
                slot=field.slot,
                title=field.verbose_name.capitalize(),
                fallback_language=None,  # Information cant' be known by "render_placeholder" in the template.
            ))

        return data
Exemplo n.º 5
0
 def get_placeholder_data(self, request, obj):
     return [PlaceholderData(slot='main', role='m', title='Main')]