commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/appserver/src frontend.py geasSession.py


From: Reinhard Mueller
Subject: gnue/appserver/src frontend.py geasSession.py
Date: Sat, 04 Jan 2003 11:25:32 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Reinhard Mueller <address@hidden>       03/01/04 11:25:31

Modified files:
        appserver/src  : frontend.py geasSession.py 

Log message:
        Implemented "load" function.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/src/frontend.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/src/geasSession.py.diff?tr1=1.15&tr2=1.16&r1=text&r2=text

Patches:
Index: gnue/appserver/src/frontend.py
diff -c gnue/appserver/src/frontend.py:1.4 gnue/appserver/src/frontend.py:1.5
*** gnue/appserver/src/frontend.py:1.4  Wed Jan  1 19:45:40 2003
--- gnue/appserver/src/frontend.py      Sat Jan  4 11:25:30 2003
***************
*** 19,25 ****
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: frontend.py,v 1.4 2003/01/02 00:45:40 jcater Exp $
  
  import os, getpass
  from gnue.common import GClientApp
--- 19,25 ----
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: frontend.py,v 1.5 2003/01/04 16:25:30 reinhard Exp $
  
  import os, getpass
  from gnue.common import GClientApp
***************
*** 87,92 ****
--- 87,93 ----
            % (self.classname, self.server.count (self.session, self.list))
      print
      print "  1 - Display objects"
+     print "  2 - Display more data"
      print "  8 - Request another list"
      print "  9 - Exit"
      print
***************
*** 96,101 ****
--- 97,104 ----
  
        if choice == 1:
          return self.display
+       if choice == 2:
+         return self.more
        elif choice == 8:
          return self.request
        elif choice == 9:
***************
*** 119,129 ****
  
      for index in range (0, count):
        object = rset [index]
!       print "* Object number %d with id %s:" % (start+index, object["_id_"])
        for property in self.propertylist:
          print "*   " + property + ":", object [property]
  
    # 
---------------------------------------------------------------------------
    # Request a list of objects
    # 
---------------------------------------------------------------------------
  
--- 122,177 ----
  
      for index in range (0, count):
        object = rset [index]
!       print "* Object number %d with id %s:" % (start + index, object 
["_id_"])
        for property in self.propertylist:
          print "*   " + property + ":", object [property]
  
    # 
---------------------------------------------------------------------------
+   # Display more data
+   # 
---------------------------------------------------------------------------
+ 
+   def more (self):
+     # select the properties to display
+     propertylist = []
+     while 1:
+       property = raw_input ("? Property to read: ")
+       if property:
+         break
+       print "! Please enter at least one property"
+ 
+     while property:
+       propertylist.append (property)
+       property = raw_input ("? Property to read (empty to finish): ")
+ 
+     # select objects to display
+     start = askint ("Start with object number", "0")
+ 
+     # get maximum possible object count from given start position
+     if start < 0:                       # from end of list
+       maxcount = -start
+     else:
+       maxcount = self.server.count (self.session, self.list) - start
+ 
+     count = askint ("Number of objects to display", "%d" % maxcount)
+ 
+     # first, get all object_ids
+     rset = self.server.fetch (self.session, self.list, start, count)
+     object_ids = []
+     for index in range (0, count):
+       object = rset [index]
+       object_ids.append (object ["_id_"])
+ 
+     # now, we have all object_ids and we can use "load" to get the data
+     rset = self.server.load (self.session, self.classname, object_ids,
+                              propertylist)
+     for index in range (0, count):
+       object = rset [index]
+       print "* Object number %d with id %s:" % (start + index,
+                                                 object_ids [index])
+       for property in propertylist:
+         print "*   " + property + ":", object [property]
+ 
+   # 
---------------------------------------------------------------------------
    # Request a list of objects
    # 
---------------------------------------------------------------------------
  
***************
*** 150,156 ****
        self.propertylist.append (property)
        property = raw_input ("? Property to read (empty to finish): ")
  
-     print "propertylist", self.propertylist
      # TODO: define filter
  
      # select the properties to sort by
--- 198,203 ----
***************
*** 193,199 ****
  class geasLoginHandler (GLoginHandler.LoginHandler):
    def getLogin (self, *arguments):
      # log in as the user "gnue"
!     return {"_username": "gnue", "_password": "(none)"}
  
  # 
=============================================================================
  # Let it rock
--- 240,246 ----
  class geasLoginHandler (GLoginHandler.LoginHandler):
    def getLogin (self, *arguments):
      # log in as the user "gnue"
!     return {"_username": "gnue", "_password": None}
  
  # 
=============================================================================
  # Let it rock
Index: gnue/appserver/src/geasSession.py
diff -c gnue/appserver/src/geasSession.py:1.15 
gnue/appserver/src/geasSession.py:1.16
*** gnue/appserver/src/geasSession.py:1.15      Wed Jan  1 19:45:41 2003
--- gnue/appserver/src/geasSession.py   Sat Jan  4 11:25:30 2003
***************
*** 19,25 ****
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: geasSession.py,v 1.15 2003/01/02 00:45:41 jcater Exp $
  
  import geasList
  import geasTrigger 
--- 19,25 ----
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: geasSession.py,v 1.16 2003/01/04 16:25:30 reinhard Exp $
  
  import geasList
  import geasTrigger 
***************
*** 171,194 ****
    # Fetch data from the database backend
    # 
---------------------------------------------------------------------------
  
!   def fetch(self,list_id,start,count):
!     rset=[]
!     c=0
!     row=self._lists[list_id].firstInstance ()
!     while (row!=None) and (c<start+count):
!       if c>=start:
!         rrow={}
!         for field in self._lists[list_id]._prefetch:
!           rrow[field]=row.get(field)
!         rset.append(rrow)
!         
!       c+=1
!       row=self._lists[list_id].nextInstance ()
!     
!     return rset;
! 
!   def load(self,classname,obj_id_list,propertylist):
!     return self._getClass(classname).load(self,obj_id_list,propertylist)
          
    def store(self,classname,obj_id_list,propertylist,data):
      return self._getClass(classname).store(obj_id_list,propertylist,data)
--- 171,212 ----
    # Fetch data from the database backend
    # 
---------------------------------------------------------------------------
  
!   def fetch (self, list_id, start, count):
!     list = self._lists [list_id]
!     result = []
!     c = 0
!     object = list.firstInstance ()
!     while (object != None) and (c < start + count):
!       if c >= start:
!         row = {}
!         for property in list._prefetch:
!           row [property] = object.get (property)
!         result.append (row)
!       c += 1
!       object = list.nextInstance ()
!     return result
! 
!   # 
---------------------------------------------------------------------------
!   # Load data from the database backend
!   # 
---------------------------------------------------------------------------
! 
!   def load (self, classname, obj_id_list, propertylist):
!     # create a temporary geasList
!     list = geasList.geasList (self, classname)
!     list.setPrefetch (["_id_"] + propertylist)
!     list.setSort (["_id_"])
!     # Accessing the database for every single object_id is not very elegant,
!     # but for now it works. -- Reinhard
!     result = []
!     for object_id in obj_id_list:
!       list.setConditions ("= _id_ %s" % object_id)
!       list.populate ()
!       object = list.firstInstance ()
!       row = {}
!       for property in propertylist:
!         row [property] = object.get (property)
!       result.append (row)
!     return result
          
    def store(self,classname,obj_id_list,propertylist,data):
      return self._getClass(classname).store(obj_id_list,propertylist,data)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]