'Field method to group events by time of day'

def case_event_time_of_day(self, row):

    if hasattr(row, 'dvr_case_event'):
        row = row.dvr_case_event
    try:
        date = row.date
    except AttributeError:
        date = None
    if date:
        try:
            person_id = row.person_id
            type_id = row.type_id
        except AttributeError:
            person_id = 0
            type_id = None
        if ((type_id == self.FOOD) and (person_id is None)):
            tod = self.SURPLUS_MEALS
        else:
            date = date.replace(tzinfo=self.UTC).astimezone(self.LOCAL)
            hour = date.time().hour
            if (7 <= hour < 13):
                tod = '07:00    -    13:00'
            elif (13 <= hour < 17):
                tod = '13:00    -    17:00'
            elif (17 <= hour < 20):
                tod = '17:00    -    20:00'
            else:
                tod = '20:00    -    07:00'
    else:
        tod = '-'
    return tod
