'Handle requests to edit TS category name or description'

@web.expose
@web.require_admin
def edit_category(self, trans, **kwd):

    message = escape(kwd.get('message', ''))
    status = kwd.get('status', 'done')
    id = kwd.get('id', None)
    if (not id):
        message = 'No    category    ids    received    for    editing'
        trans.response.send_redirect(web.url_for(controller='admin', action='manage_categories', message=message, status='error'))
    category = suc.get_category(trans.app, id)
    original_category_name = str(category.name)
    original_category_description = str(category.description)
    if kwd.get('edit_category_button', False):
        flush_needed = False
        new_name = kwd.get('name', '').strip()
        new_description = kwd.get('description', '').strip()
        if (original_category_name != new_name):
            if (not new_name):
                message = 'Enter    a    valid    name'
                status = 'error'
            elif ((original_category_name != new_name) and suc.get_category_by_name(trans.app, new_name)):
                message = 'A    category    with    that    name    already    exists'
                status = 'error'
            else:
                category.name = new_name
                flush_needed = True
        if (original_category_description != new_description):
            category.description = new_description
            if (not flush_needed):
                flush_needed = True
        if flush_needed:
            trans.sa_session.add(category)
            trans.sa_session.flush()
            if (original_category_name != new_name):
                trans.app.repository_registry.edit_category_entry(original_category_name, new_name)
            message = ("The    information    has    been    saved    for    category    '%s'" % escape(category.name))
            status = 'done'
            return trans.response.send_redirect(web.url_for(controller='admin', action='manage_categories', message=message, status=status))
    return trans.fill_template('/webapps/tool_shed/category/edit_category.mako', category=category, message=message, status=status)
