comparison roundup/cgi/templating.py @ 5381:0942fe89e82e

Python 3 preparation: change "x.has_key(y)" to "y in x". (Also likewise "not in" where appropriate.) Tool-generated patch.
author Joseph Myers <jsm@polyomino.org.uk>
date Tue, 24 Jul 2018 22:08:17 +0000
parents 35ea9b1efc14
children d26921b851c3
comparison
equal deleted inserted replaced
5380:64c4e43fbb84 5381:0942fe89e82e
341 } 341 }
342 # add in the item if there is one 342 # add in the item if there is one
343 if client.nodeid: 343 if client.nodeid:
344 c['context'] = HTMLItem(client, classname, client.nodeid, 344 c['context'] = HTMLItem(client, classname, client.nodeid,
345 anonymous=1) 345 anonymous=1)
346 elif client.db.classes.has_key(classname): 346 elif classname in client.db.classes:
347 c['context'] = HTMLClass(client, classname, anonymous=1) 347 c['context'] = HTMLClass(client, classname, anonymous=1)
348 return c 348 return c
349 349
350 class HTMLDatabase: 350 class HTMLDatabase:
351 """ Return HTMLClasses for valid class fetches 351 """ Return HTMLClasses for valid class fetches
430 def _set_input_default_args(dic): 430 def _set_input_default_args(dic):
431 # 'text' is the default value anyway -- 431 # 'text' is the default value anyway --
432 # but for CSS usage it should be present 432 # but for CSS usage it should be present
433 dic.setdefault('type', 'text') 433 dic.setdefault('type', 'text')
434 # useful e.g for HTML LABELs: 434 # useful e.g for HTML LABELs:
435 if not dic.has_key('id'): 435 if 'id' not in dic:
436 try: 436 try:
437 if dic['text'] in ('radio', 'checkbox'): 437 if dic['text'] in ('radio', 'checkbox'):
438 dic['id'] = '%(name)s-%(value)s' % dic 438 dic['id'] = '%(name)s-%(value)s' % dic
439 else: 439 else:
440 dic['id'] = dic['name'] 440 dic['id'] = dic['name']
958 prop = self[prop_n] 958 prop = self[prop_n]
959 if not isinstance(prop, HTMLProperty): 959 if not isinstance(prop, HTMLProperty):
960 continue 960 continue
961 current[prop_n] = prop.plain(escape=1) 961 current[prop_n] = prop.plain(escape=1)
962 # make link if hrefable 962 # make link if hrefable
963 if (self._props.has_key(prop_n) and 963 if (prop_n in self._props and
964 isinstance(self._props[prop_n], hyperdb.Link)): 964 isinstance(self._props[prop_n], hyperdb.Link)):
965 classname = self._props[prop_n].classname 965 classname = self._props[prop_n].classname
966 try: 966 try:
967 template = self._client.selectTemplate(classname, 'item') 967 template = self._client.selectTemplate(classname, 'item')
968 if template.startswith('_generic.'): 968 if template.startswith('_generic.'):
1096 old = '<a ref="nofollow" href="%s%s">%s</a>'%(classname, 1096 old = '<a ref="nofollow" href="%s%s">%s</a>'%(classname,
1097 args[k], label) 1097 args[k], label)
1098 else: 1098 else:
1099 old = label; 1099 old = label;
1100 cell.append('%s: %s' % (self._(k), old)) 1100 cell.append('%s: %s' % (self._(k), old))
1101 if current.has_key(k): 1101 if k in current:
1102 cell[-1] += ' -> %s'%current[k] 1102 cell[-1] += ' -> %s'%current[k]
1103 current[k] = old 1103 current[k] = old
1104 1104
1105 elif isinstance(prop, hyperdb.Date) and args[k]: 1105 elif isinstance(prop, hyperdb.Date) and args[k]:
1106 if args[k] is None: 1106 if args[k] is None:
1107 d = '' 1107 d = ''
1108 else: 1108 else:
1109 d = date.Date(args[k], 1109 d = date.Date(args[k],
1110 translator=self._client).local(timezone) 1110 translator=self._client).local(timezone)
1111 cell.append('%s: %s'%(self._(k), str(d))) 1111 cell.append('%s: %s'%(self._(k), str(d)))
1112 if current.has_key(k): 1112 if k in current:
1113 cell[-1] += ' -> %s' % current[k] 1113 cell[-1] += ' -> %s' % current[k]
1114 current[k] = str(d) 1114 current[k] = str(d)
1115 1115
1116 elif isinstance(prop, hyperdb.Interval) and args[k]: 1116 elif isinstance(prop, hyperdb.Interval) and args[k]:
1117 val = str(date.Interval(args[k], 1117 val = str(date.Interval(args[k],
1118 translator=self._client)) 1118 translator=self._client))
1119 cell.append('%s: %s'%(self._(k), val)) 1119 cell.append('%s: %s'%(self._(k), val))
1120 if current.has_key(k): 1120 if k in current:
1121 cell[-1] += ' -> %s'%current[k] 1121 cell[-1] += ' -> %s'%current[k]
1122 current[k] = val 1122 current[k] = val
1123 1123
1124 elif isinstance(prop, hyperdb.String) and args[k]: 1124 elif isinstance(prop, hyperdb.String) and args[k]:
1125 val = cgi.escape(args[k]) 1125 val = cgi.escape(args[k])
1126 cell.append('%s: %s'%(self._(k), val)) 1126 cell.append('%s: %s'%(self._(k), val))
1127 if current.has_key(k): 1127 if k in current:
1128 cell[-1] += ' -> %s'%current[k] 1128 cell[-1] += ' -> %s'%current[k]
1129 current[k] = val 1129 current[k] = val
1130 1130
1131 elif isinstance(prop, hyperdb.Boolean) and args[k] is not None: 1131 elif isinstance(prop, hyperdb.Boolean) and args[k] is not None:
1132 val = args[k] and ''"Yes" or ''"No" 1132 val = args[k] and ''"Yes" or ''"No"
1133 cell.append('%s: %s'%(self._(k), val)) 1133 cell.append('%s: %s'%(self._(k), val))
1134 if current.has_key(k): 1134 if k in current:
1135 cell[-1] += ' -> %s'%current[k] 1135 cell[-1] += ' -> %s'%current[k]
1136 current[k] = val 1136 current[k] = val
1137 1137
1138 elif isinstance(prop, hyperdb.Password) and args[k] is not None: 1138 elif isinstance(prop, hyperdb.Password) and args[k] is not None:
1139 val = args[k].dummystr() 1139 val = args[k].dummystr()
1140 cell.append('%s: %s'%(self._(k), val)) 1140 cell.append('%s: %s'%(self._(k), val))
1141 if current.has_key(k): 1141 if k in current:
1142 cell[-1] += ' -> %s'%current[k] 1142 cell[-1] += ' -> %s'%current[k]
1143 current[k] = val 1143 current[k] = val
1144 1144
1145 elif not args[k]: 1145 elif not args[k]:
1146 if current.has_key(k): 1146 if k in current:
1147 cell.append('%s: %s'%(self._(k), current[k])) 1147 cell.append('%s: %s'%(self._(k), current[k]))
1148 current[k] = '(no value)' 1148 current[k] = '(no value)'
1149 else: 1149 else:
1150 cell.append(self._('%s: (no value)')%self._(k)) 1150 cell.append(self._('%s: (no value)')%self._(k))
1151 1151
1152 else: 1152 else:
1153 cell.append('%s: %s'%(self._(k), str(args[k]))) 1153 cell.append('%s: %s'%(self._(k), str(args[k])))
1154 if current.has_key(k): 1154 if k in current:
1155 cell[-1] += ' -> %s'%current[k] 1155 cell[-1] += ' -> %s'%current[k]
1156 current[k] = str(args[k]) 1156 current[k] = str(args[k])
1157 1157
1158 arg_s = '<br />'.join(cell) 1158 arg_s = '<br />'.join(cell)
1159 else: 1159 else:
1307 1307
1308 # If no value is already present for this property, see if one 1308 # If no value is already present for this property, see if one
1309 # is specified in the current form. 1309 # is specified in the current form.
1310 form = self._client.form 1310 form = self._client.form
1311 try: 1311 try:
1312 is_in = form.has_key(self._formname) 1312 is_in = self._formname in form
1313 except TypeError: 1313 except TypeError:
1314 is_in = False 1314 is_in = False
1315 if is_in and (not self._value or self._client.form_wins): 1315 if is_in and (not self._value or self._client.form_wins):
1316 if isinstance(prop, hyperdb.Multilink): 1316 if isinstance(prop, hyperdb.Multilink):
1317 value = lookupIds(self._db, prop, 1317 value = lookupIds(self._db, prop,
2631 else: 2631 else:
2632 var.append((dir, propname)) 2632 var.append((dir, propname))
2633 2633
2634 def _form_has_key(self, name): 2634 def _form_has_key(self, name):
2635 try: 2635 try:
2636 return self.form.has_key(name) 2636 return name in self.form
2637 except TypeError: 2637 except TypeError:
2638 pass 2638 pass
2639 return False 2639 return False
2640 2640
2641 def _post_init(self): 2641 def _post_init(self):
2737 2737
2738 def update(self, kwargs): 2738 def update(self, kwargs):
2739 """ Update my attributes using the keyword args 2739 """ Update my attributes using the keyword args
2740 """ 2740 """
2741 self.__dict__.update(kwargs) 2741 self.__dict__.update(kwargs)
2742 if kwargs.has_key('columns'): 2742 if 'columns' in kwargs:
2743 self.show = support.TruthDict(self.columns) 2743 self.show = support.TruthDict(self.columns)
2744 2744
2745 def description(self): 2745 def description(self):
2746 """ Return a description of the request - handle for the page title. 2746 """ Return a description of the request - handle for the page title.
2747 """ 2747 """
2863 for key in args.keys(): 2863 for key in args.keys():
2864 if key[0] in '@:': 2864 if key[0] in '@:':
2865 specials[key[1:]] = args[key] 2865 specials[key[1:]] = args[key]
2866 2866
2867 # ok, now handle the specials we received in the request 2867 # ok, now handle the specials we received in the request
2868 if self.columns and not specials.has_key('columns'): 2868 if self.columns and 'columns' not in specials:
2869 l.append(sc+'columns=%s'%(','.join(self.columns))) 2869 l.append(sc+'columns=%s'%(','.join(self.columns)))
2870 if self.sort and not specials.has_key('sort'): 2870 if self.sort and 'sort' not in specials:
2871 val = [] 2871 val = []
2872 for dir, attr in self.sort: 2872 for dir, attr in self.sort:
2873 if dir == '-': 2873 if dir == '-':
2874 val.append('-'+attr) 2874 val.append('-'+attr)
2875 else: 2875 else:
2876 val.append(attr) 2876 val.append(attr)
2877 l.append(sc+'sort=%s'%(','.join(val))) 2877 l.append(sc+'sort=%s'%(','.join(val)))
2878 if self.group and not specials.has_key('group'): 2878 if self.group and 'group' not in specials:
2879 val = [] 2879 val = []
2880 for dir, attr in self.group: 2880 for dir, attr in self.group:
2881 if dir == '-': 2881 if dir == '-':
2882 val.append('-'+attr) 2882 val.append('-'+attr)
2883 else: 2883 else:
2884 val.append(attr) 2884 val.append(attr)
2885 l.append(sc+'group=%s'%(','.join(val))) 2885 l.append(sc+'group=%s'%(','.join(val)))
2886 if self.filter and not specials.has_key('filter'): 2886 if self.filter and 'filter' not in specials:
2887 l.append(sc+'filter=%s'%(','.join(self.filter))) 2887 l.append(sc+'filter=%s'%(','.join(self.filter)))
2888 if self.search_text and not specials.has_key('search_text'): 2888 if self.search_text and 'search_text' not in specials:
2889 l.append(sc+'search_text=%s'%q(self.search_text)) 2889 l.append(sc+'search_text=%s'%q(self.search_text))
2890 if not specials.has_key('pagesize'): 2890 if 'pagesize' not in specials:
2891 l.append(sc+'pagesize=%s'%self.pagesize) 2891 l.append(sc+'pagesize=%s'%self.pagesize)
2892 if not specials.has_key('startwith'): 2892 if 'startwith' not in specials:
2893 l.append(sc+'startwith=%s'%self.startwith) 2893 l.append(sc+'startwith=%s'%self.startwith)
2894 2894
2895 # finally, the remainder of the filter args in the request 2895 # finally, the remainder of the filter args in the request
2896 if self.classname and self.filterspec: 2896 if self.classname and self.filterspec:
2897 cls = self.client.db.getclass(self.classname) 2897 cls = self.client.db.getclass(self.classname)
2898 for k,v in self.filterspec.items(): 2898 for k,v in self.filterspec.items():
2899 if not args.has_key(k): 2899 if k not in args:
2900 if type(v) == type([]): 2900 if type(v) == type([]):
2901 prop = cls.get_transitive_prop(k) 2901 prop = cls.get_transitive_prop(k)
2902 if k != 'id' and isinstance(prop, hyperdb.String): 2902 if k != 'id' and isinstance(prop, hyperdb.String):
2903 l.append('%s=%s'%(k, '%20'.join([q(i) for i in v]))) 2903 l.append('%s=%s'%(k, '%20'.join([q(i) for i in v])))
2904 else: 2904 else:
3077 def __getattr__(self, name): 3077 def __getattr__(self, name):
3078 """Try the tracker's templating_utils.""" 3078 """Try the tracker's templating_utils."""
3079 if not hasattr(self.client.instance, 'templating_utils'): 3079 if not hasattr(self.client.instance, 'templating_utils'):
3080 # backwards-compatibility 3080 # backwards-compatibility
3081 raise AttributeError(name) 3081 raise AttributeError(name)
3082 if not self.client.instance.templating_utils.has_key(name): 3082 if name not in self.client.instance.templating_utils:
3083 raise AttributeError(name) 3083 raise AttributeError(name)
3084 return self.client.instance.templating_utils[name] 3084 return self.client.instance.templating_utils[name]
3085 3085
3086 def keywords_expressions(self, request): 3086 def keywords_expressions(self, request):
3087 return render_keywords_expression_editor(request) 3087 return render_keywords_expression_editor(request)

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