def updateContent(self, content, contentMainId=None): contentId = h5p_contents.objects.filter( content_id=content['id']).values('content_id') if not contentId.exists(): self.insertContent(content, contentMainId) return # Update content update = h5p_contents.objects.get(content_id=contentId) update.title = content['title'] update.author = content['author'] update.json_contents = content['params'] update.embed_type = 'div' update.main_library_id = content['library']['libraryId'] update.filtered = '' update.disable = content['disable'] update.slug = slugify(content['title']) update.community_id = content['community_id'] update.community_name = content['community_name'] update.save() # Derive library data from string if 'h5p_library' in content: libraryData = content['h5p_library'].split(' ') content['library']['machineName'] = libraryData[0] content['machineName'] = libraryData[0] libraryVersions = libraryData[1].split('.') content['library']['majorVersion'] = libraryVersions[0] content['library']['minorVersion'] = libraryVersions[1] # Log update event event = H5PEvent('content', 'update', content['id'], content['title'], content['library'][ 'machineName'], str(content['library']['majorVersion']) + '.' + str(content['library']['minorVersion']))
def saveLibraryData(self, libraryData, new=True): print("\n\n\nLIBRARY DATA: ", libraryData) preloadedJs = self.pathsToCsv(libraryData, 'preloadedJs') preloadedCss = self.pathsToCsv(libraryData, 'preloadedCss') dropLibraryCss = '' if 'dropLibraryCss' in libraryData: for lib in libraryData['dropLibraryCss']: libs.append(lib['machineName']) dropLibraryCss = libs.split(', ') embedTypes = '' if 'embedTypes' in libraryData: embedTypes = libraryData['embedTypes'] if not 'semantics' in libraryData: libraryData['semantics'] = '' if not 'fullscreen' in libraryData: libraryData['fullscreen'] = 0 if new: libraryId = h5p_libraries.objects.create( machine_name=libraryData['machineName'], title=libraryData['title'], major_version=libraryData['majorVersion'], minor_version=libraryData['minorVersion'], patch_version=libraryData['patchVersion'], runnable=libraryData['runnable'], fullscreen=libraryData['fullscreen'], embed_types=embedTypes, preloaded_js=preloadedJs, preloaded_css=preloadedCss, drop_library_css=dropLibraryCss, semantics=libraryData['semantics']) libraryData['libraryId'] = libraryId.library_id else: library = h5p_libraries.objects.get( library_id=libraryData['libraryId']) library.title = libraryData['title'] library.patch_version = libraryData['patchVersion'] library.runnable = libraryData['runnable'] library.fullscreen = libraryData['fullscreen'] library.embed_types = embedTypes library.preloaded_js = preloadedJs library.preloaded_css = preloadedCss library.drop_library_css = dropLibraryCss library.semantics = libraryData['semantics'] library.save() self.deleteLibraryDependencies(libraryData['libraryId']) # Log library, installed or updated event = H5PEvent(self.user, 'library', ('create' if new else 'update'), None, None, libraryData[ 'machineName'], str(libraryData['majorVersion']) + '.' + str(libraryData['minorVersion'])) h5p_libraries_languages.objects.filter( library_id=libraryData['libraryId']).delete() if 'language' in libraryData: for languageCode, languageJson in libraryData['language'].items(): pid = h5p_libraries_languages.objects.create(library_id=libraryData[ 'libraryId'], language_code=languageCode, language_json=languageJson)
def insertContent(self, content, contentMainId=None): # Insert result = h5p_contents.objects.create( title=content['title'], json_contents=content['params'], embed_type='div', content_type=content['library']['machineName'], main_library_id=content['library']['libraryId'], author=content['author'], disable=content['disable'], filtered='', slug=slugify(content['title'])) event = H5PEvent('content', 'create', result.content_id, content['title'] if 'title' in content else '', content[ 'library']['machineName'], str(content['library']['majorVersion']) + '.' + str(content['library']['minorVersion'])) return result.content_id