class Cases:
""" 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."""
def __init__(self, CSVfile = None):
if CSVfile == None:
print "No File"
self.ifile = None
else:
self.ifile = CSVfile
self.caselist = []
f = open(self.ifile, 'r')
reader = csv.DictReader(f)
for row in reader:
self.caselist.append(row)
f.close()
def CasesBySalesman(self, salesman = None):
if salesman == None:
pass
else:
#I'm not sure if this is very Pythonic...
self.tempcaselist = []
for acase in self.caselist:
if acase['Region'] == salesman:
self.tempcaselist.append(acase)
self.caselist = self.tempcaselist
def CasesBetweenDates(self, startdate = None, enddate = None):
#I'll do this one last - dates are hard; Let's go shopping!
#It will likely be splitting the date string by "/" and assigning
#each part to a different date.day/year/month and doing canned
#comparisons for greater than and less than.
pass
def OpenCases(self):
self.tempcaselist = []
for acase in self.caselist:
if acase['Closed'] == "":
self.tempcaselist.append(acase)
self.caselist = self.tempcaselist
def ClosedCases(self):
self.tempcaselist = []
for acase in self.caselist:
if acase['Closed'] == "":
self.tempcaselist.append(acase)
self.caselist = self.tempcaselists
def ResetCases(self):
self.caselist = []
f = open(self.ifile, 'r')
reader = csv.DictReader(f)
for row in reader:
self.caselist.append(row)
f.close()
def Verify2012Format(self):
#Hopefully not necessary, but you never know
pass