Ejemplo n.º 1
0
    def createMetaData(self, template):
        """
        if user did not supply metadata title, description or creator
        then use package title, description, or creator in imslrm
        if they did not supply a package title, use the package name
        if they did not supply a date, use today
        """
        xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
        namespace = 'xmlns="http://ltsc.ieee.org/xsd/LOM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ltsc.ieee.org/xsd/LOM lomCustom.xsd"'

        modifiedMetaData = False

        # depending on (user desired) the metadata type:
        if self.metadataType == 'LOMES':
            output = StringIO.StringIO()
            metadata = copy.deepcopy(self.package.lomEs)
            title = metadata.get_general().get_title() or lomsubs.titleSub([])
            if not title.get_string():
                title.add_string(
                    lomsubs.LangStringSub(self.package.lang.encode('utf-8'),
                                          self.package.name))
                metadata.get_general().set_title(title)
            if self.scormType == "scorm1.2":
                modifiedMetaData = self._validateMetaData(metadata)

            if self.package.exportSource:
                technical = metadata.get_technical()
                if not technical:
                    technical = lomsubs.technicalSub('technical')
                    metadata.set_technical(technical)
                opr = technical.get_otherPlatformRequirements()
                if not opr:
                    opr = lomsubs.otherPlatformRequirementsSub()
                    technical.set_otherPlatformRequirements(opr)
                opr.add_string(
                    lomsubs.LangStringSub(self.package.lang.encode('utf-8'),
                                          'editor: eXe Learning'))

                found = False
                for platform in opr.get_string():
                    if platform.get_valueOf_(
                    ) == self.package.lomESPlatformMark:
                        found = True
                if not found:
                    opr.add_string(
                        lomsubs.LangStringSub(
                            self.package.lang.encode('utf-8'),
                            self.package.lomESPlatformMark))

            metadata.export(output,
                            0,
                            namespacedef_=namespace,
                            pretty_print=False)
            xml += output.getvalue()
        if self.metadataType == 'LOM':
            output = StringIO.StringIO()
            metadata = copy.deepcopy(self.package.lom)
            title = metadata.get_general().get_title() or lomsubs.titleSub([])
            if not title.get_string():
                title.add_string(
                    lomsubs.LangStringSub(self.package.lang.encode('utf-8'),
                                          self.package.name))
                metadata.get_general().set_title(title)

            if self.scormType == "scorm1.2":
                modifiedMetaData = self._validateMetaData(metadata)

            metadata.export(output,
                            0,
                            namespacedef_=namespace,
                            pretty_print=False)
            xml += output.getvalue()
        if self.metadataType == 'DC':
            lrm = self.package.dublinCore.__dict__.copy()
            # use package values in absentia:
            if lrm.get('title', '') == '':
                lrm['title'] = self.package.title
            if lrm['title'] == '':
                lrm['title'] = self.package.name
            if lrm.get('description', '') == '':
                lrm['description'] = self.package.description
            if lrm['description'] == '':
                lrm['description'] = self.package.name
            if lrm.get('creator', '') == '':
                lrm['creator'] = self.package.author
            if lrm['date'] == '':
                lrm['date'] = time.strftime('%Y-%m-%d')
            # if they don't look like VCARD entries, coerce to fn:
            for f in ('creator', 'publisher', 'contributors'):
                if re.match('.*[:;]', lrm[f]) == None:
                    lrm[f] = u'FN:' + lrm[f]
            xml = template % lrm

        return {'xml': xml, 'modifiedMetaData': modifiedMetaData}
