Previously asked on edx code (edx Google Group) How to expand a field for course, such as adding a category field to a course.
The reply says to add the field you want directly to the couesefields. Position common/lib/xmodule/course_module.py
after. The field is automatically displayed in the Advanced settings. In this way I find that the field is indeed a property of course (experiment in the shell). However, it is not automatically displayed in the Advanced settings, do not know whether it is a version problem.
There is also a reply that he uses the Org field to store the class classification. Because they are internally using edx, no org is required. But this is not always a good way.
I received an e-mail two days ago and said that he also wanted to expand the course, similar to my previous needs, and wanted to help.
It seems to be a very common requirement.
I'll share my own way. Also talk about the specific process, but not only to give a plan, so that the small partners encounter similar problems next, you can follow similar ideas to solve their own.
Requirements Description
Common requirements are similar to the following: Adding category fields to courses for classifying courses and using them on the home page.
The initial scenario
- I wrote a Django app and added it to Lms/djangoapps. course_id field in App.models
- Write Yourself a homepage
- Manage the contents of the homepage in admin
In fact, it is like writing a small content management system, the core object of management is course. And we know that the key sign of the course is course_id. I track the code that registers the course and add a custom create_home_course function to the code execution path.
Registering the newly created course in our own app.models in the Create_home_course function is the key to getting course_id from it so that you can navigate to the course.
The advantage of this approach is that there is no need to invade Couesefields
We're going to focus on the following scenario today.
Now the solution
In fact, the idea is simple. is 日程&细节
how the field in the trace is stored and interacts with the front end. You can imitate it.
OK, full of coffee, let's start.
I chose to track this field: 每周投入课程学习的小时数
.
Using the Chrome Developer tool, you see that the ID of the form field iscourse-effort
Search for effort in Edx-platform. We can see all the effort-related code and the files it contains. In fact, it is very recommended to use GitHub to study the code, you can refer to my blog
Next is the work of gourd painting. The fields we need are added accordingly. We modify it in the following order: Python>js>html>sass
0
The following work is done in the/edx/app/edxapp/edx-platform/directory.
Python
Vim cms/djangoapps/models/settings/course_details.py
Self.effort = none # int hours/week+ self.category = none self.course_image_name = "" ... + Temploc = Course_key.make_usage_key (' About ', ' category ') + try:+ course_details.category = Modulestore (). get_item ( Temploc). data+ except itemnotfounderror:+ pass++ temploc = Course_key.make_usage_key (' About ', ' video ' try: raw_video = Modulestore (). get_item (temploc). Data ... - for About_type in [' Syllabus ', ' Overview ', ' effort ', ' short_description ']:+ for about_type in [' Syllabus ', ' overview ', ' effort ', ' Category ', ' Short_description ']: cls.update_about_item (Course_key, About_type, Jsondict[about_type], descriptor, user)
Vim cms/templates/settings.html
' Requirements ', ' syllabus ', ' textbook ', ' FAQs ', ' more_info ', ' number ', ' Instructors ', ' Overview ',- ' effort ', ' End_date ', ' Prerequisites ', ' ocw_links ']:+ ' effort ', ' Category ', ' end_date ', ' Prerequisites ', ' ocw_links ']:
Js
Vim Cms/static/js/views/settings/main.js
this. $el. Find (' # ' + this.fieldtoselectormap[' effort '). Val (this.model.get (' effort ')), + + //added by wwj+ this. $el. Find (' # ' + this.fieldtoselectormap[' category '). Val (this.model.get (' category ')); ... ' Effort ': "Course-effort", + ' category ': "Course-category", ' course_image_asset_path ': ' Course-image-url ' ... Case ' Course-effort ': This.setfield (event); break;+ //added by wwj+ case ' course-category ': + This.setfield (event); + Break ;
Vim Cms/static/js/models/settings/course_details.js
Effort:null, //an int or null,+ category:null,
Html
Vim cms/templates/settings.html
+ # #added by wwj+% if about_page_editable:+ Vim lms/templates/courseware/course_about.html
<li><div class= "icon effort" ></div><p>${_ ("estimated effort")}</p><span class= " Start-date ">${get_course_about_section (Course," effort ")}</span></li> % endif+ if get_ Course_about_section (Course, "category"): + <li><div class= "icon category" ></div><p> Course categories </p><span class= "Start-date" >${get_course_about_section (Course, "category")}</span></li >+ % endif
SassVim Cms/static/sass/views/_settings.scss
#field-course-effort { Width:flex-grid (3, 9); } + #field-course-category {+ Width:flex-grid (3, 9); + }
Outstanding
- Commit the above changes once to your own branch and try not to merge into the official branch
- Update_assets
Sudo-h-u edxapp bashsource/edx/app/edxapp/edxapp_envcd/edx/app/edxapp/edx-platformpaver update_assets cms-- Settings=aws
* Restart Edxapp:sudo /edx/bin/supervisorctl -c /edx/etc/supervisord.conf restart edxapp:
Test
- Let's go to the CMS
日程&细节
and fill in the class category
- Go to the About page of the course to see
Online learning expands fields for course