Skip to content

DataItems of type DTypes.MULTIPLE_CHOICE and DTypes.CHOICE cannot handle duplicate values approprietly #21

@vld-codra

Description

@vld-codra

The DataItem.choices attribute contains a list of tuple containing key value pairs (list[tuple[str, str]] in most cases). When we need a value, we parse this list to find the corresponding key. However, there are some instances where we parse the list and check the values to get the corresponding keys. This is a problem when several keys point to duplicate values (e.g. two projects of the same name) as we never check for duplicate value. This behavior also prevents the addition of new color that would have the same first letter.

The root of the issue is located in the DataItem.from_text, DataItem.to_text and DataItem.from_display.

Proposed improvements/solutions could be:

  • Replace the list of tuples by a dictionnary which would improve readability, ergonomy and (maybe) speed
  • Decoralate the displayed values from the actual values, by example by removing/modifying DataItem.from_display
  • Decorelate the displayed values from the xml values. For example, for a MULTIPLE_CHOICE data item, the method DataItem.to_text is called both to set the display value and the value to write in the XML. This method returns the choices values instead of the keys which forces us to match the values to get back the keys when reopening the XML file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions