Author: justi9
Date: 2008-03-27 16:17:14 -0400 (Thu, 27 Mar 2008)
New Revision: 1808
Modified:
mgmt/cumin/python/cumin/widgets.py
mgmt/cumin/python/cumin/widgets.strings
mgmt/cumin/python/wooly/widgets.py
mgmt/cumin/python/wooly/widgets.strings
Log:
Move Paginator from cumin to wooly
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2008-03-27 18:51:34 UTC (rev 1807)
+++ mgmt/cumin/python/cumin/widgets.py 2008-03-27 20:17:14 UTC (rev 1808)
@@ -305,124 +305,6 @@
return sql
-class Paginator(ItemSet):
- def __init__(self, app, name):
- super(Paginator, self).__init__(app, name)
-
- self.__page = IntegerParameter(app, "page")
- self.__page.default = 0
- self.add_parameter(self.__page)
-
- self.__pageset = IntegerParameter(app, "pageset")
- self.__pageset.default = 0
- self.add_parameter(self.__pageset)
-
- self.__count = Attribute(app, "count")
- self.add_attribute(self.__count)
-
- self.page_size = 15
- self.pageset_size = 5
-
- def get_bounds(self, session):
- page = self.__page.get(session)
- return self.page_size * page, self.page_size * (page + 1)
-
- def get_pageset_bounds(self, session):
- pageset = self.__pageset.get(session)
- return self.pageset_size * pageset, self.pageset_size * (pageset + 1)
-
- def set_count(self, session, count):
- return self.__count.set(session, count)
-
- def get_count(self, session):
- return self.__count.get(session)
-
- def get_page_count(self, session):
- count = self.get_count(session)
- return int(ceil(count / float(self.page_size)))
-
- def get_pageset_count(self, session):
- page_count = self.get_page_count(session)
- return int(ceil(page_count / float(self.pageset_size)))
-
- def render_prev_page_link(self, session, *args):
- page = self.__page.get(session)
-
- if page < 1:
- html = fmt_link(session.marshal(), "<", "pagenav
disabled")
- else:
- page -= 1
- pageset_start = self.get_pageset_bounds(session)[0]
-
- branch = session.branch()
- self.__page.set(branch, page)
- if page < pageset_start:
- self.__pageset.set(branch, self.__pageset.get(session) - 1)
- html = fmt_link(branch.marshal(), "<", "pagenav")
-
- return html
-
- def render_next_page_link(self, session, *args):
- page = self.__page.get(session)
-
- if page >= self.get_page_count(session) - 1:
- html = fmt_link(session.marshal(), ">", "pagenav
disabled")
- else:
- page += 1
- pageset_end = self.get_pageset_bounds(session)[1]
-
- branch = session.branch()
- self.__page.set(branch, page)
- if page >= pageset_end: # XXX should be >? bounds func is funny
- self.__pageset.set(branch, self.__pageset.get(session) + 1)
- html = fmt_link(branch.marshal(), ">", "pagenav")
-
- return html
-
- def render_prev_pageset_link(self, session, *args):
- pageset = self.__pageset.get(session)
-
- if pageset < 1:
- html = fmt_link(session.marshal(), "<<",
"pagenav disabled")
- else:
- branch = session.branch()
- self.__pageset.set(branch, pageset - 1)
- html = fmt_link(branch.marshal(), "<<",
"pagenav")
-
- return html
-
- def render_next_pageset_link(self, session, *args):
- pageset = self.__pageset.get(session)
-
- if pageset >= self.get_pageset_count(session) - 1:
- html = fmt_link(session.marshal(), ">>",
"pagenav disabled")
- else:
- branch = session.branch()
- self.__pageset.set(branch, pageset + 1)
- html = fmt_link(branch.marshal(), ">>",
"pagenav")
-
- return html
-
- def do_get_items(self, session, *args):
- count = self.__count.get(session)
-
- start, end = self.get_pageset_bounds(session)
- page_count = self.get_page_count(session)
-
- return range(start, min(end, page_count))
-
- def render_item_class_attr(self, session, page):
- if self.__page.get(session) == page:
- return " class=\"selected\""
-
- def render_item_href(self, session, page):
- branch = session.branch()
- self.__page.set(branch, page)
- return branch.marshal()
-
- def render_item_content(self, session, page):
- return page + 1
-
class CuminTable(SqlTable):
def __init__(self, app, name):
super(CuminTable, self).__init__(app, name)
Modified: mgmt/cumin/python/cumin/widgets.strings
===================================================================
--- mgmt/cumin/python/cumin/widgets.strings 2008-03-27 18:51:34 UTC (rev 1807)
+++ mgmt/cumin/python/cumin/widgets.strings 2008-03-27 20:17:14 UTC (rev 1808)
@@ -126,48 +126,6 @@
[StateSwitch.item_html]
<li>{item_link}</li>
-[Paginator.css]
-ul.Paginator {
- display: inline;
- font-size: 0.9em;
-}
-
-ul.Paginator li {
- display: inline;
- margin: 0 0.1em;
-}
-
-ul.Paginator a {
- padding: 0.075em 0.25em;
- border: 1px solid #f7f7f7;
-}
-
-ul.Paginator a:hover {
- border: 1px solid #ddd;
- background-color: white;
-}
-
-ul.Paginator a.pagenav {
- border: 1px solid #ddd;
- color: black;
-}
-
-ul.Paginator a.disabled {
- color: #ccc;
-}
-
-ul.Paginator a.pagenav:hover {
- background-color: white;
-}
-
-[Paginator.html]
-<ul class="Paginator">
-
<li>{prev_pageset_link}</li><li>{prev_page_link}</li>{items}<li>{next_page_link}</li><li>{next_pageset_link}</li>
-</ul>
-
-[Paginator.item_html]
-<li><a {item_class_attr}
href="{item_href}">{item_content}</a></li>
-
[CuminTable.css]
table.mobjects th.setnav {
font-size: 0.9em;
Modified: mgmt/cumin/python/wooly/widgets.py
===================================================================
--- mgmt/cumin/python/wooly/widgets.py 2008-03-27 18:51:34 UTC (rev 1807)
+++ mgmt/cumin/python/wooly/widgets.py 2008-03-27 20:17:14 UTC (rev 1808)
@@ -1,6 +1,8 @@
-from wooly import *
+from math import ceil
+
from parameters import *
from resources import *
+from wooly import *
strings = StringCatalog(__file__)
@@ -196,3 +198,125 @@
self.item_tmpl.render(writer, session, child)
return writer.to_string()
+
+class Paginator(ItemSet):
+ def __init__(self, app, name):
+ super(Paginator, self).__init__(app, name)
+
+ self.__page = IntegerParameter(app, "page")
+ self.__page.default = 0
+ self.add_parameter(self.__page)
+
+ self.__pageset = IntegerParameter(app, "pageset")
+ self.__pageset.default = 0
+ self.add_parameter(self.__pageset)
+
+ self.__count = Attribute(app, "count")
+ self.add_attribute(self.__count)
+
+ self.page_size = 15
+ self.pageset_size = 5
+
+ def get_bounds(self, session):
+ page = self.__page.get(session)
+ return self.page_size * page, self.page_size * (page + 1)
+
+ def get_pageset_bounds(self, session):
+ pageset = self.__pageset.get(session)
+ return self.pageset_size * pageset, self.pageset_size * (pageset + 1)
+
+ def set_count(self, session, count):
+ return self.__count.set(session, count)
+
+ def get_count(self, session):
+ return self.__count.get(session)
+
+ def get_page_count(self, session):
+ count = self.get_count(session)
+ return int(ceil(count / float(self.page_size)))
+
+ def get_pageset_count(self, session):
+ page_count = self.get_page_count(session)
+ return int(ceil(page_count / float(self.pageset_size)))
+
+ def __link(self, href, content, class_=""):
+ return "<a href=\"%s\"%s>%s</a>" % \
+ (href, class_ and " class=\"%s\" " % class_ or "
", content)
+
+ def render_prev_page_link(self, session, *args):
+ page = self.__page.get(session)
+
+ if page < 1:
+ html = self.__link(session.marshal(), "<", "pagenav
disabled")
+ else:
+ page -= 1
+ pageset_start = self.get_pageset_bounds(session)[0]
+
+ branch = session.branch()
+ self.__page.set(branch, page)
+ if page < pageset_start:
+ self.__pageset.set(branch, self.__pageset.get(session) - 1)
+ html = self.__link(branch.marshal(), "<",
"pagenav")
+
+ return html
+
+ def render_next_page_link(self, session, *args):
+ page = self.__page.get(session)
+
+ if page >= self.get_page_count(session) - 1:
+ html = self.__link(session.marshal(), ">", "pagenav
disabled")
+ else:
+ page += 1
+ pageset_end = self.get_pageset_bounds(session)[1]
+
+ branch = session.branch()
+ self.__page.set(branch, page)
+ if page >= pageset_end: # XXX should be >? bounds func is funny
+ self.__pageset.set(branch, self.__pageset.get(session) + 1)
+ html = self.__link(branch.marshal(), ">",
"pagenav")
+
+ return html
+
+ def render_prev_pageset_link(self, session, *args):
+ pageset = self.__pageset.get(session)
+
+ if pageset < 1:
+ html = self.__link(session.marshal(), "<<",
"pagenav disabled")
+ else:
+ branch = session.branch()
+ self.__pageset.set(branch, pageset - 1)
+ html = self.__link(branch.marshal(), "<<",
"pagenav")
+
+ return html
+
+ def render_next_pageset_link(self, session, *args):
+ pageset = self.__pageset.get(session)
+
+ if pageset >= self.get_pageset_count(session) - 1:
+ html = self.__link(session.marshal(), ">>",
"pagenav disabled")
+ else:
+ branch = session.branch()
+ self.__pageset.set(branch, pageset + 1)
+ html = self.__link(branch.marshal(), ">>",
"pagenav")
+
+ return html
+
+ def do_get_items(self, session, *args):
+ count = self.__count.get(session)
+
+ start, end = self.get_pageset_bounds(session)
+ page_count = self.get_page_count(session)
+
+ return range(start, min(end, page_count))
+
+ def render_item_class_attr(self, session, page):
+ if self.__page.get(session) == page:
+ return " class=\"selected\""
+
+ def render_item_href(self, session, page):
+ branch = session.branch()
+ self.__page.set(branch, page)
+ return branch.marshal()
+
+ def render_item_content(self, session, page):
+ return page + 1
Modified: mgmt/cumin/python/wooly/widgets.strings
===================================================================
--- mgmt/cumin/python/wooly/widgets.strings 2008-03-27 18:51:34 UTC (rev 1807)
+++ mgmt/cumin/python/wooly/widgets.strings 2008-03-27 20:17:14 UTC (rev 1808)
@@ -88,3 +88,45 @@
<tr>
{cells}
</tr>
+
+[Paginator.css]
+ul.Paginator {
+ display: inline;
+ font-size: 0.9em;
+}
+
+ul.Paginator li {
+ display: inline;
+ margin: 0 0.1em;
+}
+
+ul.Paginator a {
+ padding: 0.075em 0.25em;
+ border: 1px solid #f7f7f7;
+}
+
+ul.Paginator a:hover {
+ border: 1px solid #ddd;
+ background-color: white;
+}
+
+ul.Paginator a.pagenav {
+ border: 1px solid #ddd;
+ color: black;
+}
+
+ul.Paginator a.disabled {
+ color: #ccc;
+}
+
+ul.Paginator a.pagenav:hover {
+ background-color: white;
+}
+
+[Paginator.html]
+<ul class="Paginator">
+
<li>{prev_pageset_link}</li><li>{prev_page_link}</li>{items}<li>{next_page_link}</li><li>{next_pageset_link}</li>
+</ul>
+
+[Paginator.item_html]
+<li><a {item_class_attr}
href="{item_href}">{item_content}</a></li>