Ejemplo n.º 2
0
 def createMetaData(self):
     """
     if user did not supply metadata title, description or creator
     then use package title, description, or creator in imslrm
     if they did not supply a package title, use the package name
     if they did not supply a date, use today
     """
     xml = ''
     namespace = 'lom:'
     # depending on (user desired) the metadata type:
     if self.metadataType == 'LOMES':
         output = StringIO.StringIO()
         metadata = copy.deepcopy(self.package.lomEs)
         title = metadata.get_general().get_title() or lomsubs.titleSub([])
         if not title.get_string():
             title.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.name))
             metadata.get_general().set_title(title)
         if self.package.exportSource:
             technical = metadata.get_technical()
             if not technical:
                 technical = lomsubs.technicalSub('technical')
                 metadata.set_technical(technical)
             opr = technical.get_otherPlatformRequirements()
             if not opr:
                 opr = lomsubs.otherPlatformRequirementsSub()
                 technical.set_otherPlatformRequirements(opr)
             found = False
             for platform in opr.get_string():
                 if platform.get_valueOf_() == self.package.lomESPlatformMark:
                     found = True
             if not found:
                 opr.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.lomESPlatformMark))
         metadata.export(output, 0, namespace_=namespace, pretty_print=False)
         xml = output.getvalue()
     if self.metadataType == 'LOM':
         output = StringIO.StringIO()
         metadata = copy.deepcopy(self.package.lom)
         title = metadata.get_general().get_title() or lomsubs.titleSub([])
         if not title.get_string():
             title.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.name))
             metadata.get_general().set_title(title)
         metadata.export(output, 0, namespace_=namespace, pretty_print=False)
         xml = output.getvalue()
     if self.metadataType == 'DC':
         lrm = self.package.dublinCore.__dict__.copy()
         # use package values in absentia:
         if lrm.get('title', '') == '':
             lrm['title'] = self.package.title
         if lrm['title'] == '':
             lrm['title'] = self.package.name
         if lrm.get('description', '') == '':
             lrm['description'] = self.package.description
         if lrm['description'] == '':
             lrm['description'] = self.package.name
         if lrm.get('creator', '') == '':
             lrm['creator'] = self.package.author
         if lrm['date'] == '':
             lrm['date'] = time.strftime('%Y-%m-%d')
         # if they don't look like VCARD entries, coerce to fn:
         for f in ('creator', 'publisher', 'contributors'):
             if re.match('.*[:;]', lrm[f]) == None:
                 lrm[f] = u'FN:' + lrm[f]
         templateFilename = self.config.webDir/'templates'/'imslrm.xml'
         template = open(templateFilename, 'rb').read()
         xml = template % lrm
         out = open(self.outputDir/'imslrm.xml', 'wb')
         out.write(xml.encode('utf8'))
         out.close()
         xml = '<adlcp:location>imslrm.xml</adlcp:location>'
     return xml
Ejemplo n.º 3
0
 def createMetaData(self):
     """
     if user did not supply metadata title, description or creator
     then use package title, description, or creator in imslrm
     if they did not supply a package title, use the package name
     if they did not supply a date, use today
     """
     xml = ''
     namespace = 'lom:'
     # depending on (user desired) the metadata type:
     if self.metadataType == 'LOMES':
         output = StringIO.StringIO()
         metadata = copy.deepcopy(self.package.lomEs)
         title = metadata.get_general().get_title() or lomsubs.titleSub([])
         if not title.get_string():
             title.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.name))
             metadata.get_general().set_title(title)
         if self.package.exportSource:
             technical = metadata.get_technical()
             if not technical:
                 technical = lomsubs.technicalSub('technical')
                 metadata.set_technical(technical)
             opr = technical.get_otherPlatformRequirements()
             if not opr:
                 opr = lomsubs.otherPlatformRequirementsSub()
                 technical.set_otherPlatformRequirements(opr)
             found = False
             for platform in opr.get_string():
                 if platform.get_valueOf_() == self.package.lomESPlatformMark:
                     found = True
             if not found:
                 opr.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.lomESPlatformMark))
         metadata.export(output, 0, namespace_=namespace, pretty_print=False)
         xml = output.getvalue()
     if self.metadataType == 'LOM':
         output = StringIO.StringIO()
         metadata = copy.deepcopy(self.package.lom)
         title = metadata.get_general().get_title() or lomsubs.titleSub([])
         if not title.get_string():
             title.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.name))
             metadata.get_general().set_title(title)
         metadata.export(output, 0, namespace_=namespace, pretty_print=False)
         xml = output.getvalue()
     if self.metadataType == 'DC':
         lrm = self.package.dublinCore.__dict__.copy()
         # use package values in absentia:
         if lrm.get('title', '') == '':
             lrm['title'] = self.package.title
         if lrm['title'] == '':
             lrm['title'] = self.package.name
         if lrm.get('description', '') == '':
             lrm['description'] = self.package.description
         if lrm['description'] == '':
             lrm['description'] = self.package.name
         if lrm.get('creator', '') == '':
             lrm['creator'] = self.package.author
         if lrm['date'] == '':
             lrm['date'] = time.strftime('%Y-%m-%d')
         # if they don't look like VCARD entries, coerce to fn:
         for f in ('creator', 'publisher', 'contributors'):
             if re.match('.*[:;]', lrm[f]) == None:
                 lrm[f] = u'FN:' + lrm[f]
         templateFilename = self.config.webDir/'templates'/'imslrm.xml'
         template = open(templateFilename, 'rb').read()
         xml = template % lrm
         out = open(self.outputDir/'imslrm.xml', 'wb')
         out.write(xml.encode('utf8'))
         out.close()
         xml = '<adlcp:location>imslrm.xml</adlcp:location>'
     return xml
