def students_require_certificate(course_id, enrolled_students, statuses_to_regenerate=None):
 if statuses_to_regenerate:
  students_require_certificates = enrolled_students.filter(generatedcertificate__course_id=course_id, generatedcertificate__status__in=statuses_to_regenerate)
  return list(students_require_certificates)
 else:
  students_already_have_certs = User.objects.filter((~ Q(generatedcertificate__status=CertificateStatuses.unavailable)), generatedcertificate__course_id=course_id)
  return list((set(enrolled_students) - set(students_already_have_certs)))

def students_require_certificate ( course_id , enrolled_students , statuses_to_regenerate = None ) : if statuses_to_regenerate : students_require_certificates = enrolled_students . filter ( generatedcertificate__course_id = course_id , generatedcertificate__status__in = statuses_to_regenerate ) return list ( students_require_certificates ) else : students_already_have_certs = User . objects . filter ( ( ~ Q ( generatedcertificate__status = CertificateStatuses . unavailable ) ) , generatedcertificate__course_id = course_id ) return list ( ( set ( enrolled_students ) - set ( students_already_have_certs ) ) )
returns list of students where certificates needs to be generated .