Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 7035:edaf7086cb2e
flake8 E228 missing whitespace around modulo operator
plus some indenting fixes to realign lines.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 10 Oct 2022 14:41:11 -0400 |
| parents | 036267634a89 |
| children | 7847c9bdb631 |
comparison
equal
deleted
inserted
replaced
| 7034:036267634a89 | 7035:edaf7086cb2e |
|---|---|
| 2340 "data-height": height | 2340 "data-height": height |
| 2341 } | 2341 } |
| 2342 | 2342 |
| 2343 return ('<a class="classhelp" %s href="javascript:help_window(' | 2343 return ('<a class="classhelp" %s href="javascript:help_window(' |
| 2344 "'%s?@template=calendar&property=%s&form=%s%s', %d, %d)" | 2344 "'%s?@template=calendar&property=%s&form=%s%s', %d, %d)" |
| 2345 '">%s</a>'%(self.cgi_escape_attrs(**data_attr), | 2345 '">%s</a>' % (self.cgi_escape_attrs(**data_attr), |
| 2346 self._classname, self._name, form, date, width, | 2346 self._classname, self._name, form, date, width, |
| 2347 height, label)) | 2347 height, label)) |
| 2348 | 2348 |
| 2349 | 2349 |
| 2350 class IntervalHTMLProperty(HTMLProperty): | 2350 class IntervalHTMLProperty(HTMLProperty): |
| 2351 def __init__(self, client, classname, nodeid, prop, name, value, | 2351 def __init__(self, client, classname, nodeid, prop, name, value, |
| 2352 anonymous=0): | 2352 anonymous=0): |
| 2413 if attr == '__render_with_namespace__': | 2413 if attr == '__render_with_namespace__': |
| 2414 def nothing(*args, **kw): | 2414 def nothing(*args, **kw): |
| 2415 return '' | 2415 return '' |
| 2416 return nothing | 2416 return nothing |
| 2417 msg = self._('Attempt to look up %(attr)s on a missing value') | 2417 msg = self._('Attempt to look up %(attr)s on a missing value') |
| 2418 return MissingValue(msg%locals()) | 2418 return MissingValue(msg % locals()) |
| 2419 i = HTMLItem(self._client, self._prop.classname, self._value) | 2419 i = HTMLItem(self._client, self._prop.classname, self._value) |
| 2420 return getattr(i, attr) | 2420 return getattr(i, attr) |
| 2421 | 2421 |
| 2422 def __getitem__(self, item): | 2422 def __getitem__(self, item): |
| 2423 """Explicitly define __getitem__ -- this used to work earlier | 2423 """Explicitly define __getitem__ -- this used to work earlier |
| 2424 due to __getattr__ returning the __getitem__ of HTMLItem -- this | 2424 due to __getattr__ returning the __getitem__ of HTMLItem -- this |
| 2425 lookup doesn't work for new-style classes. | 2425 lookup doesn't work for new-style classes. |
| 2426 """ | 2426 """ |
| 2427 if not self._value: | 2427 if not self._value: |
| 2428 msg = self._('Attempt to look up %(item)s on a missing value') | 2428 msg = self._('Attempt to look up %(item)s on a missing value') |
| 2429 return MissingValue(msg%locals()) | 2429 return MissingValue(msg % locals()) |
| 2430 i = HTMLItem(self._client, self._prop.classname, self._value) | 2430 i = HTMLItem(self._client, self._prop.classname, self._value) |
| 2431 return i[item] | 2431 return i[item] |
| 2432 | 2432 |
| 2433 def plain(self, escape=0): | 2433 def plain(self, escape=0): |
| 2434 """ Render a "plain" representation of the property | 2434 """ Render a "plain" representation of the property |
| 2521 value = self._value | 2521 value = self._value |
| 2522 elif value == '-1': | 2522 elif value == '-1': |
| 2523 value = None | 2523 value = None |
| 2524 | 2524 |
| 2525 linkcl = self._db.getclass(self._prop.classname) | 2525 linkcl = self._db.getclass(self._prop.classname) |
| 2526 l = ['<select %s>'%self.cgi_escape_attrs(name=self._formname, | 2526 l = ['<select %s>' % self.cgi_escape_attrs(name=self._formname, |
| 2527 **html_kwargs)] | 2527 **html_kwargs)] |
| 2528 k = linkcl.labelprop(1) | 2528 k = linkcl.labelprop(1) |
| 2529 s = '' | 2529 s = '' |
| 2530 if value is None: | 2530 if value is None: |
| 2531 s = 'selected="selected" ' | 2531 s = 'selected="selected" ' |
| 2532 l.append(self._('<option %svalue="-1">- no selection -</option>')%s) | 2532 l.append(self._('<option %svalue="-1">- no selection -</option>') % s) |
| 2533 | 2533 |
| 2534 if sort_on is not None: | 2534 if sort_on is not None: |
| 2535 if not isinstance(sort_on, tuple): | 2535 if not isinstance(sort_on, tuple): |
| 2536 if sort_on[0] in '+-': | 2536 if sort_on[0] in '+-': |
| 2537 sort_on = (sort_on[0], sort_on[1:]) | 2537 sort_on = (sort_on[0], sort_on[1:]) |
| 2586 if (showdef): | 2586 if (showdef): |
| 2587 selected_mark = showdef | 2587 selected_mark = showdef |
| 2588 | 2588 |
| 2589 # figure the label | 2589 # figure the label |
| 2590 if showid: | 2590 if showid: |
| 2591 lab = '%s%s: %s'%(self._prop.classname, optionid, option) | 2591 lab = '%s%s: %s' % (self._prop.classname, optionid, option) |
| 2592 elif not option: | 2592 elif not option: |
| 2593 lab = '%s%s'%(self._prop.classname, optionid) | 2593 lab = '%s%s' % (self._prop.classname, optionid) |
| 2594 else: | 2594 else: |
| 2595 lab = option | 2595 lab = option |
| 2596 | 2596 |
| 2597 lab = lab + selected_mark | 2597 lab = lab + selected_mark |
| 2598 # truncate if it's too long | 2598 # truncate if it's too long |
| 2600 lab = lab[:size-3] + '...' | 2600 lab = lab[:size-3] + '...' |
| 2601 if additional: | 2601 if additional: |
| 2602 m = [] | 2602 m = [] |
| 2603 for fn in additional_fns: | 2603 for fn in additional_fns: |
| 2604 m.append(str(fn(optionid))) | 2604 m.append(str(fn(optionid))) |
| 2605 lab = lab + ' (%s)'%', '.join(m) | 2605 lab = lab + ' (%s)' % ', '.join(m) |
| 2606 | 2606 |
| 2607 # and generate | 2607 # and generate |
| 2608 tr = str | 2608 tr = str |
| 2609 if translate: | 2609 if translate: |
| 2610 tr = self._ | 2610 tr = self._ |
| 2611 lab = html_escape(tr(lab)) | 2611 lab = html_escape(tr(lab)) |
| 2612 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) | 2612 l.append('<option %svalue="%s">%s</option>' % (s, optionid, lab)) |
| 2613 l.append('</select>') | 2613 l.append('</select>') |
| 2614 return '\n'.join(l) | 2614 return '\n'.join(l) |
| 2615 | 2615 |
| 2616 # def checklist(self, ...) | 2616 # def checklist(self, ...) |
| 2617 | 2617 |
| 2744 label = linkcl.get(v, k, | 2744 label = linkcl.get(v, k, |
| 2745 default=self._("[label is missing]")) | 2745 default=self._("[label is missing]")) |
| 2746 except IndexError: | 2746 except IndexError: |
| 2747 label = None | 2747 label = None |
| 2748 # fall back to designator if label is None | 2748 # fall back to designator if label is None |
| 2749 if label is None: label = '%s%s'%(self._prop.classname, k) | 2749 if label is None: label = '%s%s' % (self._prop.classname, k) |
| 2750 else: | 2750 else: |
| 2751 label = v | 2751 label = v |
| 2752 labels.append(label) | 2752 labels.append(label) |
| 2753 value = ', '.join(labels) | 2753 value = ', '.join(labels) |
| 2754 if escape: | 2754 if escape: |
| 2835 height = len(options) | 2835 height = len(options) |
| 2836 if value: | 2836 if value: |
| 2837 # The "no selection" option. | 2837 # The "no selection" option. |
| 2838 height += 1 | 2838 height += 1 |
| 2839 height = min(height, 7) | 2839 height = min(height, 7) |
| 2840 l = ['<select multiple %s>'%self.cgi_escape_attrs(name=self._formname, | 2840 l = ['<select multiple %s>' % self.cgi_escape_attrs( |
| 2841 size=height, | 2841 name=self._formname, size=height, **html_kwargs)] |
| 2842 **html_kwargs)] | |
| 2843 k = linkcl.labelprop(1) | 2842 k = linkcl.labelprop(1) |
| 2844 | 2843 |
| 2845 if value: # FIXME '- no selection -' mark for translation | 2844 if value: # FIXME '- no selection -' mark for translation |
| 2846 l.append('<option value="%s">- no selection -</option>' | 2845 l.append('<option value="%s">- no selection -</option>' |
| 2847 % ','.join(['-' + v for v in value])) | 2846 % ','.join(['-' + v for v in value])) |
| 2871 if optionid in value or option in value: | 2870 if optionid in value or option in value: |
| 2872 s = 'selected="selected" ' | 2871 s = 'selected="selected" ' |
| 2873 | 2872 |
| 2874 # figure the label | 2873 # figure the label |
| 2875 if showid: | 2874 if showid: |
| 2876 lab = '%s%s: %s'%(self._prop.classname, optionid, option) | 2875 lab = '%s%s: %s' % (self._prop.classname, optionid, option) |
| 2877 else: | 2876 else: |
| 2878 lab = option | 2877 lab = option |
| 2879 # truncate if it's too long | 2878 # truncate if it's too long |
| 2880 if size is not None and len(lab) > size: | 2879 if size is not None and len(lab) > size: |
| 2881 lab = lab[:size-3] + '...' | 2880 lab = lab[:size-3] + '...' |
| 2882 if additional: | 2881 if additional: |
| 2883 m = [] | 2882 m = [] |
| 2884 for fn in additional_fns: | 2883 for fn in additional_fns: |
| 2885 m.append(str(fn(optionid))) | 2884 m.append(str(fn(optionid))) |
| 2886 lab = lab + ' (%s)'%', '.join(m) | 2885 lab = lab + ' (%s)' % ', '.join(m) |
| 2887 | 2886 |
| 2888 # and generate | 2887 # and generate |
| 2889 tr = str | 2888 tr = str |
| 2890 if translate: | 2889 if translate: |
| 2891 tr = self._ | 2890 tr = self._ |
| 2892 lab = html_escape(tr(lab)) | 2891 lab = html_escape(tr(lab)) |
| 2893 l.append('<option %svalue="%s">%s</option>'%(s, optionid, | 2892 l.append('<option %svalue="%s">%s</option>' % (s, optionid, |
| 2894 lab)) | 2893 lab)) |
| 2895 l.append('</select>') | 2894 l.append('</select>') |
| 2896 return '\n'.join(l) | 2895 return '\n'.join(l) |
| 2897 | 2896 |
| 2898 | 2897 |
| 2899 # set the propclasses for HTMLItem | 2898 # set the propclasses for HTMLItem |
| 2973 - "filter" properties to filter the index on | 2972 - "filter" properties to filter the index on |
| 2974 - "filterspec" values to filter the index on | 2973 - "filterspec" values to filter the index on |
| 2975 - "search_text" text to perform a full-text search on for an index | 2974 - "search_text" text to perform a full-text search on for an index |
| 2976 """ | 2975 """ |
| 2977 def __repr__(self): | 2976 def __repr__(self): |
| 2978 return '<HTMLRequest %r>'%self.__dict__ | 2977 return '<HTMLRequest %r>' % self.__dict__ |
| 2979 | 2978 |
| 2980 def __init__(self, client): | 2979 def __init__(self, client): |
| 2981 # _client is needed by HTMLInputMixin | 2980 # _client is needed by HTMLInputMixin |
| 2982 self._client = self.client = client | 2981 self._client = self.client = client |
| 2983 | 2982 |
| 3016 """ | 3015 """ |
| 3017 fields = [] | 3016 fields = [] |
| 3018 dirs = [] | 3017 dirs = [] |
| 3019 for special in '@:': | 3018 for special in '@:': |
| 3020 idx = 0 | 3019 idx = 0 |
| 3021 key = '%s%s%d'%(special, name, idx) | 3020 key = '%s%s%d' % (special, name, idx) |
| 3022 while self._form_has_key(key): | 3021 while self._form_has_key(key): |
| 3023 self.special_char = special | 3022 self.special_char = special |
| 3024 fields.append(self.form.getfirst(key)) | 3023 fields.append(self.form.getfirst(key)) |
| 3025 dirkey = '%s%sdir%d'%(special, name, idx) | 3024 dirkey = '%s%sdir%d' % (special, name, idx) |
| 3026 if dirkey in self.form: | 3025 if dirkey in self.form: |
| 3027 dirs.append(self.form.getfirst(dirkey)) | 3026 dirs.append(self.form.getfirst(dirkey)) |
| 3028 else: | 3027 else: |
| 3029 dirs.append(None) | 3028 dirs.append(None) |
| 3030 idx += 1 | 3029 idx += 1 |
| 3031 key = '%s%s%d'%(special, name, idx) | 3030 key = '%s%s%d' % (special, name, idx) |
| 3032 # backward compatible (and query) URL format | 3031 # backward compatible (and query) URL format |
| 3033 key = special + name | 3032 key = special + name |
| 3034 dirkey = key + 'dir' | 3033 dirkey = key + 'dir' |
| 3035 if self._form_has_key(key) and not fields: | 3034 if self._form_has_key(key) and not fields: |
| 3036 fields = handleListCGIValue(self.form[key]) | 3035 fields = handleListCGIValue(self.form[key]) |
| 3052 else: | 3051 else: |
| 3053 dir, propname = '+', f | 3052 dir, propname = '+', f |
| 3054 # if no classname, just append the propname unchecked. | 3053 # if no classname, just append the propname unchecked. |
| 3055 # this may be valid for some actions that bypass classes. | 3054 # this may be valid for some actions that bypass classes. |
| 3056 if self.classname and cls.get_transitive_prop(propname) is None: | 3055 if self.classname and cls.get_transitive_prop(propname) is None: |
| 3057 self.client.add_error_message("Unknown %s property %s"%(name, propname)) | 3056 self.client.add_error_message("Unknown %s property %s" % ( |
| 3057 name, propname)) | |
| 3058 else: | 3058 else: |
| 3059 var.append((dir, propname)) | 3059 var.append((dir, propname)) |
| 3060 | 3060 |
| 3061 def _form_has_key(self, name): | 3061 def _form_has_key(self, name): |
| 3062 try: | 3062 try: |
| 3173 """ Return a description of the request - handle for the page title. | 3173 """ Return a description of the request - handle for the page title. |
| 3174 """ | 3174 """ |
| 3175 s = [self.client.db.config.TRACKER_NAME] | 3175 s = [self.client.db.config.TRACKER_NAME] |
| 3176 if self.classname: | 3176 if self.classname: |
| 3177 if self.client.nodeid: | 3177 if self.client.nodeid: |
| 3178 s.append('- %s%s'%(self.classname, self.client.nodeid)) | 3178 s.append('- %s%s' % (self.classname, self.client.nodeid)) |
| 3179 else: | 3179 else: |
| 3180 if self.template == 'item': | 3180 if self.template == 'item': |
| 3181 s.append('- new %s'%self.classname) | 3181 s.append('- new %s' % self.classname) |
| 3182 elif self.template == 'index': | 3182 elif self.template == 'index': |
| 3183 s.append('- %s index'%self.classname) | 3183 s.append('- %s index' % self.classname) |
| 3184 else: | 3184 else: |
| 3185 s.append('- %s %s'%(self.classname, self.template)) | 3185 s.append('- %s %s' % (self.classname, self.template)) |
| 3186 else: | 3186 else: |
| 3187 s.append('- home') | 3187 s.append('- home') |
| 3188 return ' '.join(s) | 3188 return ' '.join(s) |
| 3189 | 3189 |
| 3190 def __str__(self): | 3190 def __str__(self): |
| 3191 d = {} | 3191 d = {} |
| 3192 d.update(self.__dict__) | 3192 d.update(self.__dict__) |
| 3193 f = '' | 3193 f = '' |
| 3194 for k in self.form.keys(): | 3194 for k in self.form.keys(): |
| 3195 f += '\n %r=%r'%(k, handleListCGIValue(self.form[k])) | 3195 f += '\n %r=%r' % (k, handleListCGIValue(self.form[k])) |
| 3196 d['form'] = f | 3196 d['form'] = f |
| 3197 e = '' | 3197 e = '' |
| 3198 for k, v in self.env.items(): | 3198 for k, v in self.env.items(): |
| 3199 e += '\n %r=%r'%(k, v) | 3199 e += '\n %r=%r' % (k, v) |
| 3200 d['env'] = e | 3200 d['env'] = e |
| 3201 return """ | 3201 return """ |
| 3202 form: %(form)s | 3202 form: %(form)s |
| 3203 base: %(base)r | 3203 base: %(base)r |
| 3204 classname: %(classname)r | 3204 classname: %(classname)r |
| 3209 filter: %(filter)r | 3209 filter: %(filter)r |
| 3210 search_text: %(search_text)r | 3210 search_text: %(search_text)r |
| 3211 pagesize: %(pagesize)r | 3211 pagesize: %(pagesize)r |
| 3212 startwith: %(startwith)r | 3212 startwith: %(startwith)r |
| 3213 env: %(env)s | 3213 env: %(env)s |
| 3214 """%d | 3214 """ % d |
| 3215 | 3215 |
| 3216 def indexargs_form(self, columns=1, sort=1, group=1, filter=1, | 3216 def indexargs_form(self, columns=1, sort=1, group=1, filter=1, |
| 3217 filterspec=1, search_text=1, exclude=[]): | 3217 filterspec=1, search_text=1, exclude=[]): |
| 3218 """ return the current index args as form elements | 3218 """ return the current index args as form elements |
| 3219 | 3219 |
| 3282 dispname otherwise the parameter will be omitted | 3282 dispname otherwise the parameter will be omitted |
| 3283 from the url. | 3283 from the url. |
| 3284 """ | 3284 """ |
| 3285 q = urllib_.quote | 3285 q = urllib_.quote |
| 3286 sc = self.special_char | 3286 sc = self.special_char |
| 3287 l = ['%s=%s'%(k, is_us(v) and q(v) or v) | 3287 l = ['%s=%s' % (k, is_us(v) and q(v) or v) |
| 3288 for k, v in args.items() if v is not None] | 3288 for k, v in args.items() if v is not None] |
| 3289 # pull out the special values (prefixed by @ or :) | 3289 # pull out the special values (prefixed by @ or :) |
| 3290 specials = {} | 3290 specials = {} |
| 3291 for key in args.keys(): | 3291 for key in args.keys(): |
| 3292 if key[0] in '@:': | 3292 if key[0] in '@:': |
| 3293 specials[key[1:]] = args[key] | 3293 specials[key[1:]] = args[key] |
| 3294 | 3294 |
| 3295 # ok, now handle the specials we received in the request | 3295 # ok, now handle the specials we received in the request |
| 3296 if self.columns and 'columns' not in specials: | 3296 if self.columns and 'columns' not in specials: |
| 3297 l.append(sc+'columns=%s'%(','.join(self.columns))) | 3297 l.append(sc+'columns=%s' % (','.join(self.columns))) |
| 3298 if self.sort and 'sort' not in specials: | 3298 if self.sort and 'sort' not in specials: |
| 3299 val = [] | 3299 val = [] |
| 3300 for dir, attr in self.sort: | 3300 for dir, attr in self.sort: |
| 3301 if dir == '-': | 3301 if dir == '-': |
| 3302 val.append('-'+attr) | 3302 val.append('-'+attr) |
| 3303 else: | 3303 else: |
| 3304 val.append(attr) | 3304 val.append(attr) |
| 3305 l.append(sc+'sort=%s'%(','.join(val))) | 3305 l.append(sc+'sort=%s' % (','.join(val))) |
| 3306 if self.group and 'group' not in specials: | 3306 if self.group and 'group' not in specials: |
| 3307 val = [] | 3307 val = [] |
| 3308 for dir, attr in self.group: | 3308 for dir, attr in self.group: |
| 3309 if dir == '-': | 3309 if dir == '-': |
| 3310 val.append('-'+attr) | 3310 val.append('-'+attr) |
| 3311 else: | 3311 else: |
| 3312 val.append(attr) | 3312 val.append(attr) |
| 3313 l.append(sc+'group=%s'%(','.join(val))) | 3313 l.append(sc+'group=%s' % (','.join(val))) |
| 3314 if self.filter and 'filter' not in specials: | 3314 if self.filter and 'filter' not in specials: |
| 3315 l.append(sc+'filter=%s'%(','.join(self.filter))) | 3315 l.append(sc+'filter=%s' % (','.join(self.filter))) |
| 3316 if self.search_text and 'search_text' not in specials: | 3316 if self.search_text and 'search_text' not in specials: |
| 3317 l.append(sc+'search_text=%s'%q(self.search_text)) | 3317 l.append(sc+'search_text=%s' % q(self.search_text)) |
| 3318 if 'pagesize' not in specials: | 3318 if 'pagesize' not in specials: |
| 3319 l.append(sc+'pagesize=%s'%self.pagesize) | 3319 l.append(sc+'pagesize=%s' % self.pagesize) |
| 3320 if 'startwith' not in specials: | 3320 if 'startwith' not in specials: |
| 3321 l.append(sc+'startwith=%s'%self.startwith) | 3321 l.append(sc+'startwith=%s' % self.startwith) |
| 3322 | 3322 |
| 3323 # finally, the remainder of the filter args in the request | 3323 # finally, the remainder of the filter args in the request |
| 3324 if self.classname and self.filterspec: | 3324 if self.classname and self.filterspec: |
| 3325 cls = self.client.db.getclass(self.classname) | 3325 cls = self.client.db.getclass(self.classname) |
| 3326 for k, v in self.filterspec.items(): | 3326 for k, v in self.filterspec.items(): |
| 3327 if k not in args: | 3327 if k not in args: |
| 3328 if isinstance(v, list): | 3328 if isinstance(v, list): |
| 3329 prop = cls.get_transitive_prop(k) | 3329 prop = cls.get_transitive_prop(k) |
| 3330 if k != 'id' and isinstance(prop, hyperdb.String): | 3330 if k != 'id' and isinstance(prop, hyperdb.String): |
| 3331 l.append('%s=%s'%(k, '%20'.join([q(i) for i in v]))) | 3331 l.append('%s=%s' % ( |
| 3332 k, '%20'.join([q(i) for i in v]))) | |
| 3332 else: | 3333 else: |
| 3333 l.append('%s=%s'%(k, ','.join([q(i) for i in v]))) | 3334 l.append('%s=%s' % ( |
| 3335 k, ','.join([q(i) for i in v]))) | |
| 3334 else: | 3336 else: |
| 3335 l.append('%s=%s'%(k, q(v))) | 3337 l.append('%s=%s' % (k, q(v))) |
| 3336 return '%s?%s'%(url, '&'.join(l)) | 3338 return '%s?%s' % (url, '&'.join(l)) |
| 3337 indexargs_href = indexargs_url | 3339 indexargs_href = indexargs_url |
| 3338 | 3340 |
| 3339 def base_javascript(self): | 3341 def base_javascript(self): |
| 3340 return """ | 3342 return """ |
| 3341 <script nonce="%s" type="text/javascript"> | 3343 <script nonce="%s" type="text/javascript"> |
| 3352 function help_window(helpurl, width, height) { | 3354 function help_window(helpurl, width, height) { |
| 3353 HelpWin = window.open('%s' + helpurl, 'RoundupHelpWindow', 'scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width); | 3355 HelpWin = window.open('%s' + helpurl, 'RoundupHelpWindow', 'scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width); |
| 3354 HelpWin.focus () | 3356 HelpWin.focus () |
| 3355 } | 3357 } |
| 3356 </script> | 3358 </script> |
| 3357 """%(self._client.client_nonce, self.base) | 3359 """ % (self._client.client_nonce, self.base) |
| 3358 | 3360 |
| 3359 def batch(self, permission='View'): | 3361 def batch(self, permission='View'): |
| 3360 """ Return a batch object for results from the "current search" | 3362 """ Return a batch object for results from the "current search" |
| 3361 """ | 3363 """ |
| 3362 check = self._client.db.security.hasPermission | 3364 check = self._client.db.security.hasPermission |
| 3590 | 3592 |
| 3591 # navigation | 3593 # navigation |
| 3592 # month | 3594 # month |
| 3593 res.append('<table class="calendar"><tr><td>') | 3595 res.append('<table class="calendar"><tr><td>') |
| 3594 res.append(' <table width="100%" class="calendar_nav"><tr>') | 3596 res.append(' <table width="100%" class="calendar_nav"><tr>') |
| 3595 link = "&display=%s"%date_prev_month | 3597 link = "&display=%s" % date_prev_month |
| 3596 if date_prev_month: | 3598 if date_prev_month: |
| 3597 res.append(' <td><a href="%s&display=%s"><</a></td>' | 3599 res.append(' <td><a href="%s&display=%s"><</a></td>' |
| 3598 % (base_link, date_prev_month)) | 3600 % (base_link, date_prev_month)) |
| 3599 else: | 3601 else: |
| 3600 res.append(' <td></td>') | 3602 res.append(' <td></td>') |
| 3601 res.append(' <td>%s</td>'%calendar.month_name[display.month]) | 3603 res.append(' <td>%s</td>' % calendar.month_name[display.month]) |
| 3602 if date_next_month: | 3604 if date_next_month: |
| 3603 res.append(' <td><a href="%s&display=%s">></a></td>' | 3605 res.append(' <td><a href="%s&display=%s">></a></td>' |
| 3604 % (base_link, date_next_month)) | 3606 % (base_link, date_next_month)) |
| 3605 else: | 3607 else: |
| 3606 res.append(' <td></td>') | 3608 res.append(' <td></td>') |
| 3610 if date_prev_year: | 3612 if date_prev_year: |
| 3611 res.append(' <td><a href="%s&display=%s"><</a></td>' | 3613 res.append(' <td><a href="%s&display=%s"><</a></td>' |
| 3612 % (base_link, date_prev_year)) | 3614 % (base_link, date_prev_year)) |
| 3613 else: | 3615 else: |
| 3614 res.append(' <td></td>') | 3616 res.append(' <td></td>') |
| 3615 res.append(' <td>%s</td>'%display.year) | 3617 res.append(' <td>%s</td>' % display.year) |
| 3616 if date_next_year: | 3618 if date_next_year: |
| 3617 res.append(' <td><a href="%s&display=%s">></a></td>' | 3619 res.append(' <td><a href="%s&display=%s">></a></td>' |
| 3618 % (base_link, date_next_year)) | 3620 % (base_link, date_next_year)) |
| 3619 else: | 3621 else: |
| 3620 res.append(' <td></td>') | 3622 res.append(' <td></td>') |
| 3623 | 3625 |
| 3624 # the calendar | 3626 # the calendar |
| 3625 res.append(' <tr><td><table class="calendar_display">') | 3627 res.append(' <tr><td><table class="calendar_display">') |
| 3626 res.append(' <tr class="weekdays">') | 3628 res.append(' <tr class="weekdays">') |
| 3627 for day in calendar.weekheader(3).split(): | 3629 for day in calendar.weekheader(3).split(): |
| 3628 res.append(' <td>%s</td>'%day) | 3630 res.append(' <td>%s</td>' % day) |
| 3629 res.append(' </tr>') | 3631 res.append(' </tr>') |
| 3630 for week in calendar.monthcalendar(display.year, display.month): | 3632 for week in calendar.monthcalendar(display.year, display.month): |
| 3631 res.append(' <tr>') | 3633 res.append(' <tr>') |
| 3632 for day in week: | 3634 for day in week: |
| 3633 link = "javascript:form[field].value = '%d-%02d-%02d'; " \ | 3635 link = "javascript:form[field].value = '%d-%02d-%02d'; " \ |
| 3634 "if ('createEvent' in document) { var evt = document.createEvent('HTMLEvents'); evt.initEvent('change', true, true); form[field].dispatchEvent(evt); } else { form[field].fireEvent('onchange'); }" \ | 3636 "if ('createEvent' in document) { var evt = document.createEvent('HTMLEvents'); evt.initEvent('change', true, true); form[field].dispatchEvent(evt); } else { form[field].fireEvent('onchange'); }" \ |
| 3635 "window.close ();"%(display.year, display.month, day) | 3637 "window.close ();" % (display.year, display.month, day) |
| 3636 if (day == curr_date.day and display.month == curr_date.month | 3638 if (day == curr_date.day and display.month == curr_date.month |
| 3637 and display.year == curr_date.year): | 3639 and display.year == curr_date.year): |
| 3638 # highlight | 3640 # highlight |
| 3639 style = "today" | 3641 style = "today" |
| 3640 else: | 3642 else: |
| 3641 style = "" | 3643 style = "" |
| 3642 if day: | 3644 if day: |
| 3643 res.append(' <td class="%s"><a href="%s">%s</a></td>'%( | 3645 res.append(' <td class="%s"><a href="%s">%s</a></td>' % ( |
| 3644 style, link, day)) | 3646 style, link, day)) |
| 3645 else: | 3647 else: |
| 3646 res.append(' <td></td>') | 3648 res.append(' <td></td>') |
| 3647 res.append(' </tr>') | 3649 res.append(' </tr>') |
| 3648 res.append('</table></td></tr></table>') | 3650 res.append('</table></td></tr></table>') |
| 3672 # Python 2 compatibility: | 3674 # Python 2 compatibility: |
| 3673 __nonzero__ = __bool__ | 3675 __nonzero__ = __bool__ |
| 3674 def __contains__(self, key): return False | 3676 def __contains__(self, key): return False |
| 3675 def __eq__(self, rhs): return False | 3677 def __eq__(self, rhs): return False |
| 3676 def __ne__(self, rhs): return False | 3678 def __ne__(self, rhs): return False |
| 3677 def __str__(self): return '[%s]'%self.__description | 3679 def __str__(self): return '[%s]' % self.__description |
| 3678 def __repr__(self): return '<MissingValue 0x%x "%s">'%(id(self), | 3680 def __repr__(self): return '<MissingValue 0x%x "%s">' % ( |
| 3679 self.__description) | 3681 id(self), self.__description) |
| 3680 | 3682 |
| 3681 def gettext(self, str): return str | 3683 def gettext(self, str): return str |
| 3682 _ = gettext | 3684 _ = gettext |
| 3683 | 3685 |
| 3684 # vim: set et sts=4 sw=4 : | 3686 # vim: set et sts=4 sw=4 : |
