'Resubmit certificates with status \'error\'.
Arguments:
username (unicode): Identifier for the certificate\'s user.
Keyword Arguments:
course_key_list (list): List of course key strings.
Raises:
CommandError'

def handle(self, *args, **options):

    only_course_keys = []
    for course_key_str in options.get('course_key_list', []):
        try:
            only_course_keys.append(CourseKey.from_string(course_key_str))
        except InvalidKeyError:
            raise CommandError('"{course_key_str}"    is    not    a    valid    course    key.'.format(course_key_str=course_key_str))
    if only_course_keys:
        LOGGER.info(u'Starting    to    re-submit    certificates    with    status    "error"    in    these    courses:    %s', ',    '.join([unicode(key) for key in only_course_keys]))
    else:
        LOGGER.info(u'Starting    to    re-submit    certificates    with    status    "error".')
    queryset = GeneratedCertificate.objects.select_related('user').filter(status=CertificateStatuses.error)
    if only_course_keys:
        queryset = queryset.filter(course_id__in=only_course_keys)
    resubmit_list = [(cert.user, cert.course_id) for cert in queryset]
    course_cache = {}
    resubmit_count = 0
    for (user, course_key) in resubmit_list:
        course = self._load_course_with_cache(course_key, course_cache)
        if (course is not None):
            certs_api.generate_user_certificates(user, course_key, course=course)
            resubmit_count += 1
            LOGGER.info(u"Re-submitted    certificate    for    user    %s    in    course    '%s'", user.id, course_key)
        else:
            LOGGER.error(u"Could    not    find    course    for    course    key    '%s'.        Certificate    for    user    %s    will    not    be    resubmitted.", course_key, user.id)
    LOGGER.info('Finished    resubmitting    %s    certificate    tasks', resubmit_count)
