Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24 - extract_nodelist_options only allows key = val to span a single line #24

Open
klipstein opened this issue Nov 6, 2011 · 0 comments

Comments

@klipstein
Copy link
Owner

Since the current extract function only allowed arguments to go on a single
line I wrote this to allow multiline arguments.

def extract_multiline_nodelist_options(nodelist, context=None):
    """
    Returns a dict containing the key=value options listed within the nodelist.
    The value can be a python dict, list, tuple, or number/string literal.
    """
    ret={}
    if context:
        rendered = nodelist.render(context)
    else:
        rendered = nodelist.render({})
    if rendered.find("=") > 0:
        opts = rendered.split("\n")
        for i in range(len(opts)):
           while i+1 < len(opts) and opts[i+1].find("=") == -1:
              opts[i] += opts.pop(i+1)
        for key, val in [opt.strip().split("=") for opt in opts if opt != ""]:
           ret[key.strip()]=eval(val.strip())
    return ret 


Original link: http://code.google.com/p/dojango/issues/detail?id=24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant