'Create/set item slug. Slug is unique among user\'s importable items
for item\'s class. Returns true if item\'s slug was set/changed; false
otherwise.'

def create_item_slug(self, sa_session, item):

    cur_slug = item.slug
    if ((cur_slug is None) or (cur_slug == '')):
        if hasattr(item, 'name'):
            item_name = item.name
        elif hasattr(item, 'title'):
            item_name = item.title
        slug_base = util.ready_name_for_url(item_name.lower())
    else:
        slug_base = cur_slug
    new_slug = slug_base
    count = 1
    while (sa_session.query(item.__class__).filter((item.__class__.user == item.user), (item.__class__.slug == new_slug), (item.__class__.id != item.id)).count() != 0):
        new_slug = ('%s-%i' % (slug_base, count))
        count += 1
    item.slug = new_slug
    return (item.slug == cur_slug)
