Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add practice activity #1

Merged
merged 3 commits into from Oct 10, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions dev_start.sh
Expand Up @@ -2,11 +2,16 @@
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
reset=`tput sgr0`

# Add environment variables
source my.env

echo "${yellow}Starting siyavula_api_python_pyramid${reset}"
echo "${yellow}Go to http://localhost:6543/standalone or http://localhost:6543/assignment${reset}"
venv/bin/pserve siyavula_api_python_pyramid/development.ini --reload
echo "${green}Routes:${reset}"
echo -e "${green}\tStandalone Activity: ${reset}${blue}http://localhost:6543/standalone${reset}"
echo -e "${green}\tAssignment Activity: ${reset}${blue}http://localhost:6543/assignment${reset}"
echo -e "${green}\tPractice Activity: ${reset}${blue}http://localhost:6543/practice${reset}"
echo -e "${green}\tPractice Activity Table of Contents: ${reset}${blue}http://localhost:6543/practice-toc${reset}"
venv/bin/pserve siyavula_api_python_pyramid/development.ini --reload
Expand Up @@ -2,3 +2,5 @@ def includeme(config):
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('standalone_responsive', '/standalone')
config.add_route('assignment_responsive', '/assignment')
config.add_route('practice_responsive', '/practice')
config.add_route('practice_toc', '/practice-toc')
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<title>Siyavula API - Practice Activity</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="{{ api_base_url }}static/themes/emas/siyavula-api/siyavula-api.min.css"/>
<script type="text/javascript">
var baseUrl = '{{ api_base_url }}';
var token = '{{ token }}';
var userToken = '{{ user_token }}';
var activityType = 'practice';
var sectionId = {{ section_id }};
</script>
<style type="text/css">
.progress:before {
content:attr(data-text);
}
.progress {
height: 2.5em;
line-height: 2.5em;
text-align:center;
vertical-align: middle;
}
</style>
</head>
<body>
<main class="sv-region-main emas sv">
<span class="emphasis-bold answer">Chapter Mastery (<span id="chapter-mastery-title"></span>):</span><br>
<progress class="progress" id="chapter-mastery" value="0" max="100" data-text="0%"></progress><br>
<span class="emphasis-bold answer">Section Mastery (<span id="section-mastery-title"></span>):</span><br>
<progress class="progress" id="section-mastery" value="0" max="100" data-text="0%"></progress><br>
<br>
<div id="monassis" class="monassis monassis--practice monassis--maths monassis--siyavula-api">
<div class="question-wrapper">
<div class="question-content"></div>
</div>
</div>
</main>
</body>
<script src="{{ api_base_url }}static/themes/emas/node_modules/mathjax/MathJax.js?config=TeX-MML-AM_HTMLorMML-full"></script>
<script src="{{ api_base_url }}static/themes/emas/siyavula-api/siyavula-api.js"></script>
</html>
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Siyavula API - Practice Activity Table of Contents</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/json-path-picker@0.2.0/lib/json-path-picker.css">
<style type="text/css">
body {
padding-left: 1em;
}

.pick-path, #path {
display: none;
}
</style>
</head>
<body>
<pre id="json-renderer"></pre>
<input id="path" type="text">
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/json-path-picker@0.2.0/lib/json-path-picker.js"></script>
<script type="text/javascript">
var toc = {{ toc|tojson|safe }};
$('#json-renderer').jsonPathPicker(toc, '#path');
</script>
</html>
Expand Up @@ -84,3 +84,77 @@ def assignment_responsive(request):
'assignment_id': assignment_id,
'api_base_url': api_base_url + '/'
}


@view_config(route_name='practice_responsive', renderer='/templates/practice_responsive.jinja2')
def practice_responsive(request):
api_base_url = request.registry.settings['api_base_url']
region = 'ZA' # The country shortcode, can be either 'ZA', 'NG' or 'INTL'.
curriculum = 'CAPS' # The curriculum code, can be either 'CAPS', 'NG' or 'INTL'.
# Use 'responsive' to get a responsive theme for modern devices
# or 'basic' for older devices without JS support.
theme = 'responsive' # The theme to use, can be either 'responsive' or 'basic'.
section_id = 204 # Change this to the section you wish to practice.
# Authentication payload
data = {
'name': os.environ['api_client_name'],
'password': os.environ['api_client_password'],
'client_ip': request.client_addr,
'region': region,
'curriculum': curriculum,
'theme': theme
}

# Request client token
res = requests.post('{}/api/siyavula/v1/get-token'.format(api_base_url),
verify=False, json=data)
token = res.json()['token']

# Request user token
# Ensure you have created a user with the external id specified or this won't work.
user_id = '1'
headers = {'JWT': token}
res = requests.get('{}/api/siyavula/v1/user/{}/token'.format(api_base_url, user_id),
verify=False, json=data, headers=headers)
user_token = res.json()['token']

return {
'token': token,
'user_token': user_token,
'section_id': section_id,
'api_base_url': api_base_url + '/'
}


@view_config(route_name='practice_toc', renderer='/templates/practice_toc.jinja2')
def practice_toc(request):
api_base_url = request.registry.settings['api_base_url']
region = 'ZA' # The country shortcode, can be either 'ZA', 'NG' or 'INTL'.
curriculum = 'CAPS' # The curriculum code, can be either 'CAPS', 'NG' or 'INTL'.
# Use 'responsive' to get a responsive theme for modern devices
# or 'basic' for older devices without JS support.
theme = 'responsive' # The theme to use, can be either 'responsive' or 'basic'.
# Authentication payload
data = {
'name': os.environ['api_client_name'],
'password': os.environ['api_client_password'],
'client_ip': request.client_addr,
'region': region,
'curriculum': curriculum,
'theme': theme
}

# Request client token
res = requests.post('{}/api/siyavula/v1/get-token'.format(api_base_url),
verify=False, json=data)
token = res.json()['token']

# Get the Practice Table of Contents
headers = {'JWT': token}
res = requests.get('{}/api/siyavula/v1/toc'.format(api_base_url), verify=False,
headers=headers)
toc = res.json()

return {
'toc': toc
}
9 changes: 7 additions & 2 deletions start.sh
Expand Up @@ -2,11 +2,16 @@
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
reset=`tput sgr0`

# Add environment variables
source my.env

echo "${yellow}Starting siyavula_api_python_pyramid${reset}"
echo "${yellow}Go to http://localhost:6543/standalone or http://localhost:6543/assignment${reset}"
venv/bin/pserve siyavula_api_python_pyramid/production.ini
echo "${green}Routes:${reset}"
echo -e "${green}\tStandalone Activity: ${reset}${blue}http://localhost:6543/standalone${reset}"
echo -e "${green}\tAssignment Activity: ${reset}${blue}http://localhost:6543/assignment${reset}"
echo -e "${green}\tPractice Activity: ${reset}${blue}http://localhost:6543/practice${reset}"
echo -e "${green}\tPractice Activity Table of Contents: ${reset}${blue}http://localhost:6543/practice-toc${reset}"
venv/bin/pserve siyavula_api_python_pyramid/production.ini