def edit_string_for_tags(tags):
    """
    Given list of ``Tag`` instances, creates a string representation of
    the list suitable for editing by the user, such that submitting the
    given string representation back without changing it will give the
    same list of tags.

    Tag names which contain commas will be double quoted.

    If any tag name which isn't being quoted contains whitespace, the
    resulting string of tag names will be comma-delimited, otherwise
    it will be space-delimited.
    """
    names = []
    use_commas = False
    for tag in tags:
        name = tag.name
        if ',' in name:
            names.append('"%s"' % name)
            continue
        elif ' ' in name:
            if not use_commas:
                use_commas = True
        names.append(name)
    if use_commas:
        glue = ', '
    else:
        glue = ' '
    return glue.join(names)
dataset/ETHPy150Open amarandon/smeuhsocial/apps/tagging/utils.py/edit_string_for_tags/original