Exemplo n.º 1
0
def render_uploads(content, template_path="adminfiles/render/"):
    """
    Replace all uploaded file references in a content string with the
    results of rendering a template found under ``template_path`` with
    the ``FileUpload`` instance and the key=value options found in the
    file reference.

    So if "<<<my-uploaded-file:key=val:key2=val2>>>" is found in the
    content string, it will be replaced with the results of rendering
    the selected template with ``upload`` set to the ``FileUpload``
    instance with slug "my-uploaded-file" and ``options`` set to
    {'key': 'val', 'key2': 'val2'}.

    If the given slug is not found, the reference is replaced with the
    empty string.

    If ``djangoembed`` or ``django-oembed`` is installed, also replaces OEmbed
    URLs with the appropriate embed markup.
    
    """
    def _replace(match):
        upload, options = parse_match(match)
        if upload.__class__.__name__ == 'Gallery':
            return render_gallery(upload, template_path, **options)
        else:
            return render_upload(upload, template_path, **options)
    return oembed_replace(substitute_uploads(content, _replace))
Exemplo n.º 2
0
def render_uploads(content, template_path="adminfiles/render/"):
    """
    Replace all uploaded file references in a content string with the
    results of rendering a template found under ``template_path`` with
    the ``FileUpload`` instance and the key=value options found in the
    file reference.

    So if "<<<my-uploaded-file:key=val:key2=val2>>>" is found in the
    content string, it will be replaced with the results of rendering
    the selected template with ``upload`` set to the ``FileUpload``
    instance with slug "my-uploaded-file" and ``options`` set to
    {'key': 'val', 'key2': 'val2'}.

    If the given slug is not found, the reference is replaced with the
    empty string.

    If ``djangoembed`` or ``django-oembed`` is installed, also replaces OEmbed
    URLs with the appropriate embed markup.
    
    """
    def _replace(match):
        upload, options = parse_match(match)
        return render_upload(upload, template_path, **options)

    return oembed_replace(substitute_uploads(content, _replace))
Exemplo n.º 3
0
def user_filter(string, args=None):

    # Apply oEmbed
    oembed_kwargs = {}
    oembed_kwargs["max_width"] = 320
    oembed_kwargs["max_height"] = 240
    string = oembed_replace(string, **oembed_kwargs)

    # Apply Urlize
    string = urlize(string, nofollow=True, autoescape=True)

    # Apply Textile
    string = textile(string)

    return string
Exemplo n.º 4
0
def my_oembed(input, args):
    args = args.split()
    if len(args) > 1:
        raise template.TemplateSyntaxError(
            "Oembed tag takes only one (option"
            "al) argument: WIDTHxHEIGHT, where WIDTH and HEIGHT are positive "
            "integers."
        )
    if len(args) == 1:
        width, height = args[0].lower().split("x")
        if not width and height:
            raise template.TemplateSyntaxError(
                "Oembed's optional WIDTHxHEIGH" "T argument requires WIDTH and HEIGHT to be positive integers."
            )
    else:
        width, height = None, None
    kwargs = {}
    if width and height:
        kwargs["max_width"] = width
        kwargs["max_height"] = height

    return oembed_replace(input, **kwargs)