Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. class Cases:
  2.     """ Cases takes in a CSV file and puts the cases into a list of dicts called caselist. The file passed to the class for init is kept as a instance variable called ifile. Each function modifies the internally stored case list. Getting back to a starting point means re-initializing the class, or even better calling the reset function."""
  3.    
  4.     def __init__(self, CSVfile = None):
  5.         if CSVfile == None:
  6.             print "No File"
  7.             self.ifile = None
  8.         else:
  9.             self.ifile = CSVfile
  10.             self.caselist = []
  11.             f = open(self.ifile, 'r')
  12.             reader = csv.DictReader(f)
  13.             for row in reader:
  14.                 self.caselist.append(row)
  15.             f.close()
  16.        
  17.     def CasesBySalesman(self, salesman = None):
  18.         if salesman == None:
  19.             pass
  20.        
  21.         else:
  22.             #I'm not sure if this is very Pythonic...
  23.             self.tempcaselist = []
  24.             for acase in self.caselist:
  25.                 if acase['Region'] == salesman:
  26.                     self.tempcaselist.append(acase)
  27.             self.caselist = self.tempcaselist
  28.  
  29.     def CasesBetweenDates(self, startdate = None, enddate = None):
  30.             #I'll do this one last - dates are hard; Let's go shopping!
  31.             #It will likely be splitting the date string by "/" and assigning
  32.             #each part to a different date.day/year/month and doing canned
  33.             #comparisons for greater than and less than.
  34.         pass
  35.    
  36.     def OpenCases(self):
  37.         self.tempcaselist = []
  38.         for acase in self.caselist:
  39.             if acase['Closed'] == "":
  40.                 self.tempcaselist.append(acase)
  41.         self.caselist = self.tempcaselist
  42.        
  43.     def ClosedCases(self):
  44.         self.tempcaselist = []
  45.         for acase in self.caselist:
  46.             if acase['Closed'] == "":
  47.                 self.tempcaselist.append(acase)
  48.         self.caselist = self.tempcaselists
  49.    
  50.     def ResetCases(self):
  51.         self.caselist = []
  52.         f = open(self.ifile, 'r')
  53.         reader = csv.DictReader(f)
  54.         for row in reader:
  55.             self.caselist.append(row)
  56.         f.close()
  57.    
  58.     def Verify2012Format(self):
  59.         #Hopefully not necessary, but you never know
  60.         pass