def WritePatterned(stream, type, subjNamTab, helpText, color, labHRef, numFields, labText, dictLines): pattArray = PatternNode(type) # PROBLEME: Le titre et les elements n ont pas forcement les memes couleurs. # Le cadre est celui du titre. try: if labHRef: stream.write( pattArray[0] % (subjNamTab, helpText, color, labHRef, numFields, labText)) else: stream.write(pattArray[1] % (subjNamTab, helpText, color, numFields, labText)) except UnicodeEncodeError: sys.stderr.write("WritePatterned UnicodeEncodeError: Encoding=%s\n" % sys.getdefaultencoding()) return for key in lib_util.natural_sorted(dictLines): try: stream.write("<tr>%s</tr>" % dictLines[key]) except UnicodeEncodeError: stream.write("<tr><td>Unicode error encoding=%s</td></tr>" % sys.getdefaultencoding()) stream.write("</table> > ] \n")
def WritePatterned(stream, a_type, subj_nam_tab, help_text, color, lab_h_ref, num_fields, lab_text, dict_lines): patt_array = _pattern_node(a_type) # TODO: The title and the elements might not have the same color. # TODO: At least, < and > in labels are correctly displayed, but not really clickable. # The best is to avoid them in entities names and urls. help_text = help_text.replace("\"", """) lab_text = help_text.replace("<", "<").replace(">", ">") lab_h_ref = lab_h_ref.replace("<", "<").replace(">", ">") try: if lab_h_ref: stream.write(patt_array[0] % (subj_nam_tab, help_text, color, lab_h_ref, num_fields, lab_text)) else: stream.write( patt_array[1] % (subj_nam_tab, help_text, color, num_fields, lab_text)) except UnicodeEncodeError: logging.debug("WritePatterned UnicodeEncodeError: Encoding=%s", sys.getdefaultencoding()) return for key in lib_util.natural_sorted(dict_lines): try: # Brackets have a specific role in "dot" files syntax. # So this escapes them, to be correctly displayed by the browser. dict_lines_key = dict_lines[key] dict_lines_key = dict_lines_key.replace("[", "[").replace( "]", "]") dict_lines[key] = dict_lines_key except Exception as exc: dict_lines_key = "<td>WritePatterned: exc=%s</td>" % str(exc) stream.write("<tr>%s</tr>" % dict_lines_key) stream.write("</table> > ] \n")
def _display_class_objects_no_jinja(dict_subj_prop_obj): """The subjects must be sorted by their title.""" tuples_subjects_list = [] for a_subj in dict_subj_prop_obj: subj_str = str(a_subj) subj_title, entity_graphic_class, entity_id = lib_naming.ParseEntityUri( subj_str) if subj_title: # The intention is to detect a specific test case with accented characters. if subj_title[0] == 'Y' and subj_title.find("Boulogne"): logging.debug("_display_class_objects_no_jinja subj_str=%s" % subj_str) logging.debug("_display_class_objects_no_jinja subj_title=%s" % subj_title) continue else: logging.debug("NO TITLE FOR %s" % subj_str) tuples_subjects_list.append( (a_subj, subj_str, subj_title, entity_graphic_class, entity_id)) # Sorted by the title of the subject, which is the third value of the tuple. lib_util.natural_sort_list(tuples_subjects_list, key=lambda tup: tup[2]) # Apparently, a problem is that "%" gets transformed into an hexadecimal number, preventing decoding. def _custom_decode_hex(the_str): the_str = lib_util.survol_unescape(the_str) return the_str.replace("%25", "%").replace("%2F", "/").replace( "%5C", "\\").replace("%3A", ":") # Now it iterates on the sorted list. # This reuses all the intermediate values. for a_subj, subj_str, subj_title, entity_graphic_class, entity_id in tuples_subjects_list: # FIXME: This is a specific test to catch a specific condition... if a_subj.find("Boulogne") >= 0 or subj_str.find( "Boulogne") >= 0 or subj_title.find("Boulogne") >= 0: logging.debug("a_subj=%s" % a_subj) logging.debug("subj_str=%s" % subj_str) logging.debug("subj_title=%s" % subj_title) continue dict_pred = dict_subj_prop_obj[a_subj] # Total number of lines. cnt_preds = 0 for a_pred in dict_pred: lst_objs = dict_pred[a_pred] cnt_preds += len(lst_objs) must_write_col_one_subj = True subj_str_with_mode = _url_in_html_mode(subj_str) # The predicates, i.e. the properties associated a subject with an object, # must be alphabetically sorted. for a_pred in lib_util.natural_sorted(dict_pred): lst_objs = dict_pred[a_pred] pred_str = lib_exports.AntiPredicateUri(str(a_pred)) cnt_objs = len(lst_objs) must_write_col_one_pred = True # The objects must be sorted by title. lst_tuples_objs = [] for an_obj in lst_objs: obj_str = str(an_obj) obj_str = _custom_decode_hex(obj_str) obj_title = lib_naming.ParseEntityUri(obj_str)[0] lst_tuples_objs.append((an_obj, obj_str, obj_title)) # Sorted by the title of the object, which is the third value of the tuple. lib_util.natural_sort_list(lst_tuples_objs, key=lambda tup: tup[2]) for an_obj, obj_str, obj_title in lst_tuples_objs: # FIXME: This is a specific test to catch a specific condition... if an_obj.find("Boulogne") >= 0 or obj_str.find( "Boulogne") >= 0 or obj_title.find("Boulogne") >= 0: logging.debug("an_obj=%s" % an_obj) logging.debug("obj_str=%s" % obj_str) logging.debug("obj_title=%s" % obj_title) continue # Nasty encoding errors. Probably the string should have been encoded before. if lib_util.isPlatformWindows and not lib_util.is_py3: try: dummy_str = obj_title.decode('ascii') except UnicodeDecodeError as exc: logging.debug("obj_title=%s" % obj_title) obj_title = obj_title.decode('cp1252') yield '<tr>' if must_write_col_one_subj: yield ( '<td valign="top" rowspan="%s"><a href="%s">%s</a></td>' % (str(cnt_preds), subj_str_with_mode, subj_title)) must_write_col_one_subj = False if must_write_col_one_pred: if a_pred not in _list_props_td_double_col_span: yield '<td valign="top" rowspan="%s">%s</td>' % ( str(cnt_objs), pred_str) must_write_col_one_pred = False if a_pred in _list_props_td_double_col_span: col_span = 2 else: col_span = 1 disp_mime_urls = True yield '<td colspan="%d">' % col_span if disp_mime_urls: if lib_kbase.IsLink(an_obj): obj_str_clean = lib_util.UrlNoAmp(obj_str) mimeType = lib_mime.get_mime_type_from_url( obj_str_clean) if mimeType: if mimeType.startswith("image/"): yield ( """<a href="%s"><img src="%s" alt="%s" height="42" width="42"></a>""" % (obj_str, obj_str, obj_title)) else: yield """<a href="%s">%s</a>""" % (obj_str, obj_title) else: url_with_mode = lib_util.url_mode_replace( obj_str, "html") yield """<a href="%s">%s</a>""" % (url_with_mode, obj_title) else: yield '%s' % obj_str else: if lib_kbase.IsLink(an_obj): url_with_mode = _url_in_html_mode(obj_str) yield '<a href="%s">%s</a>' % (url_with_mode, obj_title) else: yield '%s' % obj_str yield "</td>" yield "</tr>"
def DispClassObjects(dictSubjPropObj): listPropsTdDoubleColSpan = [ pc.property_information, pc.property_rdf_data_nolist2, pc.property_rdf_data_nolist1 ] WrtAsUtf('<table class="class_objects">') # The subjects must be sorted by their title. lstTuplesSubjects = [] for aSubj in dictSubjPropObj: subj_str = str(aSubj) (subj_title, entity_graphic_class, entity_id) = lib_naming.ParseEntityUri(subj_str) lstTuplesSubjects.append( (aSubj, subj_str, subj_title, entity_graphic_class, entity_id)) # Sorted by the title of the subject, which is the third value of the tuple. lib_util.natural_sort_list(lstTuplesSubjects, key=lambda tup: tup[2]) # Now it iterates on the sorted list. # This reuses all the intermediate values. for aSubj, subj_str, subj_title, entity_graphic_class, entity_id in lstTuplesSubjects: dictPred = dictSubjPropObj[aSubj] arrayGraphParams = lib_patterns.TypeToGraphParams(entity_graphic_class) # "Graphic_shape","Graphic_colorfill","Graphic_colorbg","Graphic_border","Graphic_is_rounded" colorClass = arrayGraphParams[1] # Total number of lines. cntPreds = 0 for aPred in dictPred: lstObjs = dictPred[aPred] cntPreds += len(lstObjs) mustWriteColOneSubj = True subj_str_with_mode = UrlInHtmlMode(subj_str) # The predicates, i.e. the properties associated a subject with an object, # must be alphabetically sorted. for aPred in lib_util.natural_sorted(dictPred): lstObjs = dictPred[aPred] predStr = lib_exports.AntiPredicateUri(str(aPred)) cntObjs = len(lstObjs) mustWriteColOnePred = True # The objects must be sorted by title. lstTuplesObjs = [] for anObj in lstObjs: obj_str = str(anObj) obj_str = DesHex(obj_str) obj_title = lib_naming.ParseEntityUri(obj_str)[0] lstTuplesObjs.append((anObj, obj_str, obj_title)) # Sorted by the title of the object, which is the third value of the tuple. lib_util.natural_sort_list(lstTuplesObjs, key=lambda tup: tup[2]) for anObj, obj_str, obj_title in lstTuplesObjs: WrtAsUtf('<tr bgcolor="%s">' % colorClass) if mustWriteColOneSubj: WrtAsUtf( '<td valign="top" rowspan="%s"><a href="%s">%s</a></td>' % (str(cntPreds), subj_str_with_mode, subj_title)) mustWriteColOneSubj = False if mustWriteColOnePred: if aPred not in listPropsTdDoubleColSpan: WrtAsUtf('<td valign="top" rowspan="%s">%s</td>' % (str(cntObjs), predStr)) mustWriteColOnePred = False if aPred in listPropsTdDoubleColSpan: colSpan = 2 else: colSpan = 1 dispMimeUrls = True WrtAsUtf('<td colspan="%d">' % (colSpan)) if dispMimeUrls: if lib_kbase.IsLink(anObj): objStrClean = lib_util.UrlNoAmp(obj_str) mimeType = lib_mime.GetMimeTypeFromUrl(objStrClean) if mimeType: if mimeType.startswith("image/"): WrtAsUtf( """<a href="%s"><img src="%s" alt="%s" height="42" width="42"></a>""" % (obj_str, obj_str, obj_title)) else: WrtAsUtf("""<a href="%s">%s</a>""" % (obj_str, obj_title)) else: url_with_mode = lib_util.AnyUriModed( obj_str, "html") WrtAsUtf("""<a href="%s">%s</a>""" % (url_with_mode, obj_title)) else: WrtAsUtf('%s' % (obj_str)) else: if lib_kbase.IsLink(anObj): url_with_mode = UrlInHtmlMode(obj_str) WrtAsUtf('<a href="%s">%s</a>' % (url_with_mode, obj_title)) else: WrtAsUtf('%s' % (obj_str)) WrtAsUtf("</td>") WrtAsUtf("</tr>") WrtAsUtf(" </table>")