Skip to content

Commit

Permalink
fix: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
Talha-Rizwan committed Jan 3, 2024
1 parent 3660dae commit 7f0e5cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions openedx_cmi5_xblock/openedx_cmi5_xblock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Openedx CMI5 XBlock implementation."""

import copy
import hashlib
import json
import logging
Expand All @@ -8,7 +9,6 @@
import uuid
import xml.etree.ElementTree as ET
import zipfile
import copy

import pkg_resources
import requests
Expand Down Expand Up @@ -166,6 +166,7 @@ def student_view(self, context=None):
"""The primary view of the CMI5XBlock, shown to students when viewing courses."""
student_context = {
'title': self.display_name,
'index_page_url': self.index_page_url,
'au_urls': self.launch_all_au_urls,
'cmi5_xblock': self,
}
Expand Down Expand Up @@ -270,8 +271,9 @@ def studio_submit(self, request, _suffix):

@property
def launch_all_au_urls(self):
"""Gets the URLs of all the cmi5 AUs."""
temp_au_list = copy.deepcopy(self.au_urls)

for au in temp_au_list:
au['url'] = self.launch_au_url(au['url'])

Expand All @@ -285,6 +287,19 @@ def launch_au_url(self, url):
lms_cmi5_url = self.make_launch_url(url)
return lms_cmi5_url

@property
def index_page_url(self):
"""
Gets the URL of the CMI5 index page.
Returns an empty string if the package metadata or index page path is not available.
"""
if not self.package_meta or not self.index_page_path:
return ''

lms_cmi5_url = self.make_launch_url(self.index_page_path)
return lms_cmi5_url

def make_launch_url(self, url):
"""Make the launch url for the AUs of cmi5."""
if is_url(url):
Expand Down
4 changes: 2 additions & 2 deletions openedx_cmi5_xblock/static/html/openedx_cmi5_xblock.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<h3 class="xblock-title mb-2">{{title}}</h3>
<br>

{% if au_urls %}
{% if index_page_url %}
<h5 class="xblock-title mb-2"> {% trans "Available Assignables:" %}</h5>
<ol>
{% for au_url in au_urls %}
<li>
<a href="{{ au_url.url }}">
<a href="{{ au_url.url }}" target="_blank">
<span>{% trans "AU No." %}</span> {{ forloop.counter }}
</a>
({%trans "Launch: "%} {{au_url.launch_method}})
Expand Down

0 comments on commit 7f0e5cd

Please sign in to comment.