def create_role(request):
  result = {'status': -1, 'message': 'Error'}

  try:
    role = json.loads(request.POST['role'])

    api = get_api(request.user)

    api.create_sentry_role(role['name'])

    privileges = [privilege for privilege in role['privileges'] if privilege['status'] not in ('deleted', 'alreadydeleted')]
    result['privileges'] = _hive_add_privileges(request.user, role, privileges)
    api.alter_sentry_role_add_groups(role['name'], role['groups'])

    result['role'] = {"name": role['name'], "groups": role['groups']}

    result['message'] = _('Role created!')
    result['status'] = 0
  except Exception, e:
    LOG.exception("could not create role")

    result['message'] = unicode(str(e), "utf8")

  return JsonResponse(result)
dataset/ETHPy150Open cloudera/hue/apps/security/src/security/api/hive.py/create_role/original