def validate_row(self, row):
    'Perform data integrity checks and set default values. Returns a valid object for insertion, or False.\n        Errors are stored for later display. Intentionally not broken up into separate validator functions because\n        there are interdpendencies, such as checking for existing `creator` in one place and then using\n        that creator for group membership check in others.'
    row_errors = []
    if (not row.get('Created By')):
        msg = f'Missing required task creator.'
        row_errors.append(msg)
    creator = get_user_model().objects.filter(username=row.get('Created By')).first()
    if (not creator):
        msg = f"Invalid task creator {row.get('Created By')}"
        row_errors.append(msg)
    assignee = None
    if row.get('Assigned To'):
        assigned = get_user_model().objects.filter(username=row.get('Assigned To'))
        if assigned.exists():
            assignee = assigned.first()
        else:
            msg = f"Missing or invalid task assignee {row.get('Assigned To')}"
            row_errors.append(msg)
    try:
        target_group = Group.objects.get(name=row.get('Group'))
    except Group.DoesNotExist:
        msg = f"Could not find group {row.get('Group')}."
        row_errors.append(msg)
        target_group = None
    if (creator and (target_group not in creator.groups.all())):
        msg = f'{creator} is not in group {target_group}'
        row_errors.append(msg)
    if (assignee and (target_group not in assignee.groups.all())):
        msg = f'{assignee} is not in group {target_group}'
        row_errors.append(msg)
    try:
        tasklist = TaskList.objects.get(name=row.get('Task List'), group=target_group)
        row['Task List'] = tasklist
    except TaskList.DoesNotExist:
        msg = f"Task list {row.get('Task List')} in group {target_group} does not exist"
        row_errors.append(msg)
    datefields = ['Due Date', 'Created Date']
    for datefield in datefields:
        datestring = row.get(datefield)
        if datestring:
            valid_date = self.validate_date(datestring)
            if valid_date:
                row[datefield] = valid_date
            else:
                msg = f'Could not convert {datefield} {datestring} to valid date instance'
                row_errors.append(msg)
    row['Created By'] = creator
    row['Group'] = target_group
    if assignee:
        row['Assigned To'] = assignee
    row['Completed'] = (row['Completed'] == 'Yes')
    if row_errors:
        self.errors.append({self.line_count: row_errors})
        return False
    return row
Perform data integrity checks and set default values. Returns a valid object for insertion, or False.
Errors are stored for later display. Intentionally not broken up into separate validator functions because
there are interdpendencies, such as checking for existing `creator` in one place and then using
that creator for group membership check in others.
def validate_row(self, row):
    'Perform data integrity checks and set default values. Returns a valid object for insertion, or False.\n        Errors are stored for later display. Intentionally not broken up into separate validator functions because\n        there are interdpendencies, such as checking for existing `creator` in one place and then using\n        that creator for group membership check in others.'
    row_errors = []
    if (not row.get('Created By')):
        msg = f'Missing required task creator.'
        row_errors.append(msg)
    creator = get_user_model().objects.filter(username=row.get('Created By')).first()
    if (not creator):
        msg = f"Invalid task creator {row.get('Created By')}"
        row_errors.append(msg)
    assignee = None
    if row.get('Assigned To'):
        assigned = get_user_model().objects.filter(username=row.get('Assigned To'))
        if assigned.exists():
            assignee = assigned.first()
        else:
            msg = f"Missing or invalid task assignee {row.get('Assigned To')}"
            row_errors.append(msg)
    try:
        target_group = Group.objects.get(name=row.get('Group'))
    except Group.DoesNotExist:
        msg = f"Could not find group {row.get('Group')}."
        row_errors.append(msg)
        target_group = None
    if (creator and (target_group not in creator.groups.all())):
        msg = f'{creator} is not in group {target_group}'
        row_errors.append(msg)
    if (assignee and (target_group not in assignee.groups.all())):
        msg = f'{assignee} is not in group {target_group}'
        row_errors.append(msg)
    try:
        tasklist = TaskList.objects.get(name=row.get('Task List'), group=target_group)
        row['Task List'] = tasklist
    except TaskList.DoesNotExist:
        msg = f"Task list {row.get('Task List')} in group {target_group} does not exist"
        row_errors.append(msg)
    datefields = ['Due Date', 'Created Date']
    for datefield in datefields:
        datestring = row.get(datefield)
        if datestring:
            valid_date = self.validate_date(datestring)
            if valid_date:
                row[datefield] = valid_date
            else:
                msg = f'Could not convert {datefield} {datestring} to valid date instance'
                row_errors.append(msg)
    row['Created By'] = creator
    row['Group'] = target_group
    if assignee:
        row['Assigned To'] = assignee
    row['Completed'] = (row['Completed'] == 'Yes')
    if row_errors:
        self.errors.append({self.line_count: row_errors})
        return False
    return row