def clean(self): if self.request.POST['h5p_type'] == 'upload': h5pfile = self.cleaned_data.get('h5p') if not h5pfile: raise forms.ValidationError( 'You need to choose a valid h5p package.') interface = H5PDjango(self.request.user) paths = handleUploadedFile(h5pfile, h5pfile.name) validator = interface.h5pGetInstance( 'validator', paths['folderPath'], paths['path']) if not validator.isValidPackage(False, False): raise forms.ValidationError( 'The uploaded file was not a valid h5p package.') #self.request.POST['h5p_upload'] = paths['path'] #self.request.POST['h5p_upload_folder'] = paths['folderPath'] if not h5pInsert(self.request, interface): raise forms.ValidationError('Error during saving the content.') else: interface = H5PDjango(self.request.user) core = interface.h5pGetInstance('core') content = dict() content['disable'] = 0 libraryData = core.libraryFromString( self.request.POST['h5p_library']) if not libraryData: raise forms.ValidationError( 'You must choose an H5P content type or upload an H5P file.') else: content['library'] = libraryData runnable = h5p_libraries.objects.filter(machine_name=libraryData['machineName'], major_version=libraryData[ 'majorVersion'], minor_version=libraryData['minorVersion']).values('runnable') if not len(runnable) > 0 and runnable[0]['runnable'] == 0: raise forms.ValidationError('Invalid H5P content type') content['library']['libraryId'] = core.h5pF.getLibraryId(content['library'][ 'machineName'], content['library']['majorVersion'], content['library']['minorVersion']) if not content['library']['libraryId']: raise forms.ValidationError('No such library') content['title'] = self.request.POST['title'] content['params'] = self.request.POST['json_content'] content['author'] = self.request.user.username params = json.loads(content['params']) if 'contentId' in self.request.POST: content['id'] = self.request.POST['contentId'] content['id'] = core.saveContent(content) if not createContent(self.request, content, params): raise forms.ValidationError( 'Impossible to create the content') return content['id'] return self.cleaned_data
def editorAjax(request, contentId): data = None if request.method == 'POST': if 'libraries' in request.GET: framework = H5PDjango(request.user) editor = framework.h5pGetInstance('editor') data = editor.getLibraries(request) return HttpResponse( data, content_type='application/json' ) elif 'file' in request.FILES: framework = H5PDjango(request.user) f = H5PEditorFile(request, request.FILES, framework) if not f.isLoaded(): return HttpResponse( 'File Not Found', content_type='application/json' ) if f.validate(): core = framework.h5pGetInstance('core') fileId = core.fs.saveFile(f, request.POST['contentId']) data = f.printResult() return HttpResponse( data, content_type='application/json' ) return HttpResponseRedirect('h5p/') if 'libraries' in request.GET: name = request.GET[ 'machineName'] if 'machineName' in request.GET else '' major = request.GET[ 'majorVersion'] if 'majorVersion' in request.GET else 0 minor = request.GET[ 'minorVersion'] if 'minorVersion' in request.GET else 0 framework = H5PDjango(request.user) editor = framework.h5pGetInstance('editor') if name != '': data = editor.getLibraryData( name, major, minor, settings.H5P_LANGUAGE) return HttpResponse( data, content_type='application/json' ) else: data = editor.getLibraries(request) return HttpResponse( data, content_type='application/json' ) return HttpResponse( data, content_type='application/json' )
def test_save_library_data(self): user = User.objects.get(username='******') interface = H5PDjango(user) libraryData = { 'title': 'Test2', 'majorVersion': 1, 'minorVersion': 1, 'patchVersion': 2, 'runnable': 1, 'machineName': 'H5P.Test2', 'author': 'drclockwork', 'license': 'MIT', 'coreApi': { 'majorVersion': 1, 'minorVersion': 6 }, 'preloadedJs': [{ 'path': 'js/test.js' }], 'preloadedCss': [{ 'path': 'css/test.css' }], } interface.saveLibraryData(libraryData) result = h5p_libraries.objects.filter(library_id=2).values() self.assertTrue(result[0]['machine_name'] == 'H5P.Test2') libraryData['title'] = 'Test3' libraryData['libraryId'] = 2 interface.saveLibraryData(libraryData, False) result = h5p_libraries.objects.filter(library_id=2).values() self.assertTrue(result[0]['title'] == 'Test3') print('test_save_library_data ---- Check')
def h5pGetContentSettings(user, content): interface = H5PDjango(user) core = interface.h5pGetInstance('core') filtered = core.filterParameters(content) # Get preloaded user data results = h5p_content_user_data.objects.filter(user_id=user.id, content_main_id=content[ 'id'], preloaded=1).values('sub_content_id', 'data_id', 'data') contentUserData = { 0: { 'state': '{}' } } for result in results: contentUserData[result['sub_content_id']][ result['data_id']] = result['data'] contentSettings = { 'library': libraryToString(content['library']), 'jsonContent': filtered, 'fullScreen': content['library']['fullscreen'], 'exportUrl': h5pGetExportPath(content), 'embedCode': str('<iframe src="' + settings.BASE_URL + settings.H5P_URL + 'embed/' + str(content['id']) + '" width=":w" height=":h" frameborder="0" allowFullscreen="allowfullscreen"></iframe>'), 'mainId': content['id'], 'url': str(content['url']), 'title': str(content['title'].encode('utf-8')), 'contentUserData': contentUserData, 'displayOptions': content['displayOptions'] } return contentSettings
def createView(request, contentId=None): if request.user.is_authenticated: editor = h5peditorContent(request, contentId) if request.method == 'POST': if contentId != None: request.POST['contentId'] = contentId form = CreateForm(request, request.POST, request.FILES) if form.is_valid(): if contentId != None: return HttpResponseRedirect('/h5p/content/?contentId=' + contentId) else: newId = h5p_contents.objects.all( ).order_by('-content_id')[0] return HttpResponseRedirect('/h5p/content/?contentId=' + str(newId.content_id)) return render(request, 'h5p/create.html', {'form': form, 'data': editor}) elif contentId != None: framework = H5PDjango(request.user) edit = framework.loadContent(contentId) request.GET = request.GET.copy() request.GET['contentId'] = contentId request.GET['json_content'] = edit['params'] request.GET['h5p_library'] = edit['library_name'] + ' ' + \ str(edit['library_major_version']) + '.' + \ str(edit['library_minor_version']) form = CreateForm(request) return render(request, 'h5p/create.html', {'form': form, 'data': editor}) return HttpResponseRedirect('/h5p/login/?next=/h5p/create/')
def test_load_library(self): user = User.objects.get(username='******') interface = H5PDjango(user) library2 = h5p_libraries.objects.create( library_id='2', machine_name='H5P.Test2', title='Test2', major_version=1, minor_version=1, patch_version=0, runnable=1, fullscreen=0, embed_types='', preloaded_js="[u'scripts/test2.js']", preloaded_css="[u'styles/test2.css']", drop_library_css=None, semantics='', restricted=0, tutorial_url='') librarylibrary = h5p_libraries_libraries.objects.create( library_id=1, required_library_id=2, dependency_type='preloaded') self.assertFalse(interface.loadLibrary('H5P.Test3', 1, 1)) result = interface.loadLibrary('H5P.Test', 1, 1) self.assertTrue(len(result) > 0) self.assertTrue( result['preloadedDependencies'][0]['machineName'] == 'H5P.Test2') print('test_load_library ---- Check')
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 test_update_content(self): user = User.objects.get(username='******') interface = H5PDjango(user) content = { 'id': 1, 'title': 'ContentTest', 'params': '', 'library': { 'libraryId': 1, 'machineName': 'H5P.Test', 'majorVersion': 1, 'minorVersion': 1 }, 'disable': 0, } interface.updateContent(content) result = h5p_contents.objects.filter(content_id=1).values() self.assertTrue(result.exists()) content['title'] = 'ContentTest2' content['h5p_library'] = 'H5P.Test 1.12' del (content['library']['machineName']) del (content['library']['majorVersion']) del (content['library']['minorVersion']) interface.updateContent(content) result = h5p_contents.objects.filter(content_id=1).values() self.assertTrue(result[0]['title'] == 'ContentTest2') self.assertTrue(content['library']['machineName'] == 'H5P.Test') self.assertTrue(content['library']['majorVersion'] == '1' and content['library']['minorVersion'] == '12') print('test_update_content ---- Check')
def test_load_content(self): user = User.objects.get(username='******') interface = H5PDjango(user) core = interface.h5pGetInstance('core') content = { 'id': 1, 'title': 'ContentTest', 'params': '', 'library': { 'libraryId': 1, 'machineName': 'H5P.Test', 'majorVersion': 1, 'minorVersion': 1 }, 'disable': 0, } interface.insertContent(content) result = core.load_content(1) self.assertTrue(result['library']['contentId'] == 1) self.assertTrue(result['library']['id'] == 1) self.assertTrue(result['library']['name'] == 'H5P.Test') self.assertFalse('library_id' in result) print('test_load_content ---- Check')
def test_save_content(self): user = User.objects.get(username='******') interface = H5PDjango(user) core = interface.h5pGetInstance('core') content = { 'id': 1, 'title': 'ContentTest', 'params': '', 'library': { 'libraryId': 1, 'machineName': 'H5P.Test', 'majorVersion': 1, 'minorVersion': 1 }, 'disable': 0, } core.save_content(content) result = h5p_contents.objects.values() self.assertTrue(result.exists()) del (content['id']) content['title'] = 'ContentTest2' core.save_content(content) result = list(h5p_contents.objects.values()) self.assertTrue(result[1]['title'] == 'ContentTest2') print('test_save_content ---- Check')
def h5pGetContent(request): interface = H5PDjango(request.user) core = interface.h5pGetInstance('core') return { 'id': h5pGetContentId(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': settings.BASE_URL + settings.MEDIA_URL + 'h5pp/content/' + h5pGetContentId(request), 'displayOptions': '', 'slug': request.GET['h5p_slug'] }
def test_is_patched_library(self): user = User.objects.get(username='******') interface = H5PDjango(user) library = { 'machineName': 'H5P.Test', 'majorVersion': 1, 'minorVersion': 1, 'patchVersion': 2 } self.assertFalse(interface.isPatchedLibrary(library)) h5p_libraries.objects.create(library_id='2', machine_name='H5P.Test', title='Test', major_version=1, minor_version=1, patch_version=1, runnable=1, fullscreen=0, embed_types='', preloaded_js="[u'scripts/test.js']", preloaded_css="[u'styles/test.css']", drop_library_css=None, semantics='', restricted=0, tutorial_url='') self.assertTrue(interface.isPatchedLibrary(library)) print('test_is_patched_library ---- Check')
def h5pEmbed(request): h5pPath = settings.STATIC_URL + 'h5p/' coreSettings = h5pGetCoreSettings(request.user) framework = H5PDjango(request.user) scripts = list() for script in SCRIPTS: scripts.append(h5pPath + script) styles = list() for style in STYLES: styles.append(h5pPath + style) integration = h5pGetCoreSettings(request.user) content = h5pGetContent(request) integration['contents'] = dict() integration['contents']['cid-' + content['id']] = h5pGetContentSettings( request.user, content) core = framework.h5pGetInstance('core') preloadedDependencies = core.loadContentDependencies(content['id']) files = core.getDependenciesFiles(preloadedDependencies) libraryList = h5pDependenciesToLibraryList(preloadedDependencies) scripts = scripts + core.getAssetsUrls(files['scripts']) styles = styles + core.getAssetsUrls(files['styles']) return { 'h5p': json.dumps(integration), 'scripts': scripts, 'styles': styles, 'lang': settings.H5P_LANGUAGE }
def h5peditorContent(request, contentId=None): assets = h5pAddCoreAssets() coreAssets = h5pAddCoreAssets() editor = h5pAddFilesAndSettings(request, True) framework = H5PDjango(request.user) add = list() for style in STYLES: css = settings.STATIC_URL + 'h5p/h5peditor/' + style assets['css'].append(css) #Override Css assets['css'].append(OVERRIDE_STYLES) for script in SCRIPTS: if script != 'scripts/h5peditor-editor.js': js = settings.STATIC_URL + 'h5p/h5peditor/' + script assets['js'].append(js) add.append(settings.STATIC_URL + 'h5p/h5peditor/scripts/h5peditor-editor.js') add.append(settings.STATIC_URL + 'h5p/h5peditor/application.js') languageFile = settings.STATIC_URL + \ 'h5p/h5peditor/language/' + settings.H5P_LANGUAGE + '.js' if not os.path.exists(settings.BASE_DIR + languageFile): languageFile = settings.STATIC_URL + 'h5p/h5peditor/language/en.js' add.append(languageFile) contentValidator = framework.h5pGetInstance('contentvalidator') editor['editor'] = { 'filesPath': os.path.join(settings.MEDIA_URL, 'h5pp', 'editor'), 'fileIcon': { 'path': settings.BASE_URL + settings.STATIC_URL + 'h5p/h5peditor/images/binary-file.png', 'width': 50, 'height': 50 }, 'ajaxPath': settings.BASE_URL + settings.H5P_URL + 'editorajax/' + (request['contentId'] if 'contentId' in request else '0') + '/', 'libraryPath': settings.BASE_URL + settings.STATIC_URL + 'h5p/h5peditor/', 'copyrightSemantics': contentValidator.getCopyrightSemantics(), 'assets': assets, 'contentRelUrl': '../media/h5pp/content/' } return { 'editor': json.dumps(editor), 'coreAssets': coreAssets, 'assets': assets, 'add': add }
def h5pAddIframeAssets(request, integration, contentId, files): framework = H5PDjango(request.user) core = framework.h5pGetInstance('core') assets = h5pAddCoreAssets() integration['core'] = dict() integration['core']['scripts'] = assets['js'] integration['core']['styles'] = assets['css'] writable = os.path.exists(settings.H5P_PATH) # Temp writable = False if writable: if not os.path.exists(os.path.join(settings.H5P_PATH, 'files')): os.mkdir(os.path.join(settings.H5P_PATH, 'files')) styles = list() externalStyles = list() for style in files['styles']: if h5pIsExternalAsset(style['path']): externalStyles.append(style) else: styles.append({'data': style['path'], 'type': 'file'}) integration['contents'][ 'cid-' + contentId]['styles'] = core.getAssetsUrls(externalStyles) integration['contents']['cid-' + contentId]['styles'].append(styles) else: integration['contents']['cid-' + contentId]['styles'] = core.getAssetsUrls( files['styles']) #Override Css integration['contents']['cid-' + contentId]['styles'].append(OVERRIDE_STYLES) if writable: if not os.path.exists(os.path.join(settings.H5P_PATH, 'files')): os.mkdir(os.path.join(settings.H5P_PATH, 'files')) scripts = dict() externalScripts = dict() for script in files['scripts']: if h5pIsExternalAsset(script['path']): externalScripts.append(script) else: scripts[script['path']] = list() scripts[script['path']].append({ 'data': script['path'], 'type': 'file', 'preprocess': True }) integration['contents']['cid-' + contentId]['scripts'] = core.getAssetsUrls( externalScripts) integration['contents']['cid-' + contentId]['scripts'].append(scripts) else: integration['contents']['cid-' + contentId]['scripts'] = core.getAssetsUrls( files['scripts'])
def test_load_library(self): user = User.objects.get(username='******') interface = H5PDjango(user) core = interface.h5pGetInstance('core') result = core.load_library('H5P.Test', 1, 1) self.assertEqual(1, result['library_id']) print('test_load_library ---- Check')
def test_get_platform_info(self): user = User.objects.get(username='******') interface = H5PDjango(user) info = { 'name': 'django', 'version': django.get_version(), 'h5pVersion': '7.x' } self.assertEqual(info, interface.getPlatformInfo()) print('test_get_platform_info --- Check')
def h5pDeleteH5PContent(request, content): framework = H5PDjango(request.user) storage = framework.h5pGetInstance('storage') storage.deletePackage(content) # Remove content points h5p_points.objects.filter(content_id=content.content_id).delete() # Remove content user data h5p_content_user_data.objects.filter( content_main_id=content.content_id).delete()
def test_get_library_id(self): user = User.objects.get(username='******') interface = H5PDjango(user) self.assertEqual(1, interface.getLibraryId('H5P.Test')) self.assertEqual(1, interface.getLibraryId('H5P.Test', 1, 1)) h5p_libraries.objects.filter(library_id=1).delete() self.assertTrue(interface.getLibraryId('H5P.Test') == None) print('test_get_library_id ---- Check')
def h5pGetListContent(request): interface = H5PDjango(request.user) contents = interface.getNumContentPlus() if contents > 0: result = list() for content in interface.loadAllContents(): load = interface.loadContent(content['content_id']) load['score'] = getUserScore(content['content_id']) result.append(load) return result else: return 0
def createContent(request, content, params): framework = H5PDjango(request.user) editor = framework.h5pGetInstance('editor') contentId = content['id'] if not editor.createDirectories(contentId): print(('Unable to create content directory.', 'error')) return False editor.processParameters(contentId, content['library'], params) return True
def test_load_libraries(self): user = User.objects.get(username='******') interface = H5PDjango(user) self.assertTrue(len(interface.loadLibraries()) > 0) self.assertTrue('H5P.Test' in interface.loadLibraries()) h5p_libraries.objects.filter(library_id=1).delete() self.assertFalse(len(interface.loadLibraries()) > 0) self.assertEqual('', interface.loadLibraries()) print('test_load_libraries ---- Check')
def h5p_add_iframe_assets(request, integration, content_id, files): framework = H5PDjango(request.user) core = framework.h5pGetInstance('core') assets = h5p_add_core_assets() integration['core'] = dict() integration['core']['scripts'] = assets['js'] integration['core']['styles'] = assets['css'] writable = False # Temporary, future feature if writable: pass # if not os.path.exists(os.path.join(settings.H5P_PATH, 'files')): # os.mkdir(os.path.join(settings.H5P_PATH, 'files')) # # styles = list() # externalStyles = list() # for style in files['styles']: # if h5p_is_external_asset(style['path']): # externalStyles.append(style) # else: # styles.append({'data': style['path'], 'type': 'file'}) # integration['contents']['cid-' + content_id]['styles'] = core.get_assets_urls(externalStyles) # integration['contents']['cid-' + content_id]['styles'].append(styles) else: integration['contents']['cid-' + content_id]['styles'] = core.get_assets_urls( files['styles']) # Override Css integration['contents']['cid-' + content_id]['styles'].append(OVERRIDE_STYLES) if writable: pass # if not os.path.exists(os.path.join(settings.H5P_PATH, 'files')): # os.mkdir(os.path.join(settings.H5P_PATH, 'files')) # # scripts = dict() # externalScripts = dict() # for script in files['scripts']: # if h5p_is_external_asset(script['path']): # externalScripts.append(script) # else: # scripts[script['path']] = list() # scripts[script['path']].append({'data': script['path'], 'type': 'file', 'preprocess': True}) # integration['contents']['cid-' + content_id]['scripts'] = core.get_assets_urls(externalScripts) # integration['contents']['cid-' + content_id]['scripts'].append(scripts) else: integration['contents']['cid-' + content_id]['scripts'] = core.get_assets_urls( files['scripts'])
def clean(self): h5pfile = self.cleaned_data.get('h5p') down = self.cleaned_data.get('download') unins = self.cleaned_data.get('uninstall') if h5pfile != None: if down != False or unins != False: raise forms.ValidationError( 'Too many choices selected.') interface = H5PDjango(self.user) paths = handleUploadedFile(h5pfile, h5pfile.name) validator = interface.h5pGetInstance( 'validator', paths['folderPath'], paths['path']) if not validator.isValidPackage(True, False): raise forms.ValidationError( 'The uploaded file was not a valid h5p package.') storage = interface.h5pGetInstance('storage') if not storage.savePackage(None, None, True): raise forms.ValidationError('Error during library save.') elif down != False: if unins != False: raise forms.ValidationError( 'Too many choices selected.') libraries = h5p_libraries.objects.values() if not len(libraries) > 0: raise forms.ValidationError( 'You cannot update libraries when you don\'t have libraries installed !.') interface = H5PDjango(self.user) interface.updateTutorial() elif unins == False: raise forms.ValidationError( 'No actions selected.') return self.cleaned_data
def h5pAddFilesAndSettings(request, embedType): interface = H5PDjango(request.user) integration = h5pGetCoreSettings(request.user) assets = h5pAddCoreAssets() if not 'json_content' in request.GET or not 'contentId' in request.GET: return integration content = h5pGetContent(request) if 'contents' in integration and content['id'] in integration['contents']: return integration integration['contents'] = dict() integration['contents'][str('cid-' + content['id'])] = h5pGetContentSettings( request.user, content) core = interface.h5pGetInstance('core') preloadedDependencies = core.loadContentDependencies(content['id']) files = core.getDependenciesFiles(preloadedDependencies) libraryList = h5pDependenciesToLibraryList(preloadedDependencies) filesAssets = {'js': list(), 'css': list()} if embedType == 'div': for script in files['scripts']: url = settings.MEDIA_URL + 'h5pp/' + \ script['path'] + script['version'] filesAssets['js'].append(settings.MEDIA_URL + 'h5pp/' + script['path']) integration['loadedJs'] = url for style in files['styles']: url = settings.MEDIA_URL + 'h5pp/' + \ style['path'] + style['version'] filesAssets['css'].append(settings.MEDIA_URL + 'h5pp/' + style['path']) integration['loadedCss'] = url #Override CSS filesAssets['css'].append(OVERRIDE_STYLES) integration['loadedCss'] = OVERRIDE_STYLES elif embedType == 'iframe': h5pAddIframeAssets(request, integration, content['id'], files) return { 'integration': json.dumps(integration), 'assets': assets, 'filesAssets': filesAssets }
def h5pLoad(request): interface = H5PDjango(request.user) core = interface.h5pGetInstance('core') content = core.loadContent(h5pGetContentId(request)) if content != None: request.GET = request.GET.copy() request.GET['json_content'] = content['params'] request.GET['title'] = content['title'] request.GET['language'] = 'en' request.GET['main_library_id'] = content['library']['id'] request.GET['embed_type'] = content['embed_type'] request.GET['main_library'] = content['library'] request.GET['filtered'] = content['filtered'] request.GET['disable'] = content['disable'] request.GET['h5p_slug'] = content['slug']
def test_create_directories(self): user = User.objects.get(username='******') interface = H5PDjango(user) editor = interface.h5pGetInstance('editor') editor.createDirectories(1) self.assertTrue(os.path.exists('/home/pod/H5PP/media/h5pp/content/1/')) self.assertTrue( os.path.exists('/home/pod/H5PP/media/h5pp/content/1/audios/')) self.assertTrue( os.path.exists('/home/pod/H5PP/media/h5pp/content/1/files/')) self.assertTrue( os.path.exists('/home/pod/H5PP/media/h5pp/content/1/images/')) self.assertTrue( os.path.exists('/home/pod/H5PP/media/h5pp/content/1/videos/')) print('test_create_directories ---- Check')
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 test_get_instance(self): user = User.objects.get(username='******') interface = H5PDjango(user) self.assertTrue(isinstance( interface.h5pGetInstance('validator'), H5PValidator)) self.assertTrue(isinstance( interface.h5pGetInstance('storage'), H5PStorage)) self.assertTrue(isinstance(interface.h5pGetInstance( 'contentvalidator'), H5PContentValidator)) self.assertTrue(isinstance( interface.h5pGetInstance('export'), H5PExport)) self.assertTrue(isinstance( interface.h5pGetInstance('interface'), H5PDjango)) self.assertTrue(isinstance(interface.h5pGetInstance('core'), H5PCore)) self.assertTrue(isinstance( interface.h5pGetInstance('editor'), H5PDjangoEditor)) print('test_get_instance ---- Check')
def test_insert_content(self): user = User.objects.get(username='******') interface = H5PDjango(user) content = { 'title': 'ContentTest', 'params': '', 'library': { 'libraryId': 1, 'machineName': 'H5P.Test', 'majorVersion': 1, 'minorVersion': 1 }, 'disable': 0, } self.assertEqual(1, interface.insertContent(content)) self.assertTrue(len(h5p_contents.objects.values()) > 0) print('test_insert_content ---- Check')