Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 3194:f887e55edc94
replaced MutlilinkIterator with multilinkGenerator (thanks Bob Ippolito)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 16 Feb 2005 03:32:26 +0000 |
| parents | 7faae85e1e33 |
| children | 0b7990f54778 |
comparison
equal
deleted
inserted
replaced
| 3191:008596732188 | 3194:f887e55edc94 |
|---|---|
| 1685 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) | 1685 l.append('<option %svalue="%s">%s</option>'%(s, optionid, lab)) |
| 1686 l.append('</select>') | 1686 l.append('</select>') |
| 1687 return '\n'.join(l) | 1687 return '\n'.join(l) |
| 1688 # def checklist(self, ...) | 1688 # def checklist(self, ...) |
| 1689 | 1689 |
| 1690 class MultilinkIterator: | 1690 |
| 1691 def __init__(self, classname, client, values): | 1691 def multilinkGenerator(classname, client, values): |
| 1692 self.classname = classname | 1692 id = -1 |
| 1693 self.client = client | 1693 check = client.db.security.hasPermission |
| 1694 self.values = values | 1694 userid = client.userid |
| 1695 self.id = -1 | 1695 while 1: |
| 1696 def next(self): | 1696 id += 1 |
| 1697 '''Return the next item, but skip inaccessible items.''' | 1697 if id >= len(values): |
| 1698 check = self.client.db.security.hasPermission | 1698 raise StopIteration |
| 1699 userid = self.client.userid | 1699 value = values[id] |
| 1700 while 1: | 1700 if check('View', userid, classname, itemid=value): |
| 1701 self.id += 1 | 1701 yield HTMLItem(client, classname, value) |
| 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 | 1702 |
| 1710 | 1703 |
| 1711 class MultilinkHTMLProperty(HTMLProperty): | 1704 class MultilinkHTMLProperty(HTMLProperty): |
| 1712 ''' Multilink HTMLProperty | 1705 ''' Multilink HTMLProperty |
| 1713 | 1706 |
| 1731 raise AttributeError, attr | 1724 raise AttributeError, attr |
| 1732 | 1725 |
| 1733 def __iter__(self): | 1726 def __iter__(self): |
| 1734 ''' iterate and return a new HTMLItem | 1727 ''' iterate and return a new HTMLItem |
| 1735 ''' | 1728 ''' |
| 1736 return MultilinkIterator(self._prop.classname, self._client, | 1729 return multilinkGenerator(self._prop.classname, self._client, |
| 1737 self._value) | 1730 self._value) |
| 1738 | 1731 |
| 1739 def reverse(self): | 1732 def reverse(self): |
| 1740 ''' return the list in reverse order | 1733 ''' return the list in reverse order |
| 1741 ''' | 1734 ''' |
| 1742 l = self._value[:] | 1735 l = self._value[:] |
| 1743 l.reverse() | 1736 l.reverse() |
| 1744 return MultilinkIterator(self._prop.classname, self._client, l) | 1737 return multilinkGenerator(self._prop.classname, self._client, l) |
| 1745 | 1738 |
| 1746 def sorted(self, property): | 1739 def sorted(self, property): |
| 1747 ''' Return this multilink sorted by the given property ''' | 1740 ''' Return this multilink sorted by the given property ''' |
| 1748 value = list(self.__iter__()) | 1741 value = list(self.__iter__()) |
| 1749 value.sort(lambda a,b:cmp(a[property], b[property])) | 1742 value.sort(lambda a,b:cmp(a[property], b[property])) |