Ejemplo n.º 4
0
    def createMetaData(self, template):
        """
        if user did not supply metadata title, description or creator
        then use package title, description, or creator in imslrm
        if they did not supply a package title, use the package name
        if they did not supply a date, use today
        """
        xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
        namespace = 'xmlns="http://ltsc.ieee.org/xsd/LOM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ltsc.ieee.org/xsd/LOM lomCustom.xsd"'

        modifiedMetaData = False

        # depending on (user desired) the metadata type:
        if self.metadataType == 'LOMES':
            output = StringIO.StringIO()
            metadata = copy.deepcopy(self.package.lomEs)
            title = metadata.get_general().get_title() or lomsubs.titleSub([])
            if not title.get_string():
                title.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.name))
                metadata.get_general().set_title(title)
            if self.scormType == "scorm1.2":
                modifiedMetaData = self._validateMetaData(metadata)

            if self.package.exportSource:
                technical = metadata.get_technical()
                if not technical:
                    technical = lomsubs.technicalSub('technical')
                    metadata.set_technical(technical)
                opr = technical.get_otherPlatformRequirements()
                if not opr:
                    opr = lomsubs.otherPlatformRequirementsSub()
                    technical.set_otherPlatformRequirements(opr)
                opr.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), 'editor: eXe Learning'))

                found = False
                for platform in opr.get_string():
                    if platform.get_valueOf_() == self.package.lomESPlatformMark:
                        found = True
                if not found:
                    opr.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.lomESPlatformMark))

            metadata.export(output, 0, namespacedef_=namespace, pretty_print=False)
            xml += output.getvalue()
        if self.metadataType == 'LOM':
            output = StringIO.StringIO()
            metadata = copy.deepcopy(self.package.lom)
            title = metadata.get_general().get_title() or lomsubs.titleSub([])
            if not title.get_string():
                title.add_string(lomsubs.LangStringSub(self.package.lang.encode('utf-8'), self.package.name))
                metadata.get_general().set_title(title)

            if self.scormType == "scorm1.2":
                modifiedMetaData = self._validateMetaData(metadata)

            metadata.export(output, 0, namespacedef_=namespace, pretty_print=False)
            xml += output.getvalue()
        if self.metadataType == 'DC':
            lrm = self.package.dublinCore.__dict__.copy()
            # use package values in absentia:
            if lrm.get('title', '') == '':
                lrm['title'] = self.package.title
            if lrm['title'] == '':
                lrm['title'] = self.package.name
            if lrm.get('description', '') == '':
                lrm['description'] = self.package.description
            if lrm['description'] == '':
                lrm['description'] = self.package.name
            if lrm.get('creator', '') == '':
                lrm['creator'] = self.package.author
            if lrm['date'] == '':
                lrm['date'] = time.strftime('%Y-%m-%d')
            # if they don't look like VCARD entries, coerce to fn:
            for f in ('creator', 'publisher', 'contributors'):
                if re.match('.*[:;]', lrm[f]) == None:
                    lrm[f] = u'FN:' + lrm[f]
            xml = template % lrm

        return {'xml': xml, 'modifiedMetaData' : modifiedMetaData}