Esempio n. 1
0
    def test_course_unit_lesson_creation_and_query(self):
        """
        create a course, then unit, then lesson and make sure the entity
        relationships are all valid
        """
        course_key = Curriculum(
            content_type='course',
            content={
                'title': 'numero uno'
            },
        ).put()
        unit_key = Curriculum(content_type='unit',
                              content={
                                  'course': int(course_key.id())
                              }).put()
        lesson_key = Curriculum(content_type='lesson',
                                content={
                                    'course': int(course_key.id()),
                                    'unit': int(unit_key.id())
                                }).put()

        lesson = lesson_key.get()
        unit = ndb.Key(Curriculum, lesson.content['unit']).get()
        course = ndb.Key(Curriculum, unit.content['course']).get()
        self.assertIsNotNone(unit)
        self.assertIsNotNone(course)
        self.assertEqual(course.content['title'], 'numero uno')
Esempio n. 2
0
def new_lesson(content):
    """
    create a new lesson and return the lesson id
    """
    unit_id = content['unit']
    unit = get_content_by_id(unit_id)
    if unit is None:
        raise Exception("invalid unit id: that unit does not exist")

    if 'title' not in content:
        content['title'] = ''
    if 'body' not in content:
        content['body'] = ''

    content['private'] = unit.content['private']
    content['teacher'] = unit.content['teacher']
    content['course'] = unit.content['course']

    key = Curriculum(content_type = 'lesson', content = content).put()
    
    # add this lesson to the parent unit's lesson list
    unit.content['lessons'].append(int(key.id()))
    unit.put()

    return int(key.id())
Esempio n. 3
0
def new_unit(content):
    """
    create a new unit entity; return the id of the new unit
    """
    course_id = content['course']
    course = get_content_by_id(course_id)
    if course is None:
        raise Exception("invalid course id: that course does not exist")

    if 'title' not in content:
        content['title'] = ''
    if 'body' not in content:
        content['body'] = ''

    content['private'] = course.content['private']
    content['teacher'] = course.content['teacher']
    content['course'] = course_id
    content['lessons'] = []
    key = Curriculum(content_type='unit', content=content).put()

    # add this unit to the parent course's unit list
    course.content['units'].append(int(key.id()))
    course.put()

    return int(key.id())
 def setUp(self):
     self.curr_1 = Curriculum(name="computer_science",
                              country="ireland",
                              ID="n/a",
                              num_of_strands=3,
                              strand_names=[
                                  "core concepts",
                                  "practices and principles",
                                  "applied learning tasks"
                              ],
                              filename_LOs_txt="./fixtures/test_LO_CS.txt")
Esempio n. 5
0
    def test_simple_creation_of_new_curriculum_model(self):
        """
        test a simple put() of a new curriculum model 
        """

        new_content = Curriculum()
        new_content.populate(content_type='course',
                             content={
                                 'title': 'foo course',
                                 'owner': 123,
                                 'units': None
                             })
        key = new_content.put()

        fetched_content = ndb.Key(Curriculum, key.id()).get()
        self.assertEqual(fetched_content.content['title'], 'foo course')
Esempio n. 6
0
def new_course(content):
    """
    create a new course entity; return the id of the new course

    content should conform to:
    content = {
        'teacher' : (str or int, Required),
        'title' : (string),
        'body' : (string),
        'private' : (boolean),
    }
    """
    teacher_id = content['teacher']
    teacher = get_user(teacher_id)
    if teacher is None:
        raise Exception("invalid user id: that user does not exist")

    if 'title' not in content:
        content['title'] = ''
    if 'body' not in content:
        content['body'] = ''
    
    if 'private' not in content or content['private'] != True:
        content['private'] = False
        
    content['approved_students'] = []
    content['pending_approval'] = []
    content['units'] = []
    content['listed'] = False
    key = Curriculum(content_type = 'course', content = content).put()

    if teacher.courses:
        teacher.courses.append(int(key.id()))
    else:
        teacher.courses = [int(key.id())]
    teacher.put()

    return int(key.id())
Esempio n. 7
0
from models.curriculum import (
        Curriculum,
        LO_list_to_dict,
        dict_to_LO_list,
        dump_LO_dict
        )

""" Scripts which builds a curriculum for the user from an input
learning outcome .txt file and dumps it to a pickle file.
A human-readable version is dumped to a json file, as a dictionary """

# Instantiates a curriculum object
curr = Curriculum()
# User inputs name of the curriculum e.g. 'computer_science'
curr.user_input_name()
# User inputs name of the .txt file containing the learning outcomes
curr.user_input_filename_LOs()
# Sets the number of learning outcome strands from blank lines in file
curr.set_num_strands_from_file()
# Checks with user whether number of strands is correct
curr.user_check_num_strands()
# User inputs names of the strands
curr.user_input_strand_names()
# Loads the LOs into the curriculum, as a list of lists of LearningOutcome objects
curr.load_LOs_from_file(curr.filename_LOs_txt)
# Writes a pickle object representation of the curriculum to file
curr.dump_curriculum(f"{curr.name}.curriculum.pickle")
# Converts the LO lists to dictionary form
LO_dict = LO_list_to_dict(curr.LOs, curr.strand_names)
dump_LO_dict(LO_dict, f"{curr.name}.LO_dict.json")