def get_group_id_for_comments_service(request, course_key, commentable_id=None):
 if ((commentable_id is None) or is_commentable_cohorted(course_key, commentable_id)):
  if (request.method == 'GET'):
   requested_group_id = request.GET.get('group_id')
  elif (request.method == 'POST'):
   requested_group_id = request.POST.get('group_id')
  if has_permission(request.user, 'see_all_cohorts', course_key):
   if (not requested_group_id):
    return None
   try:
    group_id = int(requested_group_id)
    get_cohort_by_id(course_key, group_id)
   except CourseUserGroup.DoesNotExist:
    raise ValueError
  else:
   group_id = get_cohort_id(request.user, course_key)
  return group_id
 else:
  return None

def get_group_id_for_comments_service ( request , course_key , commentable_id = None ) : if ( ( commentable_id is None ) or is_commentable_cohorted ( course_key , commentable_id ) ) : if ( request . method == 'GET' ) : requested_group_id = request . GET . get ( 'group_id' ) elif ( request . method == 'POST' ) : requested_group_id = request . POST . get ( 'group_id' ) if has_permission ( request . user , 'see_all_cohorts' , course_key ) : if ( not requested_group_id ) : return None try : group_id = int ( requested_group_id ) get_cohort_by_id ( course_key , group_id ) except CourseUserGroup . DoesNotExist : raise ValueError else : group_id = get_cohort_id ( request . user , course_key ) return group_id else : return None
given a user requesting content within a commentable_id .