def convertToFreeText(self): """ Actually do the Converting of ImageWithTextIdevice -> FreeTextIdevice, now that FreeText can hold embeddded images. """ new_content = "" imageResource_exists = False if self.image.imageResource: self.image.imageResource.checksumCheck() if os.path.exists(self.image.imageResource.path) and \ os.path.isfile(self.image.imageResource.path): imageResource_exists = True else: log.warn("Couldn't find ImageWithText image when upgrading "\ + self.image.imageResource.storageName) if imageResource_exists: new_content += "<img src=\"resources/" \ + self.image.imageResource.storageName + "\" " if self.image.height: new_content += "height=\"" + self.image.height + "\" " if self.image.width: new_content += "width=\"" + self.image.width + "\" " new_content += "/> \n" elif self.image.imageResource: new_content += "<BR>\n[WARNING: missing image: " \ + self.image.imageResource.storageName + "]\n" if self.caption != "": new_content += "<BR>\n[" + self.caption + "]\n" if self.text.content != "": new_content += "<P>\n" + self.text.content + "\n" replacementIdev = FreeTextIdevice(new_content) replacementIdev.content.content_wo_resourcePaths = \ replacementIdev.content.MassageContentForRenderView( \ replacementIdev.content.content_w_resourcePaths) self.parentNode.addIdevice(replacementIdev) replacementIdev.content.setParentNode() if imageResource_exists: from exe.engine.galleryidevice import GalleryImage full_image_path = self.image.imageResource.path new_GalleryImage = GalleryImage(replacementIdev.content, \ self.caption, full_image_path, mkThumbnail=False) while ( self.parentNode.idevices.index(replacementIdev) \ > ( (self.parentNode.idevices.index(self) + 1))): replacementIdev.movePrev() self.delete()
def prepareTestPackage(self): idevice = FreeTextIdevice() #idevice.setParentNode(self.package.root) self.package.root.addIdevice(idevice) img = Path('testing/oliver.jpg') resource = Resource(idevice, img) idevice.content.content = '<p><img src=\"resources/oliver.jpg\"/></p>' idevice.content.content_w_resourcePaths = idevice.content.content assert img.md5 in self.package.resources assert resource in idevice.userResources return (resource, img, idevice)
def convertToFreeText(self): """ Actually do the Converting of ImageWithTextIdevice -> FreeTextIdevice, now that FreeText can hold embeddded images. """ new_content = "" # ensure that an image resource still exists on this ImageWithText, # before trying to add it into the FreeText idevice. # Why? corrupt packages have been seen missing resources... # (usually in with extra package objects as well, probably # from old code doing faulty Extracts, or somesuch nonesense) imageResource_exists = False if self.image.imageResource: # also ensure that it has the correct md5 checksum, since there was # a period in which resource checksums were being created before # the resource zip file was fully closed, and not flushed out: self.image.imageResource.checksumCheck() if os.path.exists(self.image.imageResource.path) and \ os.path.isfile(self.image.imageResource.path): imageResource_exists = True else: log.warn("Couldn't find ImageWithText image when upgrading "\ + self.image.imageResource.storageName) if imageResource_exists: new_content += "<img src=\"resources/" \ + self.image.imageResource.storageName + "\" " if self.image.height: new_content += "height=\"" + self.image.height + "\" " if self.image.width: new_content += "width=\"" + self.image.width + "\" " new_content += "/> \n" elif self.image.imageResource: new_content += "<BR>\n[WARNING: missing image: " \ + self.image.imageResource.storageName + "]\n" if self.caption != "": new_content += "<BR>\n[" + self.caption + "]\n" if self.text.content != "": new_content += "<P>\n" + self.text.content + "\n" # note: this is given a text field which itself did NOT yet have # any embedded media! easier, eh? replacementIdev = FreeTextIdevice(new_content) ########### # now, copy that content field's content into its _w_resourcePaths, # and properly remove the resource directory via Massage.... # for its _wo_resourcePaths: # note that replacementIdev's content field's content # is automatically set at its constructor (above), # as is the default content_w_resourcePaths (a copy of content) # AND the default content_wo_resourcePaths (a copy of content), # so only need to update the content_wo_resourcePaths: replacementIdev.content.content_wo_resourcePaths = \ replacementIdev.content.MassageContentForRenderView( \ replacementIdev.content.content_w_resourcePaths) # Design note: ahhhhh, the above is a good looking reason to possibly # have the MassageContentForRenderView() method # just assume its content_w_resourcePaths as the input # and write the output to its content_wo_resourcePaths..... ####### # next step, add the new IDevice into the same node as this one self.parentNode.addIdevice(replacementIdev) # in passing GalleryImage into the FieldWithResources, # that content field needs to be sure to have an updated # parentNode, courtesy of its idevice: replacementIdev.content.setParentNode() # and semi-manually add/create the current image # resource into the FreeTextIdevice's TextAreaField, content. # the content text will have already been taken care of above, # including the ideal <img src=...> including resources path, # but still need the actual image resource: if imageResource_exists: # Not sure why this can't be imported up top, but it gives # ImportError: cannot import name GalleryImages, # so here it be: from exe.engine.galleryidevice import GalleryImage full_image_path = self.image.imageResource.path new_GalleryImage = GalleryImage(replacementIdev.content, \ self.caption, full_image_path, mkThumbnail=False) # and move it up to the position following this node! while ( self.parentNode.idevices.index(replacementIdev) \ > ( (self.parentNode.idevices.index(self) + 1))): replacementIdev.movePrev() # finally: delete THIS idevice itself, deleting it from the node self.delete()
def __getFactoryExtendediDevices(self): """ JRJ: Carga los iDevices de fábrica (loads the factory iDevices) """ from exe.engine.freetextidevice import FreeTextIdevice from exe.engine.multimediaidevice import MultimediaIdevice from exe.engine.reflectionidevice import ReflectionIdevice from exe.engine.casestudyidevice import CasestudyIdevice from exe.engine.truefalseidevice import TrueFalseIdevice # converting ImageWithTextIdevice -> FreeTextIdevice: #from exe.engine.imagewithtextidevice import ImageWithTextIdevice from exe.engine.wikipediaidevice import WikipediaIdevice from exe.engine.attachmentidevice import AttachmentIdevice from exe.engine.titleidevice import TitleIdevice from exe.engine.galleryidevice import GalleryIdevice from exe.engine.clozeidevice import ClozeIdevice #from exe.engine.clozelangidevice import ClozelangIdevice from exe.engine.flashwithtextidevice import FlashWithTextIdevice from exe.engine.externalurlidevice import ExternalUrlIdevice from exe.engine.imagemagnifieridevice import ImageMagnifierIdevice # converting Maths Idevice -> FreeTextIdevice: #from exe.engine.mathidevice import MathIdevice from exe.engine.multichoiceidevice import MultichoiceIdevice from exe.engine.rssidevice import RssIdevice from exe.engine.multiselectidevice import MultiSelectIdevice from exe.engine.appletidevice import AppletIdevice from exe.engine.flashmovieidevice import FlashMovieIdevice from exe.engine.quiztestidevice import QuizTestIdevice from exe.engine.listaidevice import ListaIdevice from exe.engine.notaidevice import NotaIdevice from exe.engine.sortidevice import SortIdeviceInc from exe.engine.hangmanidevice import HangmanIdeviceInc from exe.engine.clickinorderidevice import ClickInOrderIdeviceInc from exe.engine.memorymatchidevice import MemoryMatchIdeviceInc from exe.engine.placetheobjectsidevice import PlaceTheObjectsIdeviceInc from exe.engine.fileattachidevice import FileAttachIdeviceInc # JRJ # Necesarios para la FPD # (Necessary for FPD) from exe.engine.reflectionfpdidevice import ReflectionfpdIdevice from exe.engine.reflectionfpdmodifidevice import ReflectionfpdmodifIdevice from exe.engine.clozefpdidevice import ClozefpdIdevice from exe.engine.clozelangfpdidevice import ClozelangfpdIdevice from exe.engine.parasabermasfpdidevice import ParasabermasfpdIdevice from exe.engine.debesconocerfpdidevice import DebesconocerfpdIdevice from exe.engine.citasparapensarfpdidevice import CitasparapensarfpdIdevice from exe.engine.recomendacionfpdidevice import RecomendacionfpdIdevice from exe.engine.verdaderofalsofpdidevice import VerdaderofalsofpdIdevice from exe.engine.seleccionmultiplefpdidevice import SeleccionmultiplefpdIdevice from exe.engine.eleccionmultiplefpdidevice import EleccionmultiplefpdIdevice from exe.engine.casopracticofpdidevice import CasopracticofpdIdevice from exe.engine.ejercicioresueltofpdidevice import EjercicioresueltofpdIdevice from exe.engine.destacadofpdidevice import DestacadofpdIdevice #from exe.engine.correccionfpdidevice import CorreccionfpdIdevice from exe.engine.orientacionesalumnadofpdidevice import OrientacionesalumnadofpdIdevice from exe.engine.orientacionestutoriafpdidevice import OrientacionestutoriafpdIdevice from exe.engine.freetextfpdidevice import FreeTextfpdIdevice factoryExtendedIdevices = [] factoryExtendedIdevices.append(SortIdeviceInc()) factoryExtendedIdevices.append(HangmanIdeviceInc()) factoryExtendedIdevices.append(ClickInOrderIdeviceInc()) factoryExtendedIdevices.append(MemoryMatchIdeviceInc()) #factoryExtendedIdevices.append(PlaceTheObjectsIdeviceInc()) factoryExtendedIdevices.append(FileAttachIdeviceInc()) factoryExtendedIdevices.append(FreeTextIdevice()) factoryExtendedIdevices.append(MultichoiceIdevice()) factoryExtendedIdevices.append(ReflectionIdevice()) factoryExtendedIdevices.append(CasestudyIdevice()) factoryExtendedIdevices.append(TrueFalseIdevice()) defaultImage = unicode(self.config.webDir / "images" / "sunflowers.jpg") # converting ImageWithTextIdevice -> FreeTextIdevice: #factoryExtendedIdevices.append(ImageWithTextIdevice(defaultImage)) factoryExtendedIdevices.append(ImageMagnifierIdevice(defaultImage)) defaultImage = unicode(self.config.webDir / "images" / "sunflowers.jpg") defaultSite = 'http://%s.wikipedia.org/' % self.config.locale factoryExtendedIdevices.append(WikipediaIdevice(defaultSite)) #JRJ: Eliminamos este iDevice de los extendidos # (we eliminate this iDevice from the extended ones) #factoryExtendedIdevices.append(AttachmentIdevice()) factoryExtendedIdevices.append(GalleryIdevice()) factoryExtendedIdevices.append(ClozeIdevice()) #factoryExtendedIdevices.append(ClozelangIdevice()) #JRJ: Eliminamos este iDevices de los extendidos # (we eliminate this iDevice from the extended ones) #factoryExtendedIdevices.append(FlashWithTextIdevice()) factoryExtendedIdevices.append(ExternalUrlIdevice()) # converting Maths Idevice -> FreeTextIdevice: #factoryExtendedIdevices.append(MathIdevice()) #JRJ: Eliminamos este iDevices de los extendidos # (we eliminate this iDevice from the extended ones) #factoryExtendedIdevices.append(MultimediaIdevice()) factoryExtendedIdevices.append(RssIdevice()) factoryExtendedIdevices.append(MultiSelectIdevice()) factoryExtendedIdevices.append(AppletIdevice()) #JRJ: Eliminamos este iDevices de los extendidos # (we eliminate this iDevice from the extended ones) #factoryExtendedIdevices.append(FlashMovieIdevice()) factoryExtendedIdevices.append(QuizTestIdevice()) factoryExtendedIdevices.append(ListaIdevice()) factoryExtendedIdevices.append(NotaIdevice()) # JRJ # iDevices para la FPD # (iDevices for FPD) factoryExtendedIdevices.append(ReflectionfpdIdevice()) factoryExtendedIdevices.append(ReflectionfpdmodifIdevice()) factoryExtendedIdevices.append(ClozefpdIdevice()) factoryExtendedIdevices.append(ClozelangfpdIdevice()) factoryExtendedIdevices.append(ParasabermasfpdIdevice()) factoryExtendedIdevices.append(DebesconocerfpdIdevice()) factoryExtendedIdevices.append(CitasparapensarfpdIdevice()) factoryExtendedIdevices.append(RecomendacionfpdIdevice()) factoryExtendedIdevices.append(VerdaderofalsofpdIdevice()) factoryExtendedIdevices.append(SeleccionmultiplefpdIdevice()) factoryExtendedIdevices.append(EleccionmultiplefpdIdevice()) factoryExtendedIdevices.append(CasopracticofpdIdevice()) factoryExtendedIdevices.append(EjercicioresueltofpdIdevice()) factoryExtendedIdevices.append(DestacadofpdIdevice()) #factoryExtendedIdevices.append(CorreccionfpdIdevice()) factoryExtendedIdevices.append(OrientacionesalumnadofpdIdevice()) factoryExtendedIdevices.append(OrientacionestutoriafpdIdevice()) factoryExtendedIdevices.append(FreeTextfpdIdevice()) return factoryExtendedIdevices
def _insertNode(self, node, url, depth=0, idevice=None): if self.cancel: return if isinstance(url,str): link = None url = self.resources['urls'][url] elif isinstance(url,Link): link = url url = link.url if url.mime == 'text/html' and self.depths[str(url)] >= depth: if self.client: self.client.call('eXe.app.getController("Toolbar").updateImportProgressWindow',_(u'Inserting %s') % (str(url))) type = link.tag.name if link and link.tag else 'a' if type not in ['frame','iframe'] and node: node = node.createChild() node.setTitle(self._guessName(url)) if depth == 1: node.up() if not node: node = self.node parent = idevice if type in ['frame','iframe'] else None idevice = FreeTextIdevice(type=type,parent=parent) idevice.edit = False node.addIdevice(idevice) if url.type == "file": p = Path(self.baseurl + os.path.sep + str(url)) p.setSalt(str(url)) r = Resource(idevice,p) url.storageName = quote(r.storageName) if link and link.relative not in link.referrer.contentUpdated: if link.match: link.referrer.content = link.referrer.content.replace(link.match,'###resources###/%s' % (url.storageName)) else: link.referrer.content = link.referrer.content.replace(link.relative,'###resources###/%s' % (url.storageName)) link.referrer.contentUpdated.append(link.relative) if self.depths[str(url)] < depth: return for l in url.links: if self.cancel: return self._insertNode(node, l, depth+1, idevice) content = url.getContent() if content: content_w_resourcePaths = re.sub('###resources###/','resources/',content) content_wo_resourcePaths = re.sub('###resources###/','',content) if url.mime == "text/html" and idevice: soup = url.getSoup() if soup and soup.declaredHTMLEncoding: content_w_resourcePaths = re.sub(soup.declaredHTMLEncoding,'utf-8',content_w_resourcePaths,re.IGNORECASE) content_wo_resourcePaths = re.sub(soup.declaredHTMLEncoding,'utf-8',content_wo_resourcePaths,re.IGNORECASE) if soup and soup.find('frameset'): idevice.type = 'frameset' idevice.setContent(content_w_resourcePaths,content_wo_resourcePaths) f = open(r.path,"w") f.write(content_wo_resourcePaths.encode('utf-8')) f.close()
def convertToFreeText(self): """ Actually do the Converting of MathsIdevice -> FreeTextIdevice, now that FreeText can hold embeddded images. """ new_content = "" # ensure that an image resource still exists on this ImageWithText, # before trying to add it into the FreeText idevice. # Why? corrupt packages have been seen missing resources... # (usually in with extra package objects as well, probably # from old code doing faulty Extracts, or somesuch nonesense) imageResource_exists = False if not self.content.gifResource is None: if os.path.exists(self.content.gifResource.path) and \ os.path.isfile(self.content.gifResource.path): imageResource_exists = True else: log.warn("Couldn't find Maths image when upgrading "\ + self.content.gifResource.storageName) if imageResource_exists: new_content += "<img src=\"resources/" \ + self.content.gifResource.storageName + "\" " # create the expected math resource url for comparison later, # once we do actually create it: math_resource_url="resources/" \ + self.content.gifResource.storageName + ".tex\" " new_content += "exe_math_latex=\"" + math_resource_url + "\" " new_content += "exe_math_size=\"" + repr(self.content.fontsize) \ + "\" " # no height or width for math images, eh? nope. new_content += "/> \n" elif self.content.gifResource: new_content += "<BR>\n[WARNING: missing image: " \ + self.content.gifResource.storageName + "]\n" replacementIdev = FreeTextIdevice(new_content) ########### # now, copy that content field's content into its _w_resourcePaths, # and properly remove the resource directory via Massage.... # for its _wo_resourcePaths: # note that replacementIdev's content field's content # is automatically set at its constructor (above), # as is the default content_w_resourcePaths (a copy of content) # AND the default content_wo_resourcePaths (a copy of content), # so only need to update the content_wo_resourcePaths: replacementIdev.content.content_wo_resourcePaths = \ replacementIdev.content.MassageContentForRenderView( \ replacementIdev.content.content_w_resourcePaths) # Design note: ahhhhh, the above is a good looking reason to possibly # have the MassageContentForRenderView() method # just assume its content_w_resourcePaths as the input # and write the output to its content_wo_resourcePaths..... ####### # next step, add the new IDevice into the same node as this one self.parentNode.addIdevice(replacementIdev) # in passing GalleryImage into the FieldWithResources, # that content field needs to be sure to have an updated # parentNode, courtesy of its idevice: replacementIdev.content.setParentNode() # and semi-manually add/create the current image # resource into the FreeTextIdevice's TextAreaField, content. # the content text will have already been taken care of above, # including the ideal <img src=...> including resources path, # but still need the actual image resource: if imageResource_exists: # Not sure why this can't be imported up top, but it gives # ImportError: cannot import name GalleryImages, # so here it be: from exe.engine.galleryidevice import GalleryImage full_image_path = self.content.gifResource.path # with empty caption: new_GalleryImage = GalleryImage(replacementIdev.content, \ '', full_image_path, mkThumbnail=False) # and.... write the latex_source out into the preview_math_srcfile # such that it can then be passed into the compile command. # Using the desired name (image.gif.tex), write it into tempWebDir: webDir = Path(G.application.tempWebDir) source_tex_name = self.content.gifResource.storageName + ".tex" math_path = webDir.joinpath(source_tex_name) math_filename_str = math_path.abspath().encode('utf-8') log.debug("convertToFreeText: writing LaTeX source into \'" \ + math_filename_str + "\'.") math_file = open(math_filename_str, 'wb') # do we need to append a \n here?: math_file.write(self.content.latex) math_file.flush() math_file.close() # finally, creating a resource for the latex_source as well: new_GalleryLatex = GalleryImage(replacementIdev.content, \ '', math_filename_str, mkThumbnail=False) new_GalleryLatexResource = new_GalleryLatex._imageResource mathsrc_resource_path = new_GalleryLatexResource._storageName # and re-concatenate from the global resources name, # to build the webUrl to the resource: mathsrc_resource_url = new_GalleryLatex.resourcesUrl \ + mathsrc_resource_path # AND compare with the newly built resource_url from above, # to ensure that we've got what we had expected, jah! if (mathsrc_resource_url != math_resource_url): log.warn('The math source was resource-ified differently ' \ + 'than expected, to: ' + mathsrc_resource_url \ + '; the source will need to be recreated.') # right. we COULD go ahead and change the exe_math_latex # attribute to point to the actual mathsrc_resource_url, # EXCEPT that the entire exemath plugin is currently built # with the idea that the source .tex file will always be named # as the mathimage.gif.tex, and this exe_math_latex tag # is really just letting the rest of the world know that # there IS corresponding source expected there. # If exemath is to ever change and use the actual contents # of this exe_math_latex tag (rather than just appended .tex), # then this could be revisited here. else: log.debug('math source was resource-ified properly to: ' \ + mathsrc_resource_url) # and move the new idevice up to the position following this node! while ( self.parentNode.idevices.index(replacementIdev) \ > ( (self.parentNode.idevices.index(self) + 1))): replacementIdev.movePrev() # finally: delete THIS idevice itself, deleting it from the node self.delete()
def __loadExtended(self): """ Load the Extended iDevices (iDevices coded in Python) """ self.__loadUserExtended() from exe.engine.freetextidevice import FreeTextIdevice from exe.engine.multimediaidevice import MultimediaIdevice from exe.engine.reflectionidevice import ReflectionIdevice from exe.engine.casestudyidevice import CasestudyIdevice from exe.engine.truefalseidevice import TrueFalseIdevice # converting ImageWithTextIdevice -> FreeTextIdevice: #from exe.engine.imagewithtextidevice import ImageWithTextIdevice from exe.engine.wikipediaidevice import WikipediaIdevice from exe.engine.attachmentidevice import AttachmentIdevice from exe.engine.titleidevice import TitleIdevice from exe.engine.galleryidevice import GalleryIdevice from exe.engine.clozeidevice import ClozeIdevice from exe.engine.flashwithtextidevice import FlashWithTextIdevice from exe.engine.externalurlidevice import ExternalUrlIdevice from exe.engine.imagemagnifieridevice import ImageMagnifierIdevice # converting Maths Idevice -> FreeTextIdevice: #from exe.engine.mathidevice import MathIdevice from exe.engine.multichoiceidevice import MultichoiceIdevice from exe.engine.rssidevice import RssIdevice from exe.engine.multiselectidevice import MultiSelectIdevice from exe.engine.appletidevice import AppletIdevice from exe.engine.flashmovieidevice import FlashMovieIdevice from exe.engine.quiztestidevice import QuizTestIdevice from exe.engine.pdfidevice import PdfIdevice from exe.engine.feedbackidevice import FeedbackIdevice from exe.engine.hintidevice import HintIdevice from exe.engine.glossaryidevice import GlossaryIdevice from exe.engine.latexidevice import LatexIdevice from exe.engine.tocidevice import TOCIdevice self.extended.append(FreeTextIdevice()) self.extended.append(TOCIdevice()) self.extended.append(LatexIdevice()) self.extended.append(GlossaryIdevice()) self.extended.append(FeedbackIdevice()) self.extended.append(HintIdevice()) self.extended.append(PdfIdevice()) self.extended.append(MultichoiceIdevice()) self.extended.append(ReflectionIdevice()) self.extended.append(CasestudyIdevice()) self.extended.append(TrueFalseIdevice()) defaultImage = unicode(self.config.webDir / "images" / "sunflowers.jpg") # converting ImageWithTextIdevice -> FreeTextIdevice: #self.extended.append(ImageWithTextIdevice(defaultImage)) self.extended.append(ImageMagnifierIdevice(defaultImage)) defaultImage = unicode(self.config.webDir / "images" / "sunflowers.jpg") defaultSite = 'http://%s.wikipedia.org/' % self.config.locale self.extended.append(WikipediaIdevice(defaultSite)) self.extended.append(AttachmentIdevice()) self.extended.append(GalleryIdevice()) self.extended.append(ClozeIdevice()) self.extended.append(FlashWithTextIdevice()) self.extended.append(ExternalUrlIdevice()) # converting Maths Idevice -> FreeTextIdevice: #self.extended.append(MathIdevice()) self.extended.append(MultimediaIdevice()) self.extended.append(RssIdevice()) self.extended.append(MultiSelectIdevice()) self.extended.append(AppletIdevice()) self.extended.append(FlashMovieIdevice()) self.extended.append(QuizTestIdevice()) # generate new ids for these iDevices, to avoid any clashes for idevice in self.extended: idevice.id = self.getNewIdeviceId()
def __loadExtended(self): """ Load the Extended iDevices (iDevices coded in Python) """ self.__loadUserExtended() from exe.engine.freetextidevice import FreeTextIdevice from exe.engine.multimediaidevice import MultimediaIdevice from exe.engine.reflectionidevice import ReflectionIdevice from exe.engine.casestudyidevice import CasestudyIdevice from exe.engine.truefalseidevice import TrueFalseIdevice # converting ImageWithTextIdevice -> FreeTextIdevice: #from exe.engine.imagewithtextidevice import ImageWithTextIdevice from exe.engine.wikipediaidevice import WikipediaIdevice from exe.engine.attachmentidevice import AttachmentIdevice from exe.engine.titleidevice import TitleIdevice from exe.engine.galleryidevice import GalleryIdevice from exe.engine.clozeidevice import ClozeIdevice #from exe.engine.clozelangidevice import ClozelangIdevice from exe.engine.flashwithtextidevice import FlashWithTextIdevice from exe.engine.externalurlidevice import ExternalUrlIdevice from exe.engine.imagemagnifieridevice import ImageMagnifierIdevice # converting Maths Idevice -> FreeTextIdevice: #from exe.engine.mathidevice import MathIdevice from exe.engine.multichoiceidevice import MultichoiceIdevice from exe.engine.rssidevice import RssIdevice from exe.engine.multiselectidevice import MultiSelectIdevice from exe.engine.appletidevice import AppletIdevice from exe.engine.flashmovieidevice import FlashMovieIdevice from exe.engine.quiztestidevice import QuizTestIdevice # JR # Necesarios para la FPD from exe.engine.reflectionfpdidevice import ReflectionfpdIdevice from exe.engine.reflectionfpdmodifidevice import ReflectionfpdmodifIdevice from exe.engine.clozefpdidevice import ClozefpdIdevice from exe.engine.clozelangfpdidevice import ClozelangfpdIdevice from exe.engine.parasabermasfpdidevice import ParasabermasfpdIdevice from exe.engine.debesconocerfpdidevice import DebesconocerfpdIdevice from exe.engine.citasparapensarfpdidevice import CitasparapensarfpdIdevice from exe.engine.recomendacionfpdidevice import RecomendacionfpdIdevice from exe.engine.verdaderofalsofpdidevice import VerdaderofalsofpdIdevice from exe.engine.seleccionmultiplefpdidevice import SeleccionmultiplefpdIdevice from exe.engine.eleccionmultiplefpdidevice import EleccionmultiplefpdIdevice from exe.engine.casopracticofpdidevice import CasopracticofpdIdevice from exe.engine.ejercicioresueltofpdidevice import EjercicioresueltofpdIdevice from exe.engine.destacadofpdidevice import DestacadofpdIdevice #from exe.engine.correccionfpdidevice import CorreccionfpdIdevice from exe.engine.orientacionesalumnadofpdidevice import OrientacionesalumnadofpdIdevice from exe.engine.orientacionestutoriafpdidevice import OrientacionestutoriafpdIdevice from exe.engine.freetextfpdidevice import FreeTextfpdIdevice self.extended.append(FreeTextIdevice()) self.extended.append(MultichoiceIdevice()) self.extended.append(ReflectionIdevice()) self.extended.append(CasestudyIdevice()) self.extended.append(TrueFalseIdevice()) defaultImage = unicode(self.config.webDir / "images" / "sunflowers.jpg") # converting ImageWithTextIdevice -> FreeTextIdevice: #self.extended.append(ImageWithTextIdevice(defaultImage)) self.extended.append(ImageMagnifierIdevice(defaultImage)) defaultImage = unicode(self.config.webDir / "images" / "sunflowers.jpg") defaultSite = 'http://%s.wikipedia.org/' % self.config.locale self.extended.append(WikipediaIdevice(defaultSite)) self.extended.append(AttachmentIdevice()) self.extended.append(GalleryIdevice()) self.extended.append(ClozeIdevice()) #self.extended.append(ClozelangIdevice()) self.extended.append(FlashWithTextIdevice()) self.extended.append(ExternalUrlIdevice()) # converting Maths Idevice -> FreeTextIdevice: #self.extended.append(MathIdevice()) self.extended.append(MultimediaIdevice()) self.extended.append(RssIdevice()) self.extended.append(MultiSelectIdevice()) self.extended.append(AppletIdevice()) self.extended.append(FlashMovieIdevice()) self.extended.append(QuizTestIdevice()) # JR # iDevices para la FPD self.extended.append(ReflectionfpdIdevice()) self.extended.append(ReflectionfpdmodifIdevice()) self.extended.append(ClozefpdIdevice()) self.extended.append(ClozelangfpdIdevice()) self.extended.append(ParasabermasfpdIdevice()) self.extended.append(DebesconocerfpdIdevice()) self.extended.append(CitasparapensarfpdIdevice()) self.extended.append(RecomendacionfpdIdevice()) self.extended.append(VerdaderofalsofpdIdevice()) self.extended.append(SeleccionmultiplefpdIdevice()) self.extended.append(EleccionmultiplefpdIdevice()) self.extended.append(CasopracticofpdIdevice()) self.extended.append(EjercicioresueltofpdIdevice()) self.extended.append(DestacadofpdIdevice()) #self.extended.append(CorreccionfpdIdevice()) self.extended.append(OrientacionesalumnadofpdIdevice()) self.extended.append(OrientacionestutoriafpdIdevice()) self.extended.append(FreeTextfpdIdevice()) # generate new ids for these iDevices, to avoid any clashes for idevice in self.extended: idevice.id = self.getNewIdeviceId()
def _insertNode(self, node, url, depth=0, idevice=None): if self.cancel: return if isinstance(url, str): link = None url = self.resources['urls'][url] elif isinstance(url, Link): link = url url = link.url if url.mime == 'text/html' and self.depths[str(url)] >= depth: if self.client: self.client.call( 'eXe.app.getController("Toolbar").updateImportProgressWindow', _(u'Inserting %s') % (str(url))) type = link.tag.name if link and link.tag else 'a' if type not in ['frame', 'iframe'] and node: node = node.createChild() node.setTitle(self._guessName(url)) if depth == 1: node.up() if not node: node = self.node parent = idevice if type in ['frame', 'iframe'] else None idevice = FreeTextIdevice(type=type, parent=parent) idevice.edit = False node.addIdevice(idevice) if url.type == "file": p = Path(self.baseurl + os.path.sep + str(url)) p.setSalt(str(url)) r = Resource(idevice, p) url.storageName = quote(r.storageName) if link and link.relative not in link.referrer.contentUpdated: if link.match: link.referrer.content = link.referrer.content.replace( link.match, '###resources###/%s' % (url.storageName)) else: link.referrer.content = link.referrer.content.replace( link.relative, '###resources###/%s' % (url.storageName)) link.referrer.contentUpdated.append(link.relative) if self.depths[str(url)] < depth: return for l in url.links: if self.cancel: return self._insertNode(node, l, depth + 1, idevice) content = url.getContent() if content: content_w_resourcePaths = re.sub('###resources###/', 'resources/', content) content_wo_resourcePaths = re.sub('###resources###/', '', content) if url.mime == "text/html" and idevice: soup = url.getSoup() if soup and soup.declaredHTMLEncoding: content_w_resourcePaths = re.sub(soup.declaredHTMLEncoding, 'utf-8', content_w_resourcePaths, re.IGNORECASE) content_wo_resourcePaths = re.sub( soup.declaredHTMLEncoding, 'utf-8', content_wo_resourcePaths, re.IGNORECASE) if soup and soup.find('frameset'): idevice.type = 'frameset' idevice.setContent(content_w_resourcePaths, content_wo_resourcePaths) f = open(r.path, "w") f.write(content_wo_resourcePaths.encode('utf-8')) f.close()
def createIdevice(self): self.idevice = FreeTextIdevice() self.idevice.edit = False self.node.addIdevice(self.idevice) return self.idevice
def convertToFreeText(self): """ Actually do the Converting of MathsIdevice -> FreeTextIdevice, now that FreeText can hold embeddded images. """ new_content = "" # ensure that an image resource still exists on this ImageWithText, # before trying to add it into the FreeText idevice. # Why? corrupt packages have been seen missing resources... # (usually in with extra package objects as well, probably # from old code doing faulty Extracts, or somesuch nonesense) imageResource_exists = False if not self.content.gifResource is None: if os.path.exists(self.content.gifResource.path) and \ os.path.isfile(self.content.gifResource.path): imageResource_exists = True else: log.warn("Couldn't find Maths image when upgrading "\ + self.content.gifResource.storageName) if imageResource_exists: new_content += "<img src=\"resources/" \ + self.content.gifResource.storageName + "\" " # create the expected math resource url for comparison later, # once we do actually create it: math_resource_url="resources/" \ + self.content.gifResource.storageName + ".tex\" " new_content += "exe_math_latex=\"" + math_resource_url + "\" " new_content += "exe_math_size=\"" + repr(self.content.fontsize) \ + "\" " # no height or width for math images, eh? nope. new_content += "/> \n" elif self.content.gifResource: new_content += "<BR>\n[WARNING: missing image: " \ + self.content.gifResource.storageName + "]\n" replacementIdev = FreeTextIdevice(new_content) ########### # now, copy that content field's content into its _w_resourcePaths, # and properly remove the resource directory via Massage.... # for its _wo_resourcePaths: # note that replacementIdev's content field's content # is automatically set at its constructor (above), # as is the default content_w_resourcePaths (a copy of content) # AND the default content_wo_resourcePaths (a copy of content), # so only need to update the content_wo_resourcePaths: replacementIdev.content.content_wo_resourcePaths = \ replacementIdev.content.MassageContentForRenderView( \ replacementIdev.content.content_w_resourcePaths) # Design note: ahhhhh, the above is a good looking reason to possibly # have the MassageContentForRenderView() method # just assume its content_w_resourcePaths as the input # and write the output to its content_wo_resourcePaths..... ####### # next step, add the new IDevice into the same node as this one self.parentNode.addIdevice(replacementIdev) # in passing GalleryImage into the FieldWithResources, # that content field needs to be sure to have an updated # parentNode, courtesy of its idevice: replacementIdev.content.setParentNode() # and semi-manually add/create the current image # resource into the FreeTextIdevice's TextAreaField, content. # the content text will have already been taken care of above, # including the ideal <img src=...> including resources path, # but still need the actual image resource: if imageResource_exists: # Not sure why this can't be imported up top, but it gives # ImportError: cannot import name GalleryImages, # so here it be: from exe.engine.galleryidevice import GalleryImage full_image_path = self.content.gifResource.path # with empty caption: new_GalleryImage = GalleryImage(replacementIdev.content, \ '', full_image_path, mkThumbnail=False) # and.... write the latex_source out into the preview_math_srcfile # such that it can then be passed into the compile command. # Using the desired name (image.gif.tex), write it into tempWebDir: webDir = Path(G.application.tempWebDir) source_tex_name = self.content.gifResource.storageName+".tex" math_path = webDir.joinpath(source_tex_name) math_filename_str = math_path.abspath().encode('utf-8') log.debug("convertToFreeText: writing LaTeX source into \'" \ + math_filename_str + "\'.") math_file = open(math_filename_str, 'wb') # do we need to append a \n here?: math_file.write(self.content.latex) math_file.flush() math_file.close() # finally, creating a resource for the latex_source as well: new_GalleryLatex = GalleryImage(replacementIdev.content, \ '', math_filename_str, mkThumbnail=False) new_GalleryLatexResource = new_GalleryLatex._imageResource mathsrc_resource_path = new_GalleryLatexResource._storageName # and re-concatenate from the global resources name, # to build the webUrl to the resource: mathsrc_resource_url = new_GalleryLatex.resourcesUrl \ + mathsrc_resource_path # AND compare with the newly built resource_url from above, # to ensure that we've got what we had expected, jah! if (mathsrc_resource_url != math_resource_url): log.warn('The math source was resource-ified differently ' \ + 'than expected, to: ' + mathsrc_resource_url \ + '; the source will need to be recreated.') # right. we COULD go ahead and change the exe_math_latex # attribute to point to the actual mathsrc_resource_url, # EXCEPT that the entire exemath plugin is currently built # with the idea that the source .tex file will always be named # as the mathimage.gif.tex, and this exe_math_latex tag # is really just letting the rest of the world know that # there IS corresponding source expected there. # If exemath is to ever change and use the actual contents # of this exe_math_latex tag (rather than just appended .tex), # then this could be revisited here. else: log.debug('math source was resource-ified properly to: ' \ + mathsrc_resource_url) # and move the new idevice up to the position following this node! while ( self.parentNode.idevices.index(replacementIdev) \ > ( (self.parentNode.idevices.index(self) + 1))): replacementIdev.movePrev() # finally: delete THIS idevice itself, deleting it from the node self.delete()
def __loadExtended(self): """ Load the Extended iDevices (iDevices coded in Python) """ self.__loadUserExtended() from exe.engine.freetextidevice import FreeTextIdevice from exe.engine.multimediaidevice import MultimediaIdevice from exe.engine.reflectionidevice import ReflectionIdevice from exe.engine.casestudyidevice import CasestudyIdevice from exe.engine.truefalseidevice import TrueFalseIdevice # converting ImageWithTextIdevice -> FreeTextIdevice: #from exe.engine.imagewithtextidevice import ImageWithTextIdevice from exe.engine.wikipediaidevice import WikipediaIdevice from exe.engine.attachmentidevice import AttachmentIdevice from exe.engine.titleidevice import TitleIdevice from exe.engine.galleryidevice import GalleryIdevice from exe.engine.clozeidevice import ClozeIdevice from exe.engine.flashwithtextidevice import FlashWithTextIdevice from exe.engine.externalurlidevice import ExternalUrlIdevice from exe.engine.imagemagnifieridevice import ImageMagnifierIdevice # converting Maths Idevice -> FreeTextIdevice: #from exe.engine.mathidevice import MathIdevice from exe.engine.multichoiceidevice import MultichoiceIdevice from exe.engine.rssidevice import RssIdevice from exe.engine.multiselectidevice import MultiSelectIdevice from exe.engine.appletidevice import AppletIdevice from exe.engine.flashmovieidevice import FlashMovieIdevice from exe.engine.quiztestidevice import QuizTestIdevice #modifications by lernmodule.net #changed: clozeidevice #next 3 idevices inserted from exe.engine.scormdropdownidevice import ScormDropDownIdevice from exe.engine.scormclozeidevice import ScormClozeIdevice from exe.engine.scormmultiselectidevice import ScormMultiSelectIdevice #end modifications self.extended.append(FreeTextIdevice()) self.extended.append(MultichoiceIdevice()) self.extended.append(ReflectionIdevice()) self.extended.append(CasestudyIdevice()) self.extended.append(TrueFalseIdevice()) defaultImage = unicode(self.config.webDir/"images"/"sunflowers.jpg") # converting ImageWithTextIdevice -> FreeTextIdevice: #self.extended.append(ImageWithTextIdevice(defaultImage)) self.extended.append(ImageMagnifierIdevice(defaultImage)) defaultImage = unicode(self.config.webDir/"images"/"sunflowers.jpg") defaultSite = 'http://%s.wikipedia.org/' % self.config.locale self.extended.append(WikipediaIdevice(defaultSite)) self.extended.append(AttachmentIdevice()) self.extended.append(GalleryIdevice()) self.extended.append(ClozeIdevice()) self.extended.append(FlashWithTextIdevice()) self.extended.append(ExternalUrlIdevice()) # converting Maths Idevice -> FreeTextIdevice: #self.extended.append(MathIdevice()) self.extended.append(MultimediaIdevice()) self.extended.append(RssIdevice()) self.extended.append(MultiSelectIdevice()) self.extended.append(AppletIdevice()) self.extended.append(FlashMovieIdevice()) #modifications by lernmodule.net #self.extended.append(QuizTestIdevice()) self.extended.append(ScormDropDownIdevice()) self.extended.append(ScormClozeIdevice()) self.extended.append(ScormMultiSelectIdevice()) #end modifications # generate new ids for these iDevices, to avoid any clashes for idevice in self.extended: idevice.id = self.getNewIdeviceId()
def __getFactoryExtendediDevices(self): """ JR: Carga los iDevices de fabrica """ from exe.engine.freetextidevice import FreeTextIdevice from exe.engine.multimediaidevice import MultimediaIdevice from exe.engine.reflectionidevice import ReflectionIdevice from exe.engine.casestudyidevice import CasestudyIdevice from exe.engine.truefalseidevice import TrueFalseIdevice # converting ImageWithTextIdevice -> FreeTextIdevice: #from exe.engine.imagewithtextidevice import ImageWithTextIdevice #from exe.engine.wikipediaidevice import WikipediaIdevice from exe.engine.attachmentidevice import AttachmentIdevice from exe.engine.titleidevice import TitleIdevice from exe.engine.galleryidevice import GalleryIdevice from exe.engine.clozeidevice import ClozeIdevice #from exe.engine.clozelangidevice import ClozelangIdevice from exe.engine.flashwithtextidevice import FlashWithTextIdevice from exe.engine.externalurlidevice import ExternalUrlIdevice from exe.engine.imagemagnifieridevice import ImageMagnifierIdevice # converting Maths Idevice -> FreeTextIdevice: #from exe.engine.mathidevice import MathIdevice from exe.engine.multichoiceidevice import MultichoiceIdevice #from exe.engine.rssidevice import RssIdevice from exe.engine.multiselectidevice import MultiSelectIdevice #from exe.engine.appletidevice import AppletIdevice from exe.engine.flashmovieidevice import FlashMovieIdevice from exe.engine.quiztestidevice import QuizTestIdevice # JR # Necesarios para la FPD from exe.engine.reflectionfpdidevice import ReflectionfpdIdevice from exe.engine.reflectionfpdmodifidevice import ReflectionfpdmodifIdevice from exe.engine.clozefpdidevice import ClozefpdIdevice from exe.engine.clozelangfpdidevice import ClozelangfpdIdevice from exe.engine.parasabermasfpdidevice import ParasabermasfpdIdevice from exe.engine.debesconocerfpdidevice import DebesconocerfpdIdevice from exe.engine.citasparapensarfpdidevice import CitasparapensarfpdIdevice from exe.engine.recomendacionfpdidevice import RecomendacionfpdIdevice from exe.engine.verdaderofalsofpdidevice import VerdaderofalsofpdIdevice from exe.engine.seleccionmultiplefpdidevice import SeleccionmultiplefpdIdevice from exe.engine.eleccionmultiplefpdidevice import EleccionmultiplefpdIdevice from exe.engine.casopracticofpdidevice import CasopracticofpdIdevice from exe.engine.ejercicioresueltofpdidevice import EjercicioresueltofpdIdevice from exe.engine.destacadofpdidevice import DestacadofpdIdevice #from exe.engine.correccionfpdidevice import CorreccionfpdIdevice from exe.engine.orientacionesalumnadofpdidevice import OrientacionesalumnadofpdIdevice from exe.engine.orientacionestutoriafpdidevice import OrientacionestutoriafpdIdevice from exe.engine.freetextfpdidevice import FreeTextfpdIdevice # eXelearningPlus iDevices from exe.engine.scormclozeidevice import ScormClozeIdevice from exe.engine.scormmultiselectidevice import ScormMultiSelectIdevice from exe.engine.scormdropdownidevice import ScormDropDownIdevice from exe.engine.scormmulticlozeidevice import ScormMultiClozeIdevice from exe.engine.opinionidevice import OpinionIdevice from exe.engine.dropdownidevice import DropDownIdevice from exe.engine.scormmultiselectindfeedbackidevice import ScormMultiSelectIndFeedbackIdevice factoryExtendedIdevices = [] factoryExtendedIdevices.append(FreeTextIdevice()) factoryExtendedIdevices.append(MultichoiceIdevice()) factoryExtendedIdevices.append(ReflectionIdevice()) factoryExtendedIdevices.append(CasestudyIdevice()) factoryExtendedIdevices.append(TrueFalseIdevice()) defaultImage = unicode(self.config.webDir / "images" / "sunflowers.jpg") # converting ImageWithTextIdevice -> FreeTextIdevice: #factoryExtendedIdevices.append(ImageWithTextIdevice(defaultImage)) factoryExtendedIdevices.append(ImageMagnifierIdevice(defaultImage)) defaultImage = unicode(self.config.webDir / "images" / "sunflowers.jpg") #defaultSite = 'http://%s.wikipedia.org/' % self.config.locale #factoryExtendedIdevices.append(WikipediaIdevice(defaultSite)) #JR: Eliminamos este iDevices de los extendidos #factoryExtendedIdevices.append(AttachmentIdevice()) factoryExtendedIdevices.append(GalleryIdevice()) factoryExtendedIdevices.append(ClozeIdevice()) #factoryExtendedIdevices.append(ClozelangIdevice()) #JR: Eliminamos este iDevices de los extendidos #factoryExtendedIdevices.append(FlashWithTextIdevice()) factoryExtendedIdevices.append(ExternalUrlIdevice()) # converting Maths Idevice -> FreeTextIdevice: #factoryExtendedIdevices.append(MathIdevice()) #JR: Eliminamos este iDevices de los extendidos #factoryExtendedIdevices.append(MultimediaIdevice()) #factoryExtendedIdevices.append(RssIdevice()) factoryExtendedIdevices.append(MultiSelectIdevice()) #factoryExtendedIdevices.append(AppletIdevice()) #JR: Eliminamos este iDevices de los extendidos #factoryExtendedIdevices.append(FlashMovieIdevice()) #modification lernmodule.net #factoryExtendedIdevices.append(QuizTestIdevice()) #end modification lernmodule.net # JR # iDevices para la FPD factoryExtendedIdevices.append(ReflectionfpdIdevice()) factoryExtendedIdevices.append(ReflectionfpdmodifIdevice()) factoryExtendedIdevices.append(ClozefpdIdevice()) factoryExtendedIdevices.append(ClozelangfpdIdevice()) factoryExtendedIdevices.append(ParasabermasfpdIdevice()) factoryExtendedIdevices.append(DebesconocerfpdIdevice()) factoryExtendedIdevices.append(CitasparapensarfpdIdevice()) factoryExtendedIdevices.append(RecomendacionfpdIdevice()) factoryExtendedIdevices.append(VerdaderofalsofpdIdevice()) factoryExtendedIdevices.append(SeleccionmultiplefpdIdevice()) factoryExtendedIdevices.append(EleccionmultiplefpdIdevice()) factoryExtendedIdevices.append(CasopracticofpdIdevice()) factoryExtendedIdevices.append(EjercicioresueltofpdIdevice()) factoryExtendedIdevices.append(DestacadofpdIdevice()) #factoryExtendedIdevices.append(CorreccionfpdIdevice()) factoryExtendedIdevices.append(OrientacionesalumnadofpdIdevice()) factoryExtendedIdevices.append(OrientacionestutoriafpdIdevice()) factoryExtendedIdevices.append(FreeTextfpdIdevice()) # eXelearningPlus factoryExtendedIdevices.append(ScormClozeIdevice()) factoryExtendedIdevices.append(ScormMultiSelectIdevice()) factoryExtendedIdevices.append(ScormDropDownIdevice()) factoryExtendedIdevices.append(ScormMultiClozeIdevice()) factoryExtendedIdevices.append(OpinionIdevice()) factoryExtendedIdevices.append(DropDownIdevice()) factoryExtendedIdevices.append(ScormMultiSelectIndFeedbackIdevice()) return factoryExtendedIdevices
def convertToFreeText(self): """ Actually do the Converting of MathsIdevice -> FreeTextIdevice, now that FreeText can hold embeddded images. """ new_content = "" imageResource_exists = False if not self.content.gifResource is None: if os.path.exists(self.content.gifResource.path) and \ os.path.isfile(self.content.gifResource.path): imageResource_exists = True else: log.warn("Couldn't find Maths image when upgrading "\ + self.content.gifResource.storageName) if imageResource_exists: new_content += "<img src=\"resources/" \ + self.content.gifResource.storageName + "\" " math_resource_url="resources/" \ + self.content.gifResource.storageName + ".tex\" " new_content += "exe_math_latex=\"" + math_resource_url + "\" " new_content += "exe_math_size=\"" + repr(self.content.fontsize) \ + "\" " new_content += "/> \n" elif self.content.gifResource: new_content += "<BR>\n[WARNING: missing image: " \ + self.content.gifResource.storageName + "]\n" replacementIdev = FreeTextIdevice(new_content) replacementIdev.content.content_wo_resourcePaths = \ replacementIdev.content.MassageContentForRenderView( \ replacementIdev.content.content_w_resourcePaths) self.parentNode.addIdevice(replacementIdev) replacementIdev.content.setParentNode() if imageResource_exists: from exe.engine.galleryidevice import GalleryImage full_image_path = self.content.gifResource.path new_GalleryImage = GalleryImage(replacementIdev.content, \ '', full_image_path, mkThumbnail=False) webDir = Path(G.application.tempWebDir) source_tex_name = self.content.gifResource.storageName+".tex" math_path = webDir.joinpath(source_tex_name) math_filename_str = math_path.abspath().encode('utf-8') log.debug("convertToFreeText: writing LaTeX source into \'" \ + math_filename_str + "\'.") math_file = open(math_filename_str, 'wb') math_file.write(self.content.latex) math_file.flush() math_file.close() new_GalleryLatex = GalleryImage(replacementIdev.content, \ '', math_filename_str, mkThumbnail=False) new_GalleryLatexResource = new_GalleryLatex._imageResource mathsrc_resource_path = new_GalleryLatexResource._storageName mathsrc_resource_url = new_GalleryLatex.resourcesUrl \ + mathsrc_resource_path if (mathsrc_resource_url != math_resource_url): log.warn('The math source was resource-ified differently ' \ + 'than expected, to: ' + mathsrc_resource_url \ + '; the source will need to be recreated.') else: log.debug('math source was resource-ified properly to: ' \ + mathsrc_resource_url) while ( self.parentNode.idevices.index(replacementIdev) \ > ( (self.parentNode.idevices.index(self) + 1))): replacementIdev.movePrev() self.delete()