comparison roundup/cgi/templating.py @ 5492:6b0c542642be

blobfiles now always stores/returns bytes any conversation is done in the backend layer added a special "binary_content" property to read the data as bytes changed history generation to read property data on demand
author Christof Meerwald <cmeerw@cmeerw.org>
date Sun, 12 Aug 2018 16:05:42 +0100
parents 52cb53eedf77
children fea11d05110e
comparison
equal deleted inserted replaced
5491:e72573996caf 5492:6b0c542642be
936 shown. 936 shown.
937 """ 937 """
938 if not self.is_view_ok(): 938 if not self.is_view_ok():
939 return self._('[hidden]') 939 return self._('[hidden]')
940 940
941 # pre-load the history with the current state
942 current = {}
943 for prop_n in self._props.keys():
944 prop = self[prop_n]
945 if not isinstance(prop, HTMLProperty):
946 continue
947 current[prop_n] = prop.plain(escape=1)
948 # make link if hrefable
949 if (prop_n in self._props and
950 isinstance(self._props[prop_n], hyperdb.Link)):
951 classname = self._props[prop_n].classname
952 try:
953 template = self._client.selectTemplate(classname, 'item')
954 if template.startswith('_generic.'):
955 raise NoTemplate('not really...')
956 except NoTemplate:
957 pass
958 else:
959 id = self._klass.get(self._nodeid, prop_n, None)
960 current[prop_n] = '<a rel="nofollow" href="%s%s">%s</a>'%(
961 classname, id, current[prop_n])
962
963 # get the journal, sort and reverse 941 # get the journal, sort and reverse
964 history = self._klass.history(self._nodeid, skipquiet=(not showall)) 942 history = self._klass.history(self._nodeid, skipquiet=(not showall))
965 history.sort(key=lambda a: a[:3]) 943 history.sort(key=lambda a: a[:3])
966 history.reverse() 944 history.reverse()
967 945
969 if limit: 947 if limit:
970 history = history[:limit] 948 history = history[:limit]
971 949
972 timezone = self._db.getUserTimezone() 950 timezone = self._db.getUserTimezone()
973 l = [] 951 l = []
952 current = {}
974 comments = {} 953 comments = {}
975 for id, evt_date, user, action, args in history: 954 for id, evt_date, user, action, args in history:
976 date_s = str(evt_date.local(timezone)).replace("."," ") 955 date_s = str(evt_date.local(timezone)).replace("."," ")
977 arg_s = '' 956 arg_s = ''
978 if action in ['link', 'unlink'] and type(args) == type(()): 957 if action in ['link', 'unlink'] and type(args) == type(()):
996 comments['no_exist'] = self._( 975 comments['no_exist'] = self._(
997 "<em>The indicated property no longer exists</em>") 976 "<em>The indicated property no longer exists</em>")
998 cell.append(self._('<em>%s: %s</em>\n') 977 cell.append(self._('<em>%s: %s</em>\n')
999 % (self._(k), str(args[k]))) 978 % (self._(k), str(args[k])))
1000 continue 979 continue
980
981 # load the current state for the property (if we
982 # haven't already)
983 if k not in current:
984 val = self[k]
985 if not isinstance(val, HTMLProperty):
986 current[k] = None
987 else:
988 current[k] = val.plain(escape=1)
989 # make link if hrefable
990 if (isinstance(prop, hyperdb.Link)):
991 classname = prop.classname
992 try:
993 template = self._client.selectTemplate(classname, 'item')
994 if template.startswith('_generic.'):
995 raise NoTemplate('not really...')
996 except NoTemplate:
997 pass
998 else:
999 linkid = self._klass.get(self._nodeid, k, None)
1000 current[k] = '<a rel="nofollow" href="%s%s">%s</a>'%(
1001 classname, linkid, current[k])
1001 1002
1002 if args[k] and (isinstance(prop, hyperdb.Multilink) or 1003 if args[k] and (isinstance(prop, hyperdb.Multilink) or
1003 isinstance(prop, hyperdb.Link)): 1004 isinstance(prop, hyperdb.Link)):
1004 # figure what the link class is 1005 # figure what the link class is
1005 classname = prop.classname 1006 classname = prop.classname
1082 old = '<a ref="nofollow" href="%s%s">%s</a>'%(classname, 1083 old = '<a ref="nofollow" href="%s%s">%s</a>'%(classname,
1083 args[k], label) 1084 args[k], label)
1084 else: 1085 else:
1085 old = label; 1086 old = label;
1086 cell.append('%s: %s' % (self._(k), old)) 1087 cell.append('%s: %s' % (self._(k), old))
1087 if k in current: 1088 if k in current and current[k] is not None:
1088 cell[-1] += ' -> %s'%current[k] 1089 cell[-1] += ' -> %s'%current[k]
1089 current[k] = old 1090 current[k] = old
1090 1091
1091 elif isinstance(prop, hyperdb.Date) and args[k]: 1092 elif isinstance(prop, hyperdb.Date) and args[k]:
1092 if args[k] is None: 1093 if args[k] is None:
1093 d = '' 1094 d = ''
1094 else: 1095 else:
1095 d = date.Date(args[k], 1096 d = date.Date(args[k],
1096 translator=self._client).local(timezone) 1097 translator=self._client).local(timezone)
1097 cell.append('%s: %s'%(self._(k), str(d))) 1098 cell.append('%s: %s'%(self._(k), str(d)))
1098 if k in current: 1099 if k in current and current[k] is not None:
1099 cell[-1] += ' -> %s' % current[k] 1100 cell[-1] += ' -> %s' % current[k]
1100 current[k] = str(d) 1101 current[k] = str(d)
1101 1102
1102 elif isinstance(prop, hyperdb.Interval) and args[k]: 1103 elif isinstance(prop, hyperdb.Interval) and args[k]:
1103 val = str(date.Interval(args[k], 1104 val = str(date.Interval(args[k],
1104 translator=self._client)) 1105 translator=self._client))
1105 cell.append('%s: %s'%(self._(k), val)) 1106 cell.append('%s: %s'%(self._(k), val))
1106 if k in current: 1107 if k in current and current[k] is not None:
1107 cell[-1] += ' -> %s'%current[k] 1108 cell[-1] += ' -> %s'%current[k]
1108 current[k] = val 1109 current[k] = val
1109 1110
1110 elif isinstance(prop, hyperdb.String) and args[k]: 1111 elif isinstance(prop, hyperdb.String) and args[k]:
1111 val = cgi.escape(args[k]) 1112 val = cgi.escape(args[k])
1112 cell.append('%s: %s'%(self._(k), val)) 1113 cell.append('%s: %s'%(self._(k), val))
1113 if k in current: 1114 if k in current and current[k] is not None:
1114 cell[-1] += ' -> %s'%current[k] 1115 cell[-1] += ' -> %s'%current[k]
1115 current[k] = val 1116 current[k] = val
1116 1117
1117 elif isinstance(prop, hyperdb.Boolean) and args[k] is not None: 1118 elif isinstance(prop, hyperdb.Boolean) and args[k] is not None:
1118 val = args[k] and ''"Yes" or ''"No" 1119 val = args[k] and ''"Yes" or ''"No"
1119 cell.append('%s: %s'%(self._(k), val)) 1120 cell.append('%s: %s'%(self._(k), val))
1120 if k in current: 1121 if k in current and current[k] is not None:
1121 cell[-1] += ' -> %s'%current[k] 1122 cell[-1] += ' -> %s'%current[k]
1122 current[k] = val 1123 current[k] = val
1123 1124
1124 elif isinstance(prop, hyperdb.Password) and args[k] is not None: 1125 elif isinstance(prop, hyperdb.Password) and args[k] is not None:
1125 val = args[k].dummystr() 1126 val = args[k].dummystr()
1126 cell.append('%s: %s'%(self._(k), val)) 1127 cell.append('%s: %s'%(self._(k), val))
1127 if k in current: 1128 if k in current and current[k] is not None:
1128 cell[-1] += ' -> %s'%current[k] 1129 cell[-1] += ' -> %s'%current[k]
1129 current[k] = val 1130 current[k] = val
1130 1131
1131 elif not args[k]: 1132 elif not args[k]:
1132 if k in current: 1133 if k in current and current[k] is not None:
1133 cell.append('%s: %s'%(self._(k), current[k])) 1134 cell.append('%s: %s'%(self._(k), current[k]))
1134 current[k] = '(no value)' 1135 current[k] = '(no value)'
1135 else: 1136 else:
1136 cell.append(self._('%s: (no value)')%self._(k)) 1137 cell.append(self._('%s: (no value)')%self._(k))
1137 1138
1138 else: 1139 else:
1139 cell.append('%s: %s'%(self._(k), str(args[k]))) 1140 cell.append('%s: %s'%(self._(k), str(args[k])))
1140 if k in current: 1141 if k in current and current[k] is not None:
1141 cell[-1] += ' -> %s'%current[k] 1142 cell[-1] += ' -> %s'%current[k]
1142 current[k] = str(args[k]) 1143 current[k] = str(args[k])
1143 1144
1144 arg_s = '<br />'.join(cell) 1145 arg_s = '<br />'.join(cell)
1145 else: 1146 else:

Roundup Issue Tracker: http://roundup-tracker.org/