def get_max_text_lengths(element_tree):
    """
    Function to calculate the maximum length of all text entries in the xml file. This is useful
    for setting the max_length parameters  and correct field types in the model.
    :param element_tree:
    :return: Returns a dict with tag names and max length of text for each tag.
    """
    tag_dict = {}
    for sp in element_tree:
        for element in sp:
            if element.text is not None:
                text_length = len(element.text)
                try:
                    if text_length > tag_dict[element.tag]:
                        tag_dict[element.tag] = text_length
                except KeyError:
                    tag_dict[element.tag] = text_length
    return tag_dict