def get_courses():
    ''' safe proxy call to moodleutils.course_list '''
    try:
        lst = []
        for c in mu.course_list():
            lst.append(c[1])
        return _alphasort(lst)
    except:
        return []
def get_course_id(shortname):
    ''' returns the course id of the given course identified by shortname, or None if this does not exist '''
    course_id = None
    courses = mu.course_list()
    for c in courses:
        if shortname == c[1] and not course_id:
            course_id = c[0]
        elif shortname == c[1]:
            raise Exception("something is terribly wrong in moodle")
    return course_id
def notifyuser(fullname, username, email, password, courses):
    ''' send an account creation notification email to user '''


    courses_text = ''
    if len(courses) > 0:
        allcourses = mu.course_list()

        # id, shortname, fullname
        courses_info = [c for c in allcourses if c[1] in courses]

        courses_text = '\nYou have been enroled in the following courses:\n'
        for c in courses_info:
            courses_text = courses_text + '\n%s: %s/moodle/course/view.php?id=%s' % (c[2], MCWEB_NOTIFY_ROOT_URL, c[0])
        courses_text = courses_text + '\n'

    body = '''
Dear %s

You have been added to the %s e-Learning system.

For ease of communication, PLEASE register your email address at the mailinglist: https://lists.esss.dk/mailman/listinfo/pan-learning-users

Your username and password for accessing the e-learning system are:

username: %s
password: %s

To change your password, please visit %s
%s
Best,

The pan-learning.org admin team
    ''' % (fullname, MCWEB_NOTIFY_EMAIL_URL, username, password, MCWEB_SSP_URL, courses_text)

    try:
        f = open('_body', 'w')
        f.write(body)
        f.close()

        cmd = 'mailx -r [email protected] -s "Welcome to PaN-learning.org" %s < _body' % email
        retcode = subprocess.call(cmd, shell=True)
        print(cmd)

        if retcode != 0:
            raise Exception('notifyuser mailx retcode: %s' % retcode)
    finally:
        os.remove('_body')
Beispiel #4
0
def notifyuser(fullname, username, email, password, courses):
    ''' send an account creation notification email to user '''

    courses_text = ''
    if len(courses) > 0:
        allcourses = mu.course_list()

        # id, shortname, fullname
        courses_info = [c for c in allcourses if c[1] in courses]

        courses_text = '\nYou have been enroled in the following courses:\n'
        for c in courses_info:
            courses_text = courses_text + '\n%s: %s/moodle/course/view.php?id=%s' % (
                c[2], MCWEB_NOTIFY_ROOT_URL, c[0])
        courses_text = courses_text + '\n'

    body = '''
Dear %s

You have been added to the %s e-Learning system.

username: %s
password: %s

To change your password, please visit %s
%s
Best,

The e-neutrons.org admin team
    ''' % (fullname, MCWEB_NOTIFY_EMAIL_URL, username, password, MCWEB_SSP_URL,
           courses_text)

    try:
        f = open('_body', 'w')
        f.write(body)
        f.close()

        cmd = 'mailx -s "welcome to mcweb" %s < _body' % email
        retcode = subprocess.call(cmd, shell=True)
        print(cmd)

        if retcode != 0:
            raise Exception('notifyuser mailx retcode: %s' % retcode)
    finally:
        os.remove('_body')