Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ target/
# IDEs
.idea
.idea/*

.vscode
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ jobs:
name: Run tests
command: |
. venv/bin/activate
pep8 eoc_journal --max-line-length=120
pycodestyle eoc_journal --max-line-length=120
pylint eoc_journal
python run_tests.py
56 changes: 36 additions & 20 deletions eoc_journal/eoc_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,35 +312,51 @@ def list_user_pb_answers_by_section(self):
else:
return None

def list_pb_answers(self, all_blocks=False):
@staticmethod
def _iter_pb_answers(response):
"""
Returns a list of dicts with info about all problem builder's pb-answer
blocks present in the current coures.

The items are ordered in the order they appear in the course.
Iterate over pb-answer blocks in course blocks API response and yield
section, subsection and unit display names along with pb-answer blocks.
"""
response = self._fetch_pb_answer_blocks(all_blocks)
blocks = response['blocks']
course_block = blocks[response['root']]
result = []
for section_id in course_block.get('children', []):
section_block = blocks[section_id]
for subsection_id in section_block.get('children', []):
subsection_block = blocks[subsection_id]
for unit_id in subsection_block.get('children', []):
unit_block = blocks[unit_id]
for pb_answer_id in unit_block.get('children', []):
pb_answer_block = blocks[pb_answer_id]
result.append({
'section': section_block['display_name'],
'subsection': subsection_block['display_name'],
'unit': unit_block['display_name'],
'id': pb_answer_block['id'],
'name': pb_answer_block['student_view_data']['name'],
'question': pb_answer_block['student_view_data']['question'],
'display_name': pb_answer_block['display_name'],
})
return result
for pb_id in unit_block.get('children', []):
pb_block = blocks[pb_id]
for pb_answer_id in pb_block.get('children', []):
pb_answer_block = blocks[pb_answer_id]
yield (
section_block['display_name'],
subsection_block['display_name'],
unit_block['display_name'],
pb_answer_block,
)

def list_pb_answers(self, all_blocks=False):
"""
Returns a list of dicts with info about all problem builder's pb-answer
blocks present in the current coures.

The items are ordered in the order they appear in the course.
"""
response = self._fetch_pb_answer_blocks(all_blocks)
return [
{
'section': section,
'subsection': subsection,
'unit': unit,
'id': block['id'],
'name': block['student_view_data']['name'],
'question': block['student_view_data']['question'],
'display_name': block['display_name'],
}
for section, subsection, unit, block in self._iter_pb_answers(response)
]

def _get_course_id(self):
"""
Expand Down Expand Up @@ -485,7 +501,7 @@ def _fetch_pb_answer_blocks(self, all_blocks=False):
depth='all',
requested_fields='student_view_data,children',
student_view_data='pb-answer',
block_types_filter='pb-answer,vertical,sequential,chapter,course',
block_types_filter='pb-answer,problem-builder,vertical,sequential,chapter,course',
username=user.username,
)
return response
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lxml
mako
markupsafe
pdfminer
pep8
pycodestyle
pylint
python-dateutil
pytz
Expand Down
41 changes: 37 additions & 4 deletions tests/integration/data/course_api_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,24 @@
"display_name": "Unit 3",
"block_id": "e87577535d0e4c68a2ac9d760d003c92",
"children": [
"i4x://Org/Course/pb-answer/b86edf60454b47dbb8f2e1b4e2d48d6a"
"i4x://Org/Course/problem-builder/7e70fa0ea4684ec489e4f72734cc7bce"
],
"student_view_url": "http://example.com/xblock/i4x://Org/Course/vertical/e87577535d0e4c68a2ac9d760d003c92",
"lms_web_url": "http://example.com/courses/Org/Course/Run/jump_to/i4x://Org/Course/vertical/e87577535d0e4c68a2ac9d760d003c92",
"type": "vertical",
"id": "i4x://Org/Course/vertical/e87577535d0e4c68a2ac9d760d003c92"
},
"i4x://Org/Course/problem-builder/7e70fa0ea4684ec489e4f72734cc7bce": {
"display_name": "",
"block_id": "7e70fa0ea4684ec489e4f72734cc7bce",
"children": [
"i4x://Org/Course/pb-answer/b86edf60454b47dbb8f2e1b4e2d48d6a"
],
"student_view_url": "http://example.com/xblock/i4x://Org/Course/problem-builder/7e70fa0ea4684ec489e4f72734cc7bce",
"lms_web_url": "http://example.com/courses/Org/Course/Run/jump_to/i4x://Org/Course/problem-builder/7e70fa0ea4684ec489e4f72734cc7bce",
"type": "problem-builder",
"id": "i4x://Org/Course/problem-builder/7e70fa0ea4684ec489e4f72734cc7bce"
},
"i4x://Org/Course/chapter/c154bd7716654193969e20d6e2fd994a": {
"display_name": "Second Section",
"block_id": "c154bd7716654193969e20d6e2fd994a",
Expand Down Expand Up @@ -136,15 +147,37 @@
"display_name": "Unit 1",
"block_id": "8f995fb218664104bb3f898f10744511",
"children": [
"i4x://Org/Course/pb-answer/6f070c350e39429cbccfd3185a33621c",
"i4x://Org/Course/pb-answer/a0b04a13d3074229b6be33fbc31de233",
"i4x://Org/Course/pb-answer/927c5b8cd051475e937b8c1091a9feaf"
"i4x://Org/Course/problem-builder/693f5d5a98b94f9481c381457d290bf6",
"i4x://Org/Course/problem-builder/26071191d5344d5e931c9a90a49e6192"
],
"student_view_url": "http://example.com/xblock/i4x://Org/Course/vertical/8f995fb218664104bb3f898f10744511",
"lms_web_url": "http://example.com/courses/Org/Course/Run/jump_to/i4x://Org/Course/vertical/8f995fb218664104bb3f898f10744511",
"type": "vertical",
"id": "i4x://Org/Course/vertical/8f995fb218664104bb3f898f10744511"
},
"i4x://Org/Course/problem-builder/693f5d5a98b94f9481c381457d290bf6": {
"display_name": "",
"block_id": "693f5d5a98b94f9481c381457d290bf6",
"children": [
"i4x://Org/Course/pb-answer/6f070c350e39429cbccfd3185a33621c",
"i4x://Org/Course/pb-answer/a0b04a13d3074229b6be33fbc31de233"
],
"student_view_url": "http://example.com/xblock/i4x://Org/Course/problem-builder/693f5d5a98b94f9481c381457d290bf6",
"lms_web_url": "http://example.com/courses/Org/Course/Run/jump_to/i4x://Org/Course/problem-builder/693f5d5a98b94f9481c381457d290bf6",
"type": "problem-builder",
"id": "i4x://Org/Course/vertical/693f5d5a98b94f9481c381457d290bf6"
},
"i4x://Org/Course/problem-builder/26071191d5344d5e931c9a90a49e6192": {
"display_name": "",
"block_id": "26071191d5344d5e931c9a90a49e6192",
"children": [
"i4x://Org/Course/pb-answer/927c5b8cd051475e937b8c1091a9feaf"
],
"student_view_url": "http://example.com/xblock/i4x://Org/Course/problem-builder/26071191d5344d5e931c9a90a49e6192",
"lms_web_url": "http://example.com/courses/Org/Course/Run/jump_to/i4x://Org/Course/problem-builder/26071191d5344d5e931c9a90a49e6192",
"type": "problem-builder",
"id": "i4x://Org/Course/vertical/26071191d5344d5e931c9a90a49e6192"
},
"i4x://Org/Course/sequential/4309902bea4d4228ba1895df438c27dc": {
"display_name": "Subsection 2",
"block_id": "4309902bea4d4228ba1895df438c27dc",
Expand Down