def my_timesheets_csv_by_day(self, start, end, hyphen): matrix = {} tss = self.my_timesheets(start, end) for ts in tss: if hyphen == 'yes': val = ts.task.split('-')[0].strip() else: val = ts.task.strip() c_date = convertFromDate(ts.date) if val in matrix: if c_date in matrix[val]: matrix[val][c_date] = matrix[val][c_date] + ts.minutes else: matrix[val][c_date] = ts.minutes else: matrix[val] = {c_date: ts.minutes} result = [] start_date = convertToDate(start) end_date = convertToDate(end) delta = timedelta(days=1) ''' Create the header ''' header = [''] i_date = start_date while i_date <= end_date: header.append(convertFromDate(i_date)) i_date += delta result.append(header) ''' iterate through the tasks and date range ''' for x in matrix: line = [x] i_date = start_date while i_date <= end_date: c_date = convertFromDate(i_date) if c_date in matrix[x]: line.append(matrix[x][c_date]) else: line.append('') i_date += delta result.append(line) return result
def toDict(self): return { "ts": { "key": str(self.key()), "task": self.task, "minutes": self.minutes, "date": convertFromDate(self.date) } }
def toDict(self, sort_order): return { "ts": { "key": str(self.key()), "task": self.task, "minutes": self.minutes, "date": convertFromDate(self.date), "so": sort_order } }
def searchBookings(self, url, start, end=None): ''' Return bookings in dictionary between start and end date If no end date, add 90 days to create end date ''' result = [] if end == None: # Add in three months start_date = convertToStartDay(start) end_date = start_date + timedelta( days=90) #months not valid apparently?? end = convertFromDate(end_date) site = Administrator().getAdministratorByUrl(url) bookings = self.getAllBookings(start, end, site) count = 0 for booking in bookings: count = count + 1 result.append(booking.toDictSearch()) #here - need to add format in dictionary that we want result to come back as return result
def allBookingsAdminJson(self, start, end=None): ''' Return bookings in dictionary between start and end date If no end date, add 90 days to create end date url is passed through ''' result = {"all_bookings": []} if end == None: # Add in three months start_date = convertToStartDay(start) end_date = start_date + timedelta( days=90) #months not valid apparently?? end = convertFromDate(end_date) site = Administrator().getAdministrator() result.update(site.toDictSitePublicDetails()) bookings = self.getAllBookings(start, end, site) count = 0 for booking in bookings: count = count + 1 result['all_bookings'].append(booking.toDictAdmin()) #here - need to add format in dictionary that we want result to come back as return result
def toCSV(self): return [convertFromDate(self.date), self.task, self.minutes]