Changeset 176

Show
Ignore:
Timestamp:
Sat Aug 26 15:50:22 2006
Author:
Alexander
Message:

merge client and server versions of Data.py

Files:

Legend:

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

    r126 r176  
    93 93 # 060506 - Alex - allow dependencies between parent tasks  
    94 94 # 060520 - Alex - fix holiday bugs; added AddColumn, AddReport, and GetSuggestedColumns  
      95 # 060603 - Brian - identify current platform  
      96 # 060709 - Brian - add ability to create aliases in Update  
      97 # 060723 - Brian - translate column type labels  
      98 # 060725 - Alex - added AddAlias and UpdateAliases  
      99 # 060802 - Brian - added Task's StartHour to check change  
    95 100  
    96 101 import datetime, calendar  
     
    111 116 # 3- Use SetUndo to tell GanttPV to fix anything in response to the changes  
    112 117  
      118 if sys.platform.startswith("darwin"):  
      119     platform = "mac"  
      120 elif sys.platform.startswith("win32"):  
      121     platform = "win"  
      122 elif sys.platform.startswith("linux"):  
      123     platform = "linux"  
      124 else:  
      125     platform = "other"  
      126  
    113 127 # this is the Data only version  
    114 128 # it is overriden by ReportAids.py  
     
    588 602         Database['NextID'][name] = 1  
    589 603  
      604 def AddAlias(alias, tableName):  
      605     """ Create an alias to an existing table """  
      606     # (Note: this isn't reversed by Undo.)  
      607     change = {'Table': 'TableAlias', 'ID': 1, alias: tableName}  
      608     Update(change, 0)  
      609  
    590 610 def AddRow(change):  
    591 611     """ Add or update row """  
     
    744 764  
    745 765 # ---------  
    746   def FindID(table, field1, value1, field2=None, value2=None):  # deprecated  
      766 def GetTableNames():  
      767     return [name for name in NextID  
      768             if not name.startswith('_') and name != 'ID']  
      769  
      770 def FindID(table, field1, value1, field2=None, value2=None):  # deprecated v0.7  
    747 771     search = {field1: value1, field2: value2}  
    748 772     return SearchByColumn(Database.get(table), search, True)  
    749 773  
    750   def FindIDs(table, field1, value1, field2=None, value2=None):  # deprecated  
      774 def FindIDs(table, field1, value1, field2=None, value2=None): # deprecated v0.6  
    750 774     search = {field1: value1, field2: value2}  
    751 775     return SearchByColumn(Database.get(table), search).keys()  
     
    805 829     elif ChangedSchedule: pass  
    806 830     elif change['Table'] == 'Task':  
    807           for k in ('StartDate', 'DurationHours', 'zzStatus', 'ProjectID', 'TaskID'):  
      831         for k in ('StartDate', 'DurationHours', 'zzStatus', 'ProjectID', 'TaskID', 'StartHour'):  
    807 831             if change.has_key(k): ChangedSchedule = True; break  
    808 832     elif change['Table'] == 'Dependency':  
     
    939 963         if len(undo) > 2:  
    940 964             CheckChange(undo)  
    941    
    942           if change['Table'] == 'ForeignKey':  # add alias to table if needed  
    943               for k, v in change:  
    944                   if k in ('Table', 'ID', 'zzStatus'): continue  # these don't define foreign keys  
    945                   if k.count('/') != 1: continue  # format is tablename/columnname  
    946                   part = k.split('/')[1]  # get the column name  
    947                   if len(part) < 3 or part[-2:] != 'ID': continue  # these would be invalid foreign keys  
    948                   if not v or v not in Database: continue  # can't define an alias to non existent table  
    949                   alias = part[:-2]  
    950                   if alias not in Database or Database[alias] != Database[v]:  
    951                       Database[alias] = Database[v]  # define alias  
    952 965     else:  
    953 966         record = {}  
     
    964 977         CheckChange(undo)  
    965 978         table[id] = record  
      979  
      980     if change['Table'] == 'TableAlias':  # add aliases if needed  
      981         tableNames = GetTableNames()  
      982         for k, v in change.iteritems():  
      983             if k in ('Table', 'ID', 'zzStatus'):  # not an alias  
      984                 continue  
      985             if (k in tableNames) or (v not in tableNames):  # invalid alias  
      986                 continue  
      987             Database[k] = Database[v]  
    966 988     if push: UndoStack.append(undo)  
    967 989     return undo  
     
    1375 1397  
    1376 1398     ps = {}  # project start dates indexed by project id  
    1377       ProjectStartHour = {}; ProjectEndHour = {}  
    1378       for k, v in Project.iteritems():  
    1379           if v.get('zzStatus') == 'deleted': continue  
    1380           sd = v.get('StartDate')  
    1381           # if debug: print "project", k, ", startdate", sd  
    1382           if not (sd and sd in DateConv): sd = Today  # default project start dates to today  
    1383           ps[k] = sd  
    1384    
    1385           # convert project start dates to hours format  
    1386           si = DateConv[sd]  # get starting date index  
    1387           sh = DateInfo[si][1]  # get cum hours for start date  
    1388           ProjectStartHour[k] = sh  
    1389           if debug: "project, start hour", k, sh  
    1390           ProjectEndHour[k] = 0  # prepare to save project end hour  
    1391    
    1392       # dependencies  
    1393 1399     pre = {}  # task prerequisites indexed by task id number  
    1394 1400     suc = {}  # task successors  
     
    1411 1417         tpid[k] = pid  
    1412 1418         tsd = v.get('StartDate')  
    1413           if tsd and (tsd < ps[pid]) and (tsd in DateConv):  
    1414               # adjust project start date if task starts earlier  
    1415               ps[pid] = tsd  
      1419         if tsd and (tsd in DateConv):  
      1420             if (pid not in ps) or (tsd < ps[pid]):  
      1421                 # project start date defaults to earliest task  
      1422                 ps[pid] = tsd  
    1416 1423  
    1417 1424         p = v.get('TaskID')  # parent task id  
     
    1430 1437         ancestry[k] = anc  
    1431 1438  
      1439     ProjectStartHour = {}; ProjectEndHour = {}  
      1440     for k, v in Project.iteritems():  
      1441         if v.get('zzStatus') == 'deleted': continue  
      1442         sd = v.get('StartDate')  
      1443         # if debug: print "project", k, ", startdate", sd  
      1444         if not (sd and sd in DateConv):  
      1445             # default to earliest task if possible; otherwise, default to today  
      1446             sd = ps.get(k, Today)  
      1447  
      1448         # convert project start dates to hours format  
      1449         si = DateConv[sd]  # get starting date index  
      1450         sh = DateInfo[si][1]  # get cum hours for start date  
      1451         ProjectStartHour[k] = sh  
      1452         if debug: "project, start hour", k, sh  
      1453         ProjectEndHour[k] = 0  # prepare to save project end hour  
      1454  
      1455     # find dependencies  
    1432 1456     for k, v in Dependency.iteritems():  
    1433 1457         # if debug: print "dependency record", v  
     
    1490 1514                 moretodo = True  # make another pass through the tasks  
    1491 1515  
    1492                   # calculate early start for task  
    1493                   es = ProjectStartHour[tpid[k]]  
    1494                   for t in pre[k]:  
    1495                       ef = Task[t]["hEF"]  
    1496                       if ef > es: es = ef  
    1497                   # if start date was specified, use it if possible  
    1498                   # note: the end date is not currently used to compute a start date  
      1516                 # get task information  
      1517                 # note: end date is not currently used to compute a start date  
    1499 1518                 tsd = Task[k].get('StartDate')  
    1500                   tsdh = Task[k].get('StartHour') or 0  # allow specification of the starting hour  
      1519                 tsdh = Task[k].get('StartHour') or 0  
    1500 1519                 ted = Task[k].get('EndDate')  
    1501 1520                 td  = Task[k].get('DurationHours')  
      1521  
      1522                 # calculate early start for task  
    1502 1523                 if tsd and DateConv.has_key(tsd):  
    1503 1524                     tsi = DateConv[tsd]  # date index  
    1504 1525                     tsh = DateInfo[tsi][1]  # date hour  
    1505 1526                     tsh += tsdh  # adjust the starting hour of the day  
    1506                       if tsh > es: es = tsh  # use the date if dependencies allow  
      1527                     es = tsh  
      1528                 else:  
      1529                     es = ProjectStartHour[tpid[k]]  
      1530  
      1531                 # consider task dependencies  
      1532                 for t in pre[k]:  
      1533                     ef = Task[t]["hEF"]  
      1534                     if ef > es: es = ef  
    1507 1535  
    1508 1536                 # calculate early finish  
     
    1689 1717                 ct = ColumnType[ctid]  
    1690 1718                 label = ct.get('Label') or ct.get('Name')  
      1719                 if label:  
      1720                     label = _(label)  
    1691 1721         else:  
    1692 1722             name1 = name2 = ''  
     
    1764 1794                     vals = [str(x) for x in vals if x != None]  
    1765 1795                     value = ", ".join(vals)  
    1766               elif at in ('role'):  
      1796             elif at == 'role':  
    1766 1796                 record = Database[rtable][tid]  
    1767 1797                 path = ct.get('Path') or ct.get('Name')  
     
    1781 1811                         vals.append(v)  
    1782 1812                 value = ", ".join(vals)  
    1783               elif at == 'list':  # deprecated  
      1813             elif at == 'list':  # deprecated v0.7  
    1783 1813                 try:  
    1784 1814                     listcol, listtable, listselect, listtarget, listtable2, listcol2 = ct.get('Path').split('/')  # path to values  
     
    2124 2154     return ids  
    2125 2155  
    2126   def GetRowLevels(reportid, showHidden=False):  
      2156 def GetRowLevels(reportid, showHidden=True):  
    2126 2156     """ Return two lists: row ids and row levels (ie - ancestor counts) """  
    2127 2157     rlist = GetRowList(reportid)  
     
    2435 2465     ActiveReport = id  
    2436 2466  
      2467 def UpdateAliases():  
      2468     """ Refresh the list of table aliases """  
      2469     for alias, aTable in Database.iteritems():  
      2470         for tname in GetTableNames():  
      2471             if Database.get(tname) is aTable and (alias != tname):  
      2472                 AddAlias(alias, tname)  
      2473                 break  
      2474  
    2437 2475 def PrepDatabase():  
    2438 2476     """ After an database has been loaded or created, set all other values to match """  
     
    2452 2490     ReportType =    Database['ReportType']  
    2453 2491     ColumnType =    Database['ColumnType']  
    2454       OtherData =     Database['OtherData']  
    2455       Other =         OtherData[1]  
    2456 2492     NextID =        Database['NextID']  
    2457 2493  
    2458       Database['Other'] = OtherData  
    2459           # OtherData and Database['OtherData'] are deprecated  
    2460    
    2461       if 'Next' not in Database:  
    2462           Database['Next'] = {1: NextID}  # Database['NextID'] is deprecated  
    2463    
      2494     Database['Other'] = OtherData = Database['OtherData']  
      2495         # OtherData and Database['OtherData'] are deprecated v0.6  
      2496     if 'Other' not in NextID:  
      2497         NextID['Other'] = 2  
      2498     Other = OtherData[1]  
    2464 2499     if not Other.get('FileSignature'):  
    2465 2500         Other['FileSignature'] = random.randint(1, 1000000000)  
    2466 2501  
      2502     if 'TableAlias' not in Database:  
      2503         AddTable('TableAlias')  
      2504         Update({'Table': 'TableAlias'})  # create the first record  
      2505     UpdateAliases()  
      2506  
    2467 2507     SetupDateConv()  
    2468 2508     GanttCalculation()