Ejemplo n.º 1
0
 def _generateDataListByPackage(self,
                                dataEntryLst,
                                pkgName,
                                list_fields,
                                listName,
                                columnNames,
                                searchColumnNames,
                                fileNoOutDir,
                                custom_header=None):
     filename = os.path.join(fileNoOutDir,
                             "%s-%s.html" % (pkgName, listName))
     with open(filename, 'w') as output:
         output.write("<html>\n")
         if pkgName == "All":
             tName = "%s %s List" % (normalizePackageName(pkgName),
                                     listName)
         else:
             tName = normalizePackageName(pkgName)
         outputDataListTableHeader(output, tName, columnNames,
                                   searchColumnNames)
         output.write("<body id=\"dt_example\">")
         output.write(
             "<a class=\"brand\" href=\"%s\" style=\"height:50px; padding: 0px;\"> \
               <img src=\"https://osehra.org/sites/default/files/vivian.png\" width=\"137\" height=\"50\"/></a>"
             % VIV_URL)
         output.write("""<div id="container" style="width:80%">""")
         if pkgName == "All":
             pkgLinkName = pkgName
             output.write("<h1>%s %s List</h1>" % (pkgLinkName, listName))
         else:
             output.write("<h2 align=\"right\"><a href=\"./All-%s.html\">"
                          "All %s</a></h2>" % (listName, listName))
             pkgLinkName = getPackageHRefLink(pkgName)
             output.write("<h1>Package: %s %s List</h1>" %
                          (pkgLinkName, listName))
         if not custom_header:
             outputDataTableHeader(output, columnNames, tName)
             outputDataTableFooter(output, columnNames, tName)
         else:
             outputCustomDataTableHeaderRows(output, custom_header, tName)
             outputDataTableFooter(output, columnNames, tName)
         # table body
         output.write("<tbody>\n")
         for dataEntry in dataEntryLst:
             tableRow = [""] * len(list_fields)
             allFields = dataEntry.fields
             output.write("<tr>\n")
             for idx, id in enumerate(list_fields):
                 # If value has / in it, we take the first value as usual
                 # but assume the information is a "multiple" field and
                 # attempt to find the second bit of information within it
                 idVal, multval = id[1].split('/') if (
                     len(id[1].split('/')) > 1) else (id[1], None)
                 if idVal in allFields:
                     value = allFields[idVal].value
                     if multval:  # and (multval in value.dataEntries["1"].fields)
                         value = self.findSubValue(dataEntry, value,
                                                   multval, id)
                     if isinstance(value, list) and id[0] != "Description":
                         # Don't write out descriptions as lists
                         tmpValue = "<ul>"
                         for entry in value:
                             if id[-1]:
                                 tmpValue += "<li>" + id[-1](
                                     dataEntry,
                                     entry,
                                     sourceField=id[1],
                                     targetField=id[-2],
                                     glbData=self.dataMap,
                                     crossRef=self.crossRef) + "</li>"
                             else:
                                 tmpValue += "<li>" + entry + "</li>"
                         value = tmpValue + "</ul>"
                     else:
                         if id[-1]:
                             value = id[-1](dataEntry,
                                            value,
                                            sourceField=id[1],
                                            targetField=id[-2],
                                            glbData=self.dataMap,
                                            crossRef=self.crossRef)
                     tableRow[idx] = value
             for item in tableRow:
                 output.write("<td>%s</td>\n" % item)
             output.write("</tr>\n")
         output.write("</tbody>\n")
         output.write("</table>\n")
         output.write("</div>\n")
         output.write("</div>\n")
         output.write("</body></html>\n")
Ejemplo n.º 2
0
 def _generateDataListByPackage(self, dataEntryLst, pkgName, list_fields,
                                listName, columnNames, searchColumnNames,
                                fileNoOutDir, custom_header=None):
   filename = os.path.join(fileNoOutDir, "%s-%s.html" % (pkgName, listName))
   with open(filename, 'w') as output:
     output.write("<html>\n")
     if pkgName == "All":
       tName = "%s %s List" % (normalizePackageName(pkgName), listName)
     else:
       tName = normalizePackageName(pkgName)
     outputDataListTableHeader(output, tName, columnNames, searchColumnNames)
     output.write("<body id=\"dt_example\">")
     output.write("""<div id="container" style="width:80%">""")
     if pkgName == "All":
       pkgLinkName = pkgName
       output.write("<h1>%s %s List</h1>" % (pkgLinkName, listName))
     else:
       output.write("<h2 align=\"right\"><a href=\"./All-%s.html\">"
                    "All %s</a></h2>" % (listName, listName))
       pkgLinkName = getPackageHRefLink(pkgName)
       output.write("<h1>Package: %s %s List</h1>" % (pkgLinkName, listName))
     if not custom_header:
       outputDataTableHeader(output, columnNames, tName)
       outputDataTableFooter(output, columnNames, tName)
     else:
       outputCustomDataTableHeaderRows(output, custom_header, tName)
       outputDataTableFooter(output, columnNames, tName)
     """ table body """
     output.write("<tbody>\n")
     for dataEntry in dataEntryLst:
       tableRow = [""]*len(list_fields)
       allFields = dataEntry.fields
       output.write("<tr>\n")
       for idx, id in enumerate(list_fields):
         # If value has / in it, we take the first value as usual
         # but assume the information is a "multiple" field and
         # attempt to find the second bit of information within it
         idVal, multval = id[1].split('/') if (len(id[1].split('/')) > 1) else (id[1],None)
         if idVal in allFields:
           value = allFields[idVal].value
           if multval:  # and (multval in value.dataEntries["1"].fields)
             value = self.findSubValue(dataEntry, value,multval,id)
           if type(value) is list and id[0] != "Description":
             # Don't write out descriptions as lists
             tmpValue="<ul>"
             for entry in value:
               if id[-1]:
                 tmpValue += "<li>"+id[-1](dataEntry, entry,sourceField=id[1], targetField=id[-2], glbData=self.dataMap, crossRef=self.crossRef)+"</li>"
               else:
                 tmpValue += "<li>"+ entry +"</li>"
             value = tmpValue+"</ul>"
           else:
             if id[-1]:
               value = id[-1](dataEntry, value,sourceField=id[1], targetField=id[-2], glbData=self.dataMap, crossRef=self.crossRef)
           tableRow[idx] = value
       for item in tableRow:
         #output.write("<td class=\"ellipsis\">%s</td>\n" % item)
         output.write("<td>%s</td>\n" % item)
       output.write("</tr>\n")
     output.write("</tbody>\n")
     output.write("</table>\n")
     output.write("</div>\n")
     output.write("</div>\n")
     output.write ("</body></html>\n")