merge
authorArthur Lutz <arthur.lutz@logilab.fr>
Wed, 11 Feb 2009 17:44:08 +0100
changeset 598 4705ceb624cc
parent 597 f8c1f8a40749 (diff)
parent 587 c8ff5d88f164 (current diff)
child 599 9ef680acd92a
merge
--- a/common/selectors.py	Wed Feb 11 17:43:33 2009 +0100
+++ b/common/selectors.py	Wed Feb 11 17:44:08 2009 +0100
@@ -161,13 +161,20 @@
 def paginated_rset(cls, req, rset, *args, **kwargs):
     """accept result sets with more rows than the page size
     """
-    if rset is None or len(rset) <= req.property_value('navigation.page-size'):
+    page_size = kwargs.get('page_size')
+    if page_size is None:
+        page_size = req.form.get('page_size')
+        if page_size is None:
+            page_size = req.property_value('navigation.page-size')
+        else:
+            page_size = int(page_size)
+    if rset is None or len(rset) <= page_size:
         return 0
     return 1
 largerset_selector = deprecated_function(paginated_rset)
 
 @lltrace
-def sorted_rset(cls, req, rset, row=None, col=None):
+def sorted_rset(cls, req, rset, row=None, col=None, **kwargs):
     """accept sorted result set"""
     rqlst = rset.syntax_tree()
     if len(rqlst.children) > 1 or not rqlst.children[0].orderby:
--- a/entities/authobjs.py	Wed Feb 11 17:43:33 2009 +0100
+++ b/entities/authobjs.py	Wed Feb 11 17:44:08 2009 +0100
@@ -93,6 +93,13 @@
         """
         return self.matching_groups(group) == 1
 
+    def is_anonymous(self):
+        """ checks if user is an anonymous user"""
+        #FIXME on the web-side anonymous user is detected according
+        # to config['anonymous-user'], we don't have this info on
+        # the server side. 
+        return self.groups == frozenset(('guests', ))
+
     def owns(self, eid):
         if hasattr(self.req, 'unsafe_execute'):
             # use unsafe_execute on the repository side, in case
--- a/server/repository.py	Wed Feb 11 17:43:33 2009 +0100
+++ b/server/repository.py	Wed Feb 11 17:44:08 2009 +0100
@@ -490,7 +490,7 @@
         session = self.internal_session()
         try:
             if session.execute('EUser X WHERE X login %(login)s', {'login': login}):
-                return
+                return False
             # we have to create the user
             user = self.vreg.etype_class('EUser')(session, None)
             if isinstance(password, unicode):
@@ -505,6 +505,7 @@
             session.commit()
         finally:
             session.close()
+        return True
         
     def connect(self, login, password, cnxprops=None):
         """open a connection for a given user
--- a/web/component.py	Wed Feb 11 17:43:33 2009 +0100
+++ b/web/component.py	Wed Feb 11 17:44:08 2009 +0100
@@ -73,6 +73,19 @@
     selected_page_link_templ = u'<span class="selectedSlice"><a href="%s" title="%s">%s</a></span>'
     previous_page_link_templ = next_page_link_templ = page_link_templ
     no_previous_page_link = no_next_page_link = u''
+
+    @classmethod
+    def selected(cls, req, rset, row=None, col=None, page_size=None, **kwargs):
+        """by default web app objects are usually instantiated on
+        selection according to a request, a result set, and optional
+        row and col
+        """
+        instance = super(NavigationComponent, cls).selected(req, rset, row, col, **kwargs)
+        if page_size is not None:
+            instance.page_size = page_size
+        elif 'page_size' in req.form:
+            instance.page_size = int(req.form['page_size'])
+        return instance
     
     def __init__(self, req, rset):
         super(NavigationComponent, self).__init__(req, rset)
--- a/web/views/basetemplates.py	Wed Feb 11 17:43:33 2009 +0100
+++ b/web/views/basetemplates.py	Wed Feb 11 17:44:08 2009 +0100
@@ -7,11 +7,13 @@
 """
 __docformat__ = "restructuredtext en"
 
+
 from logilab.mtconverter import html_escape
 
 from cubicweb import NoSelectableObject, ObjectNotFound
 from cubicweb.common.view import Template, MainTemplate,  NOINDEX, NOFOLLOW
 from cubicweb.common.utils import make_uid
+from cubicweb.common.utils import UStringIO
 
 from cubicweb.web.views.baseviews import vid_from_rset
 
@@ -73,6 +75,7 @@
     - guess and call an appropriate view through the view manager
     """
     id = 'main'
+    nav_html = UStringIO()
 
     def _select_view_and_rset(self):
         req = self.req
@@ -162,7 +165,9 @@
                                                  self.req, self.rset)
         if etypefilter and etypefilter.propval('visible'):
             etypefilter.dispatch(w=self.w)
-        self.pagination(self.req, self.rset, self.w, not (view and view.need_navigation))
+        self.pagination(self.req, self.rset, self.nav_html.write,
+                        not (view and view.need_navigation))
+        self.w(_(self.nav_html.getvalue()))
         self.w(u'<div id="contentmain">\n')
     
     def template_html_header(self, content_type, page_title, additional_headers=()):
@@ -198,6 +203,7 @@
             
     def template_footer(self, view=None):
         self.w(u'</div>\n') # close id=contentmain
+        self.w(_(self.nav_html.getvalue()))
         self.w(u'</div>\n') # closes id=pageContent
         self.content_footer(view)
         self.w(u'</td>\n')
--- a/web/views/navigation.py	Wed Feb 11 17:43:33 2009 +0100
+++ b/web/views/navigation.py	Wed Feb 11 17:44:08 2009 +0100
@@ -36,15 +36,17 @@
         while start < rset.rowcount:
             stop = min(start + page_size - 1, rset.rowcount - 1)
             blocklist.append(self.page_link(basepath, params, start, stop,
-                                            u'%s - %s' % (start+1, stop+1)))
+                                            self.index_display(start, stop)))
             start = stop + 1
         w(u'<div class="pagination">')
         w(u'%s&nbsp;' % self.previous_link(params))
         w(u'[&nbsp;%s&nbsp;]' % u'&nbsp;| '.join(blocklist))
         w(u'&nbsp;%s' % self.next_link(params))
         w(u'</div>')
+        
+    def index_display(self, start, stop):
+        return u'%s - %s' % (start+1, stop+1)
 
-    
 class SortedNavigation(NavigationComponent):
     """sorted navigation apply if navigation is needed (according to page size)
     and if the result set is sorted
@@ -142,9 +144,11 @@
         self.w(u'</div>')
 
 
-def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False, show_all_option=True):
+def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False,
+                               show_all_option=True, page_size = None):
     showall = forcedisplay or req.form.get('__force_display') is not None
-    nav = not showall and self.vreg.select_component('navigation', req, rset)
+    nav = not showall and self.vreg.select_component('navigation', req, rset,
+                                                     page_size=page_size)
     if nav:
         # get boundaries before component rendering
         start, stop = nav.page_boundaries()