code: def filter_user(user, using='records', interaction=None,
                  part_of_week='allweek', part_of_day='allday'):
      if using == 'recharges':
          records = user.recharges
      else:
          records = user.records
          if interaction == 'callandtext':
              records = filter(
                  lambda r: r.interaction in ['call', 'text'], records)
          elif interaction is not None:
              records = filter(lambda r: r.interaction == interaction, records)
      if part_of_week == 'weekday':
          records = filter(
              lambda r: r.datetime.isoweekday() not in user.weekend, records)
      elif part_of_week == 'weekend':
          records = filter(
              lambda r: r.datetime.isoweekday() in user.weekend, records)
      elif part_of_week != 'allweek':
          raise KeyError(
              "{} is not a valid value for part_of_week. it should be 'weekday', "
              "'weekend' or 'allweek'.".format(part_of_week))
      if user.night_start < user.night_end:
          night_filter = lambda r: user.night_end > r.datetime.time(
          ) > user.night_start
      else:
          night_filter = lambda r: not(
              user.night_end < r.datetime.time() < user.night_start)
      if part_of_day == 'day':
          records = filter(lambda r: not(night_filter(r)), records)
      elif part_of_day == 'night':
          records = filter(night_filter, records)
      elif part_of_day != 'allday':
          raise KeyError(
              "{} is not a valid value for part_of_day. It should be 'day', 'night' or 'allday'.".format(part_of_day))
      return list(records)