def h5p_add_core_assets(): path = join_url([settings.STATIC_URL, 'h5p']) assets = {'css': list(), 'js': list()} for style in STYLES: css = join_url([path, style]) assets['css'].append(css) for script in SCRIPTS: js = join_url([path, script]) assets['js'].append(js) return assets
def h5p_get_content(request): interface = H5PDjango(request.user) # core = interface.h5pGetInstance('core') return { 'id': h5p_get_content_id(request), 'title': request.GET['title'], 'params': request.GET['json_content'], 'language': request.GET['language'], 'library': request.GET['main_library'], 'embedType': 'div', 'filtered': request.GET['filtered'], 'url': join_url([ settings.MEDIA_URL, 'h5pp/content/', str(h5p_get_content_id(request)) + '/' ]), 'displayOptions': '', 'slug': request.GET['h5p_slug'] }
def h5p_add_files_and_settings(request, embed_type): interface = H5PDjango(request.user) integration = h5p_get_core_settings(request.user) assets = h5p_add_core_assets() if 'json_content' not in request.GET or not 'contentId' in request.GET: return integration content = h5p_get_content(request) if 'contents' in integration and content['id'] in integration['contents']: return integration integration['contents'] = dict() integration['contents'][str("cid-%s" % content['id'])] = h5p_get_content_settings( request.user, content) core = interface.h5pGetInstance('core') preloaded_dependencies = core.load_content_dependencies( content['id'], 'preloaded') files = core.get_dependencies_files(preloaded_dependencies) library_list = h5p_dependencies_to_library_list(preloaded_dependencies) files_assets = {'js': list(), 'css': list()} if embed_type == 'div': for script in files['scripts']: url = join_url([settings.MEDIA_URL, 'h5pp/', script['path']]) files_assets['js'].append(url) integration['loadedJs'] = join_url([url, script['version']]) for style in files['styles']: url = join_url([settings.MEDIA_URL, 'h5pp/', style['path']]) files_assets['css'].append(url) integration['loadedCss'] = join_url([url, style['version']]) # Override CSS files_assets['css'].append(OVERRIDE_STYLES) integration['loadedCss'] = OVERRIDE_STYLES elif embed_type == 'iframe': h5p_add_iframe_assets(request, integration, content['id'], files) return { 'integration': json.dumps(integration), 'assets': assets, 'filesAssets': files_assets }
def h5p_embed(request): h5p_path = join_url([settings.STATIC_URL, 'h5p/']) # The template adds the static URL # h5pPath = 'h5p/' core_settings = h5p_get_core_settings(request.user) framework = H5PDjango(request.user) scripts = list() for script in SCRIPTS: url = join_url([h5p_path, script]) scripts.append(url) styles = list() for style in STYLES: url = join_url([h5p_path, style]) styles.append(url) integration = h5p_get_core_settings(request.user) content = h5p_get_content(request) integration['contents'] = dict() integration['contents']["cid-%s" % content['id']] = h5p_get_content_settings( request.user, content) core = framework.h5pGetInstance('core') preloaded_dependencies = core.load_content_dependencies(content['id']) files = core.get_dependencies_files(preloaded_dependencies) library_list = h5p_dependencies_to_library_list(preloaded_dependencies) scripts = scripts + core.get_assets_urls(files['scripts']) styles = styles + core.get_assets_urls(files['styles']) return { 'h5p': json.dumps(integration), 'scripts': scripts, 'styles': styles, 'lang': settings.H5P_LANGUAGE }
def h5p_get_core_settings(user): core_settings = { 'baseUrl': settings.BASE_URL, 'url': join_url([settings.MEDIA_URL, 'h5pp']), 'postUserStatistics': user.id > 0 if user.id else False, # TODO This seems to produce example.com/h5p/ajax URLs... 'ajaxPath': join_url([Site.objects.get_current().domain, settings.H5P_URL, 'ajax']), 'ajax': { 'setFinished': join_url([settings.H5P_URL, 'ajax/?setFinished']), 'contentUserData': join_url([ settings.H5P_URL, "ajax/?content-user-data&contentId=:contentId&dataType=:dataType&subContentId=:subContentId" ]), }, 'tokens': { 'result': create_token('result'), 'contentUserData': create_token('contentuserdata') }, 'saveFreq': settings.H5P_SAVE if settings.H5P_SAVE != 0 else 'false', 'l10n': { 'H5P': { 'fullscreen': 'Fullscreen', 'disableFullscreen': 'Disable fullscreen', 'download': 'Download', 'copyrights': 'Rights of use', 'embed': 'Embed', 'size': 'Size', 'showAdvanced': 'Show advanced', 'hideAdvanced': 'Hide advanced', 'advancedHelp': 'Include this script on your website' ' if you want dynamic sizing of the embedded content:', 'copyrightInformation': 'Rights of use', 'close': 'Close', 'title': 'Title', 'author': 'Author', 'year': 'Year', 'source': 'Source', 'license': 'License', 'thumbnail': 'Thumbnail', 'noCopyrights': 'No copyright information available for this content.', 'downloadDescription': 'Download this content as a H5P file.', 'copyrightsDescription': 'View copyright information for this content.', 'embedDescription': 'View the embed code for this content.', 'h5pDescription': 'Visit H5P.org to check out more cool content.', 'contentChanged': 'This content has changed since you last used it.', 'startingOver': 'You\'ll be starting over', 'by': 'by', 'showMore': 'Show more', 'showLess': 'Show less', 'subLevel': 'Sublevel', 'confirmDialogHeader': 'Confirm action', 'confirmDialogBody': 'Please confirm that you wish to proceed. This action is not reversible.', 'cancelLabel': 'Cancel', 'confirmLabel': 'Confirm' } } } if user.id: core_settings['user'] = {'name': user.username, 'mail': user.email} return core_settings
from h5pp.models import * from h5pp.h5p.h5pclasses import H5PDjango from django.core import serializers from h5pp.url_builder import join_url jsonserializer = serializers.get_serializer("json") json_serializer = jsonserializer() STYLES = [ "styles/h5p.css", "styles/h5p-confirmation-dialog.css", "styles/h5p-core-button.css" ] OVERRIDE_STYLES = join_url([settings.STATIC_URL, 'h5p/styles/h5pp.css']) SCRIPTS = [ "js/jquery.js", "js/h5p.js", "js/h5p-event-dispatcher.js", "js/h5p-x-api-event.js", "js/h5p-x-api.js", "js/h5p-content-type.js", "js/h5p-confirmation-dialog.js", "js/h5p-action-bar.js" ] ## # Get path to HML5 Package ## def h5p_get_export_path(content): # TODO Test # Converted from: return os.path.join(settings.MEDIA_ROOT, 'h5pp', 'exports',
def test_1_segment(self): self.assertEqual(join_url(['http://www.example.com']), 'http://www.example.com')
def test_1_remove_trailing_duplicate_delimiters(self): self.assertEqual(join_url(['http://www.example.com//']), 'http://www.example.com/')
def test_1_retain_delimiter(self): self.assertEqual(join_url(['http://www.example.com/']), 'http://www.example.com/')