Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 2327:36ae1b14aaab
remove excessive spaces in the translatable strings;
trim trailing spaces in code
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Tue, 18 May 2004 19:23:44 +0000 |
| parents | da4444e593f4 |
| children | fbbda3b1816d |
comparison
equal
deleted
inserted
replaced
| 2326:27e4478df7c0 | 2327:36ae1b14aaab |
|---|---|
| 1 """Implements the API used in the HTML templating for the web interface. | 1 """Implements the API used in the HTML templating for the web interface. |
| 2 """ | 2 """ |
| 3 | 3 |
| 4 todo = ''' | 4 todo = ''' |
| 5 - Most methods should have a "default" arg to supply a value | 5 - Most methods should have a "default" arg to supply a value |
| 6 when none appears in the hyperdb or request. | 6 when none appears in the hyperdb or request. |
| 7 - Multilink property additions: change_note and new_upload | 7 - Multilink property additions: change_note and new_upload |
| 8 - Add class.find() too | 8 - Add class.find() too |
| 9 - NumberHTMLProperty should support numeric operations | 9 - NumberHTMLProperty should support numeric operations |
| 10 - LinkHTMLProperty should handle comparisons to strings (cf. linked name) | 10 - LinkHTMLProperty should handle comparisons to strings (cf. linked name) |
| 11 ''' | 11 ''' |
| 173 *request* | 173 *request* |
| 174 Includes information about the current request, including: | 174 Includes information about the current request, including: |
| 175 | 175 |
| 176 - the url | 176 - the url |
| 177 - the current index information (``filterspec``, ``filter`` args, | 177 - the current index information (``filterspec``, ``filter`` args, |
| 178 ``properties``, etc) parsed out of the form. | 178 ``properties``, etc) parsed out of the form. |
| 179 - methods for easy filterspec link generation | 179 - methods for easy filterspec link generation |
| 180 - *user*, the current user node as an HTMLItem instance | 180 - *user*, the current user node as an HTMLItem instance |
| 181 - *form*, the current CGI form information as a FieldStorage | 181 - *form*, the current CGI form information as a FieldStorage |
| 182 *config* | 182 *config* |
| 183 The current tracker config. | 183 The current tracker config. |
| 548 | 548 |
| 549 def classhelp(self, properties=None, label='(list)', width='500', | 549 def classhelp(self, properties=None, label='(list)', width='500', |
| 550 height='400', property=''): | 550 height='400', property=''): |
| 551 ''' Pop up a javascript window with class help | 551 ''' Pop up a javascript window with class help |
| 552 | 552 |
| 553 This generates a link to a popup window which displays the | 553 This generates a link to a popup window which displays the |
| 554 properties indicated by "properties" of the class named by | 554 properties indicated by "properties" of the class named by |
| 555 "classname". The "properties" should be a comma-separated list | 555 "classname". The "properties" should be a comma-separated list |
| 556 (eg. 'id,name,description'). Properties defaults to all the | 556 (eg. 'id,name,description'). Properties defaults to all the |
| 557 properties of a class (excluding id, creator, created and | 557 properties of a class (excluding id, creator, created and |
| 558 activity). | 558 activity). |
| 663 return '%s%s'%(self._classname, self._nodeid) | 663 return '%s%s'%(self._classname, self._nodeid) |
| 664 | 664 |
| 665 def is_retired(self): | 665 def is_retired(self): |
| 666 """Is this item retired?""" | 666 """Is this item retired?""" |
| 667 return self._klass.is_retired(self._nodeid) | 667 return self._klass.is_retired(self._nodeid) |
| 668 | 668 |
| 669 def submit(self, label="Submit Changes"): | 669 def submit(self, label="Submit Changes"): |
| 670 """Generate a submit button. | 670 """Generate a submit button. |
| 671 | 671 |
| 672 Also sneak in the lastactivity and action hidden elements. | 672 Also sneak in the lastactivity and action hidden elements. |
| 673 """ | 673 """ |
| 720 pass | 720 pass |
| 721 else: | 721 else: |
| 722 id = self._klass.get(self._nodeid, prop_n, None) | 722 id = self._klass.get(self._nodeid, prop_n, None) |
| 723 current[prop_n] = '<a href="%s%s">%s</a>'%( | 723 current[prop_n] = '<a href="%s%s">%s</a>'%( |
| 724 classname, id, current[prop_n]) | 724 classname, id, current[prop_n]) |
| 725 | 725 |
| 726 for id, evt_date, user, action, args in history: | 726 for id, evt_date, user, action, args in history: |
| 727 date_s = str(evt_date.local(timezone)).replace("."," ") | 727 date_s = str(evt_date.local(timezone)).replace("."," ") |
| 728 arg_s = '' | 728 arg_s = '' |
| 729 if action == 'link' and type(args) == type(()): | 729 if action == 'link' and type(args) == type(()): |
| 730 if len(args) == 3: | 730 if len(args) == 3: |
| 751 prop = self._props[k] | 751 prop = self._props[k] |
| 752 except KeyError: | 752 except KeyError: |
| 753 prop = None | 753 prop = None |
| 754 if prop is None: | 754 if prop is None: |
| 755 # property no longer exists | 755 # property no longer exists |
| 756 comments['no_exist'] = _('''<em>The indicated property | 756 comments['no_exist'] = _( |
| 757 no longer exists</em>''') | 757 "<em>The indicated property no longer exists</em>") |
| 758 cell.append('<em>%s: %s</em>\n'%(k, str(args[k]))) | 758 cell.append('<em>%s: %s</em>\n'%(k, str(args[k]))) |
| 759 continue | 759 continue |
| 760 | 760 |
| 761 if args[k] and (isinstance(prop, hyperdb.Multilink) or | 761 if args[k] and (isinstance(prop, hyperdb.Multilink) or |
| 762 isinstance(prop, hyperdb.Link)): | 762 isinstance(prop, hyperdb.Link)): |
| 764 classname = prop.classname | 764 classname = prop.classname |
| 765 try: | 765 try: |
| 766 linkcl = self._db.getclass(classname) | 766 linkcl = self._db.getclass(classname) |
| 767 except KeyError: | 767 except KeyError: |
| 768 labelprop = None | 768 labelprop = None |
| 769 comments[classname] = _('''The linked class | 769 comments[classname] = _( |
| 770 %(classname)s no longer exists''')%locals() | 770 "The linked class %(classname)s no longer exists" |
| 771 ) % locals() | |
| 771 labelprop = linkcl.labelprop(1) | 772 labelprop = linkcl.labelprop(1) |
| 772 try: | 773 try: |
| 773 template = find_template(self._db.config.TEMPLATES, | 774 template = find_template(self._db.config.TEMPLATES, |
| 774 classname, 'item') | 775 classname, 'item') |
| 775 if template[1].startswith('_generic'): | 776 if template[1].startswith('_generic'): |
| 796 try: | 797 try: |
| 797 if labelprop is not None and \ | 798 if labelprop is not None and \ |
| 798 labelprop != 'id': | 799 labelprop != 'id': |
| 799 label = linkcl.get(linkid, labelprop) | 800 label = linkcl.get(linkid, labelprop) |
| 800 except IndexError: | 801 except IndexError: |
| 801 comments['no_link'] = _('''<strike>The | 802 comments['no_link'] = _( |
| 802 linked node no longer | 803 "<strike>The linked node" |
| 803 exists</strike>''') | 804 " no longer exists</strike>") |
| 804 subml.append('<strike>%s</strike>'%label) | 805 subml.append('<strike>%s</strike>'%label) |
| 805 else: | 806 else: |
| 806 if hrefable: | 807 if hrefable: |
| 807 subml.append('<a href="%s%s">%s</a>'%( | 808 subml.append('<a href="%s%s">%s</a>'%( |
| 808 classname, linkid, label)) | 809 classname, linkid, label)) |
| 817 # there's no labelprop! | 818 # there's no labelprop! |
| 818 if labelprop is not None and labelprop != 'id': | 819 if labelprop is not None and labelprop != 'id': |
| 819 try: | 820 try: |
| 820 label = linkcl.get(args[k], labelprop) | 821 label = linkcl.get(args[k], labelprop) |
| 821 except IndexError: | 822 except IndexError: |
| 822 comments['no_link'] = _('''<strike>The | 823 comments['no_link'] = _( |
| 823 linked node no longer | 824 "<strike>The linked node" |
| 824 exists</strike>''') | 825 " no longer exists</strike>") |
| 825 cell.append(' <strike>%s</strike>,\n'%label) | 826 cell.append(' <strike>%s</strike>,\n'%label) |
| 826 # "flag" this is done .... euwww | 827 # "flag" this is done .... euwww |
| 827 label = None | 828 label = None |
| 828 if label is not None: | 829 if label is not None: |
| 829 if hrefable: | 830 if hrefable: |
| 877 current[k] = str(args[k]) | 878 current[k] = str(args[k]) |
| 878 | 879 |
| 879 arg_s = '<br />'.join(cell) | 880 arg_s = '<br />'.join(cell) |
| 880 else: | 881 else: |
| 881 # unkown event!! | 882 # unkown event!! |
| 882 comments['unknown'] = _('''<strong><em>This event is not | 883 comments['unknown'] = _("<strong><em>This event is not handled" |
| 883 handled by the history display!</em></strong>''') | 884 " by the history display!</em></strong>") |
| 884 arg_s = '<strong><em>' + str(args) + '</em></strong>' | 885 arg_s = '<strong><em>' + str(args) + '</em></strong>' |
| 885 date_s = date_s.replace(' ', ' ') | 886 date_s = date_s.replace(' ', ' ') |
| 886 # if the user's an itemid, figure the username (older journals | 887 # if the user's an itemid, figure the username (older journals |
| 887 # have the username) | 888 # have the username) |
| 888 if dre.match(user): | 889 if dre.match(user): |
| 1069 ''' Render a "hyperlinked" version of the text ''' | 1070 ''' Render a "hyperlinked" version of the text ''' |
| 1070 return self.plain(hyperlink=1) | 1071 return self.plain(hyperlink=1) |
| 1071 | 1072 |
| 1072 def plain(self, escape=0, hyperlink=0): | 1073 def plain(self, escape=0, hyperlink=0): |
| 1073 '''Render a "plain" representation of the property | 1074 '''Render a "plain" representation of the property |
| 1074 | 1075 |
| 1075 - "escape" turns on/off HTML quoting | 1076 - "escape" turns on/off HTML quoting |
| 1076 - "hyperlink" turns on/off in-text hyperlinking of URLs, email | 1077 - "hyperlink" turns on/off in-text hyperlinking of URLs, email |
| 1077 addresses and designators | 1078 addresses and designators |
| 1078 ''' | 1079 ''' |
| 1079 self.view_check() | 1080 self.view_check() |
| 1181 return self.input(type="password", name=self._formname, size=size) | 1182 return self.input(type="password", name=self._formname, size=size) |
| 1182 | 1183 |
| 1183 return self.plain() | 1184 return self.plain() |
| 1184 | 1185 |
| 1185 def confirm(self, size = 30): | 1186 def confirm(self, size = 30): |
| 1186 ''' Render a second form edit field for the property, used for | 1187 ''' Render a second form edit field for the property, used for |
| 1187 confirmation that the user typed the password correctly. Generates | 1188 confirmation that the user typed the password correctly. Generates |
| 1188 a field with name "@confirm@name". | 1189 a field with name "@confirm@name". |
| 1189 | 1190 |
| 1190 If not editable, display nothing. | 1191 If not editable, display nothing. |
| 1191 ''' | 1192 ''' |
| 1314 value = cgi.escape(str(self._value.local(tz))) | 1315 value = cgi.escape(str(self._value.local(tz))) |
| 1315 | 1316 |
| 1316 if self.is_edit_ok(): | 1317 if self.is_edit_ok(): |
| 1317 value = '"'.join(value.split('"')) | 1318 value = '"'.join(value.split('"')) |
| 1318 return self.input(name=self._formname,value=value,size=size) | 1319 return self.input(name=self._formname,value=value,size=size) |
| 1319 | 1320 |
| 1320 return self.plain() | 1321 return self.plain() |
| 1321 | 1322 |
| 1322 def reldate(self, pretty=1): | 1323 def reldate(self, pretty=1): |
| 1323 ''' Render the interval between the date and now. | 1324 ''' Render the interval between the date and now. |
| 1324 | 1325 |
| 1480 k = linkcl.labelprop(1) | 1481 k = linkcl.labelprop(1) |
| 1481 s = '' | 1482 s = '' |
| 1482 if value is None: | 1483 if value is None: |
| 1483 s = 'selected="selected" ' | 1484 s = 'selected="selected" ' |
| 1484 l.append(_('<option %svalue="-1">- no selection -</option>')%s) | 1485 l.append(_('<option %svalue="-1">- no selection -</option>')%s) |
| 1485 if linkcl.getprops().has_key('order'): | 1486 if linkcl.getprops().has_key('order'): |
| 1486 sort_on = ('+', 'order') | 1487 sort_on = ('+', 'order') |
| 1487 else: | 1488 else: |
| 1488 if sort_on is None: | 1489 if sort_on is None: |
| 1489 sort_on = ('+', linkcl.labelprop()) | 1490 sort_on = ('+', linkcl.labelprop()) |
| 1490 else: | 1491 else: |
| 1491 sort_on = ('+', sort_on) | 1492 sort_on = ('+', sort_on) |
| 1492 options = linkcl.filter(None, conditions, sort_on, (None, None)) | 1493 options = linkcl.filter(None, conditions, sort_on, (None, None)) |
| 1537 if self._value: | 1538 if self._value: |
| 1538 self._value = lookupIds(self._db, self._prop, self._value, | 1539 self._value = lookupIds(self._db, self._prop, self._value, |
| 1539 fail_ok=1) | 1540 fail_ok=1) |
| 1540 sortfun = make_sort_function(self._db, self._prop.classname) | 1541 sortfun = make_sort_function(self._db, self._prop.classname) |
| 1541 self._value.sort(sortfun) | 1542 self._value.sort(sortfun) |
| 1542 | 1543 |
| 1543 def __len__(self): | 1544 def __len__(self): |
| 1544 ''' length of the multilink ''' | 1545 ''' length of the multilink ''' |
| 1545 return len(self._value) | 1546 return len(self._value) |
| 1546 | 1547 |
| 1547 def __getattr__(self, attr): | 1548 def __getattr__(self, attr): |
| 1852 self.startwith = int(self.form[name].value) | 1853 self.startwith = int(self.form[name].value) |
| 1853 | 1854 |
| 1854 def updateFromURL(self, url): | 1855 def updateFromURL(self, url): |
| 1855 ''' Parse the URL for query args, and update my attributes using the | 1856 ''' Parse the URL for query args, and update my attributes using the |
| 1856 values. | 1857 values. |
| 1857 ''' | 1858 ''' |
| 1858 env = {'QUERY_STRING': url} | 1859 env = {'QUERY_STRING': url} |
| 1859 self.form = cgi.FieldStorage(environ=env) | 1860 self.form = cgi.FieldStorage(environ=env) |
| 1860 | 1861 |
| 1861 self._post_init() | 1862 self._post_init() |
| 1862 | 1863 |
| 2070 # overwrite so we can late-instantiate the HTMLItem instance | 2071 # overwrite so we can late-instantiate the HTMLItem instance |
| 2071 def __getitem__(self, index): | 2072 def __getitem__(self, index): |
| 2072 if index < 0: | 2073 if index < 0: |
| 2073 if index + self.end < self.first: raise IndexError, index | 2074 if index + self.end < self.first: raise IndexError, index |
| 2074 return self._sequence[index + self.end] | 2075 return self._sequence[index + self.end] |
| 2075 | 2076 |
| 2076 if index >= self.length: | 2077 if index >= self.length: |
| 2077 raise IndexError, index | 2078 raise IndexError, index |
| 2078 | 2079 |
| 2079 # move the last_item along - but only if the fetched index changes | 2080 # move the last_item along - but only if the fetched index changes |
| 2080 # (for some reason, index 0 is fetched twice) | 2081 # (for some reason, index 0 is fetched twice) |
