Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 3184:6cd2cbb47fb0 maint-0.8
merge OLD changes from HEAD
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 15 Feb 2005 22:48:14 +0000 |
| parents | 2ac85e66e9bb |
| children | 79bcf944ceb8 |
comparison
equal
deleted
inserted
replaced
| 3181:65bc031c4464 | 3184:6cd2cbb47fb0 |
|---|---|
| 558 def list(self, sort_on=None): | 558 def list(self, sort_on=None): |
| 559 ''' List all items in this class. | 559 ''' List all items in this class. |
| 560 ''' | 560 ''' |
| 561 # get the list and sort it nicely | 561 # get the list and sort it nicely |
| 562 l = self._klass.list() | 562 l = self._klass.list() |
| 563 sortfunc = make_sort_function(self._db, self.classname, sort_on) | 563 sortfunc = make_sort_function(self._db, self._classname, sort_on) |
| 564 l.sort(sortfunc) | 564 l.sort(sortfunc) |
| 565 | 565 |
| 566 l = [HTMLItem(self._client, self.classname, x) for x in l] | 566 # check perms |
| 567 check = self._client.db.security.hasPermission | |
| 568 userid = self._client.userid | |
| 569 | |
| 570 l = [HTMLItem(self._client, self._classname, id) for id in l | |
| 571 if check('View', userid, self._classname, itemid=id)] | |
| 572 | |
| 567 return l | 573 return l |
| 568 | 574 |
| 569 def csv(self): | 575 def csv(self): |
| 570 ''' Return the items of this class as a chunk of CSV text. | 576 ''' Return the items of this class as a chunk of CSV text. |
| 571 ''' | 577 ''' |
| 602 ''' | 608 ''' |
| 603 if request is not None: | 609 if request is not None: |
| 604 filterspec = request.filterspec | 610 filterspec = request.filterspec |
| 605 sort = request.sort | 611 sort = request.sort |
| 606 group = request.group | 612 group = request.group |
| 613 | |
| 614 check = self._db.security.hasPermission | |
| 615 userid = self._client.userid | |
| 616 | |
| 607 l = [HTMLItem(self._client, self.classname, x) | 617 l = [HTMLItem(self._client, self.classname, x) |
| 608 for x in self._klass.filter(None, filterspec, sort, group)] | 618 for id in self._klass.filter(None, filterspec, sort, group) |
| 619 if check('View', userid, self.classname, itemid=id)] | |
| 609 return l | 620 return l |
| 610 | 621 |
| 611 def classhelp(self, properties=None, label=''"(list)", width='500', | 622 def classhelp(self, properties=None, label=''"(list)", width='500', |
| 612 height='400', property='', form='itemSynopsis'): | 623 height='400', property='', form='itemSynopsis'): |
| 613 '''Pop up a javascript window with class help | 624 '''Pop up a javascript window with class help |
| 1674 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) | 1685 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) |
| 1675 l.append('</select>') | 1686 l.append('</select>') |
| 1676 return '\n'.join(l) | 1687 return '\n'.join(l) |
| 1677 # def checklist(self, ...) | 1688 # def checklist(self, ...) |
| 1678 | 1689 |
| 1690 class MultilinkIterator: | |
| 1691 def __init__(self, classname, client, values): | |
| 1692 self.classname = classname | |
| 1693 self.client = client | |
| 1694 self.values = values | |
| 1695 self.id = -1 | |
| 1696 def next(self): | |
| 1697 '''Return the next item, but skip inaccessible items.''' | |
| 1698 check = self.client.db.security.hasPermission | |
| 1699 userid = self.client.userid | |
| 1700 while 1: | |
| 1701 self.id += 1 | |
| 1702 if self.id >= len(self.values): | |
| 1703 raise StopIteration | |
| 1704 value = self.values[self.id] | |
| 1705 if check('View', userid, self.classname, itemid=value): | |
| 1706 return HTMLItem(self.client, self.classname, value) | |
| 1707 def __iter__(self): | |
| 1708 return self | |
| 1709 | |
| 1710 | |
| 1679 class MultilinkHTMLProperty(HTMLProperty): | 1711 class MultilinkHTMLProperty(HTMLProperty): |
| 1680 ''' Multilink HTMLProperty | 1712 ''' Multilink HTMLProperty |
| 1681 | 1713 |
| 1682 Also be iterable, returning a wrapper object like the Link case for | 1714 Also be iterable, returning a wrapper object like the Link case for |
| 1683 each entry in the multilink. | 1715 each entry in the multilink. |
| 1696 | 1728 |
| 1697 def __getattr__(self, attr): | 1729 def __getattr__(self, attr): |
| 1698 ''' no extended attribute accesses make sense here ''' | 1730 ''' no extended attribute accesses make sense here ''' |
| 1699 raise AttributeError, attr | 1731 raise AttributeError, attr |
| 1700 | 1732 |
| 1701 def __getitem__(self, num): | 1733 def __iter__(self): |
| 1702 ''' iterate and return a new HTMLItem | 1734 ''' iterate and return a new HTMLItem |
| 1703 ''' | 1735 ''' |
| 1704 #print 'Multi.getitem', (self, num) | 1736 return MultilinkIterator(self._prop.classname, self._client, |
| 1705 value = self._value[num] | 1737 self._value) |
| 1706 return HTMLItem(self._client, self._prop.classname, value) | 1738 |
| 1739 def reverse(self): | |
| 1740 ''' return the list in reverse order | |
| 1741 ''' | |
| 1742 l = self._value[:] | |
| 1743 l.reverse() | |
| 1744 return MultilinkIterator(self._prop.classname, self._client, l) | |
| 1707 | 1745 |
| 1708 def sorted(self, property): | 1746 def sorted(self, property): |
| 1709 ''' Return this multilink sorted by the given property ''' | 1747 ''' Return this multilink sorted by the given property ''' |
| 1710 value = list(self._value[num]) | 1748 value = list(self.__iter__()) |
| 1711 value.sort(lambda a,b:cmp(a[property], b[property])) | 1749 value.sort(lambda a,b:cmp(a[property], b[property])) |
| 1712 return value | 1750 return value |
| 1713 | 1751 |
| 1714 def __contains__(self, value): | 1752 def __contains__(self, value): |
| 1715 ''' Support the "in" operator. We have to make sure the passed-in | 1753 ''' Support the "in" operator. We have to make sure the passed-in |
| 1718 return str(value) in self._value | 1756 return str(value) in self._value |
| 1719 | 1757 |
| 1720 def isset(self): | 1758 def isset(self): |
| 1721 '''Is my _value not []?''' | 1759 '''Is my _value not []?''' |
| 1722 return self._value != [] | 1760 return self._value != [] |
| 1723 | |
| 1724 def reverse(self): | |
| 1725 ''' return the list in reverse order | |
| 1726 ''' | |
| 1727 l = self._value[:] | |
| 1728 l.reverse() | |
| 1729 return [HTMLItem(self._client, self._prop.classname, value) | |
| 1730 for value in l] | |
| 1731 | 1761 |
| 1732 def plain(self, escape=0): | 1762 def plain(self, escape=0): |
| 1733 ''' Render a "plain" representation of the property | 1763 ''' Render a "plain" representation of the property |
| 1734 ''' | 1764 ''' |
| 1735 if not self.is_view_ok(): | 1765 if not self.is_view_ok(): |
| 1764 value = cgi.escape(','.join(value)) | 1794 value = cgi.escape(','.join(value)) |
| 1765 return self.input(name=self._formname,size=size,value=value) | 1795 return self.input(name=self._formname,size=size,value=value) |
| 1766 | 1796 |
| 1767 def menu(self, size=None, height=None, showid=0, additional=[], | 1797 def menu(self, size=None, height=None, showid=0, additional=[], |
| 1768 sort_on=None, **conditions): | 1798 sort_on=None, **conditions): |
| 1769 ''' Render a form select list for this property | 1799 ''' Render a form <select> list for this property. |
| 1770 | 1800 |
| 1771 "size" is used to limit the length of the list labels | 1801 "size" is used to limit the length of the list labels |
| 1772 "height" is used to set the <select> tag's "size" attribute | 1802 "height" is used to set the <select> tag's "size" attribute |
| 1773 "showid" includes the item ids in the list labels | 1803 "showid" includes the item ids in the list labels |
| 1774 "additional" lists properties which should be included in the | 1804 "additional" lists properties which should be included in the |
| 2181 if self.search_text: | 2211 if self.search_text: |
| 2182 matches = self.client.db.indexer.search( | 2212 matches = self.client.db.indexer.search( |
| 2183 re.findall(r'\b\w{2,25}\b', self.search_text), klass) | 2213 re.findall(r'\b\w{2,25}\b', self.search_text), klass) |
| 2184 else: | 2214 else: |
| 2185 matches = None | 2215 matches = None |
| 2186 l = klass.filter(matches, filterspec, sort, group) | 2216 |
| 2217 # filter for visibility | |
| 2218 check = self._client.db.security.hasPermission | |
| 2219 userid = self._client.userid | |
| 2220 l = [id for id in klass.filter(matches, filterspec, sort, group) | |
| 2221 if check('View', userid, self.classname, itemid=id)] | |
| 2187 | 2222 |
| 2188 # return the batch object, using IDs only | 2223 # return the batch object, using IDs only |
| 2189 return Batch(self.client, l, self.pagesize, self.startwith, | 2224 return Batch(self.client, l, self.pagesize, self.startwith, |
| 2190 classname=self.classname) | 2225 classname=self.classname) |
| 2191 | 2226 |
