Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ensure_csrf_cookie
- def show_scenario(request, scenario_id, view_name='student_view', template='workbench/block.html'):
- """
- Render the given `scenario_id` for the given `view_name`, on the provided `template`.
- `view_name` defaults to 'student_view'.
- `template` defaults to 'block.html'.
- """
- if scenario_id == 'drivepy.0':
- scen_id = 'drivepy.0'
- elif scenario_id == 'drivepy.1':
- scen_id = 'drivepy.1'
- else:
- scen_id = ''
- if scenario_id == scen_id:
- if 'credentials' not in request.session:
- return redirect('http://drivepython.10.0.2.186.xip.io:8020/oauth2callback')
- credentials = client.OAuth2Credentials.from_json(request.session['credentials'])
- if credentials.access_token_expired:
- return redirect('http://drivepython.10.0.2.186.xip.io:8020/oauth2callback')
- else:
- http_auth = credentials.authorize(httplib2.Http())
- drive_service = discovery.build('drive', 'v3', http_auth)
- files = drive_service.files().list(q="'root' in parents",fields="nextPageToken, files(id, name, mimeType, trashed, webViewLink, fileExtension)").execute()
- items = files.get('files', [])
- student_id = get_student_id(request)
- log.info("Start show_scenario %r for student %s", scenario_id, student_id)
- try:
- scenario = get_scenarios()[scenario_id]
- except KeyError:
- raise Http404
- usage_id = scenario.usage_id
- runtime = WorkbenchRuntime(student_id)
- block = runtime.get_block(usage_id)
- render_context = {
- 'activate_block_id': request.GET.get('activate_block_id', None),
- 'files': items
- }
- frag = block.render(view_name, render_context)
- log.info("End show_scenario %s", scenario_id)
- return render_to_response('drivepy/drivepy.html', {
- 'scenario': scenario,
- 'block': block,
- 'body': frag.body_html(),
- 'head_html': frag.head_html(),
- 'foot_html': frag.foot_html(),
- 'student_id': student_id,
- 'files': items
- })
- else:
- student_id = get_student_id(request)
- log.info("Start show_scenario %r for student %s", scenario_id, student_id)
- try:
- scenario = get_scenarios()[scenario_id]
- except KeyError:
- raise Http404
- usage_id = scenario.usage_id
- runtime = WorkbenchRuntime(student_id)
- block = runtime.get_block(usage_id)
- render_context = {
- 'activate_block_id': request.GET.get('activate_block_id', None)
- }
- frag = block.render(view_name, render_context)
- log.info("End show_scenario %s", scenario_id)
- return render_to_response(template, {
- 'scenario': scenario,
- 'block': block,
- 'body': frag.body_html(),
- 'head_html': frag.head_html(),
- 'foot_html': frag.foot_html(),
- 'student_id': student_id
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement