2
votes

I am trying to to insert a course template ( template being mandatory details required to create a course on edx studio and also some grading settings). I wish to insert the course template by means of an external script which will have read/write permissions on the database of the server on which openedx is installed .

I already went through the docs but they seem to have no information with regards to my objective. I arbitarily tried inserting a course in openedx and saw that at least one MySQL table changed and also some collections in the associated MongoDB also changed. But this is hardly anything concrete. I would go through the source code , but it is such a large codebase.

I am using the dogwood version of openedx.

Could someone please point me in the right direction as to how I could accomplish this or at least tell which part of the codebase I should look at?

1
Could you specify what parameters you are trying to change, exactly? Did you try to change these details programmatically? If yes, what did you try? - Régis B.
details like the assessment types the edX course would have, their respective weightages, start date and end date of the course besides the mandatory course display name ,abbreviation, organisation and course run - the_interest_seeker

1 Answers

1
votes

This is how you create a course:

from xmodule.modulestore.django import modulestore
from datetime import datetime
store.create_course(
    "org", "num", "run", # course ID
    1,                   # course creator user ID
    # Set the start date of the course to the start of the year
    fields={"start": datetime(2016, 1, 1)} 
)

See the fields argument? This is were the attributes of the new course can be defined. The list of attributes that can be defined is available in common.lib.xmodule.xmodule.course_module:CourseFields. In the example above we defined the start attribute, but other fields can be defined using the same method.

If you wish to modify a course attribute after you have created it, e.g the start attribute, this is how you would do it:

from opaque_keys.edx.keys import CourseKey
course = store.get_course(CourseKey.from_string("course-v1:org+num+run"))
course.start = datetime.now()
course.save()

Note that this does not cover defining the assessments of each course. Defining this programmatically is more complex. You can get a better understanding at how grading settings are defined by taking a look at the grading_handler view from the contentstore views. As we can see, all the grading information is stored in a CourseGradingModel. The method that you need is update_from_json.