Changeset 221

Show
Ignore:
Timestamp:
Sat Oct 7 14:58:36 2006
Author:
Alexander
Message:

Server: implemented SaveLocalChanges?; minor bug fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
  • server/trunk/update/server/ganttpv_update_server.py

    r216 r221  
    256 256  
    257 257 def get_next_ids():  
    258       result = Data.Database["NextID"]  
    259       return result  
      258     nextids = Data.Database["NextID"]  
      259     for col, v in nextids.items():  
      260         if v is None:  
      261             if debug: print "Deleting None item from: NextID", col  
      262             del nextids[col]  
      263     return nextids  
    260 264  
    261 265 def do_reserve_row_ids(rows_needed):  
     
    281 285     if ischange:  
    282 286         SaveDatabase()  
    283       nextids = Data.NextID  # it returns all, not just the ones requested  
    284       return nextids  
      287     return get_next_ids()  
    285 288  
    286 289 def reserve_row_ids(parms, rows_needed):  
     
    434 437         #             
    435 438         NonesOut(c)  
    436       SetUndo("")  # server's version of SetUndo, not Data's  
    437                    # to avoid undo stack, any other reason?  
    438 439  
    439 440     # append update to array and update "LastUpdateApplied" - what name to use?  
    440 441     if debug: print "applied all changes, adding changes to _Updates", changes, len(GetUpdates())  
    441 442     GetUpdates().append(changes)  # add to other updates  
    442       database["Other"][1]["LastChange"] = len(GetUpdates())  # number of updates  
      443     Data.Other["LastChange"] = len(GetUpdates())  # number of updates  
      444  
      445     SetUndo("")  # server's version of SetUndo; processes local changes  
    443 446  
    444 447     # only one update can be processed at a time  
     
    476 479     for tid, t in tables:  
    477 480         if tid[0] == "_": continue  # skip server internal tables  
    478    
    479           if tid == 'Next': continue  # this is the new name, handled via NextID and prep database  
    480 481          
    481 482         alias = None  # identify aliases (thanks for the code Alex!)  
     
    491 492  
    492 493         if tid in ["NextID", ]:  # list of special tables  
      494             for col, v in data.items():  
      495                if v is None:  
      496                    if debug: print "Deleting None item from: ", tid, col  
      497                    del data[col]  
    493 498             exceptions[tid] = t  
    494 499             continue  
     
    496 501         for rid, data in t.items():  # get rid of Nones for xmlrpclib  
    497 502            for col, v in data.items():  
    498                  if v == None:  
      503                if v is None:  
    498 503                    if debug: print "Deleting None item from: ", tid, rid, col  
    499 504                    del data[col]  
    500            
      505  
    500 505         # most tables can be handled like this?  
    501 506         tkeys = t.keys()  # easier to verify in testing  
     
    668 673 def SaveLocalChanges():  
    669 674     """ Use the UndoStack to capture the server's own changes. """  
    670    
      675     if debug: print "begin SaveLocalChanges"  
    670 675     delta = {}  
    671 676     while Data.UndoStack:  
    672 677         undo = Data.UndoStack.pop()  
    673           if not isinstance(undo, dict):  
    674               continue  
      678         if isinstance(undo, basestring): continue  
    675 679         key = (undo['Table'], undo['ID'])  
    676 680         if key in delta:  
     
    679 683         else:  
    680 684             delta[key] = undo  
      685     if debug: print "changed records:", delta.keys()  
    681 686  
    682       updates = GetUpdates()  
      687     changes = []  
    682 687     for (table, id), undo in delta.iteritems():  
    683           change = {}  
      688         c = {'Table': table, 'ID': id}  
    683 688         for k, v in undo.iteritems():  
    684               change['_' + k] = v  
    685               change[k] = Data.Database[table][id][k]  
    686           updates.append(change)  
      689             if k in ['Table', 'ID']: continue  
      690             c['_' + k] = v  
      691             c[k] = Data.Database[table][id].get(k)  
      692         NonesOut(c)  
      693         changes.append(c)  
      694     GetUpdates().append(changes)  
      695     if debug: print "end SaveLocalChanges"  
    687 696  
    688 697 def SetUndo(s):  # equivalent of Data.SetUndo  
     
    698 707     if UpdateGantt:  
    699 708         Data.GanttCalculation(); Data.ChangedSchedule = False  
    700   # There is a problem with report rows  
    701 709     if Data.ChangedRow:  
    702 710         Data.AdjustReportRows(); Data.ChangedRow = False  
    703 711     Data.ChangedData = True  # file needs to be saved  
    704       # SaveLocalChanges()  
      712     SaveLocalChanges()  
      713 Data.SetUndo = SetUndo  
    705 714  
    706 715 # avoid some xmlrpc problems with Nones  
     
    717 726 def NonesOut(dict):  
    718 727     for k, v in dict.items():  
    719           if v == None:  
      728         if v is None:  
    719 728             del dict[k]  
    720 729  
     
    773 782     db[1]['Changes'] = []  
    774 783     db[1]['Info'] = {}  # should save information about update (source, etc.)  
    775                                       # anywhere else version number must be reset?  
      784                               # anywhere else version number must be reset?  
    775 784  
    776 785 def GetUpdates():  
     
    879 888         try:  
    880 889             server = SimpleXMLRPCServer.SimpleXMLRPCServer((server_ip, server_port))  
      890             print "Found socket"  
    881 891         except socket.error, (value,message):  
    882 892             print "Couldn't get the socket: ", message  
    883               time.sleep(10)  # wait 10 seconds before trying again  
      893             time.sleep(10)  # wait this many seconds before trying again  
    883 893             tries -= 1  
    884 894             if tries < 1:  
  • server/trunk/update/server/HTML.py

    r216 r221  
    263 263     for webkey, signature, key in rlist:  
    264 264         db = served.get(signature)  # the database that corresponds to this key  
    265           webname = db.database['Other'][1].get('WebName')  
    266 265         if db:  
      266             webname = db.database['Other'][1].get('WebName')  
    267 267             fp.write('<tr><td class="body">')  
    268 268             fp.write((webname or "Database") + (" (%d)" % (signature % 1000)))