#6956 (Lino should refuse Choice names that are not .isidentifier())

by Luc Saffre · in Developers

Kurzbeschreibung

Until now, Choice.__init__() didn't verify whether the specified names (the third argument of the constructor) are valid Python identifiers. Now it does. Because the only purpose of these names is to make certain choices available as attributes of the choice list. But e.g. dashes aren't allowed in identifiers.

In products.DeliveryUnits we had names "m²" and "m³", which now are "m2" and "m3".

In react.PrimeReactThemes we have e.g. "bootstrap4-light-purple", which was also used as the names keyword of Choice.__init__(). We simply no longer store these strings as names. We don't need them as names.

Side effect: In the primereact_theme_name plugin setting, we want to select individual PrimeReactThemes choices, e.g. "bootstrap4-light-purple". And this setting is used only as the default value for PrimeReactThemes fields. The default value for choicelist fields can be specified as a string, and this string until now as understood as the *name* of the default choice. Not as its *value*. CallableChoice. __call__() was defined "return self.choicelist.get_by_name(self.name)". Now it's defined "return self.choicelist.get_by_name(self.name, None) or self.choicelist.get_by_value(self.name)", i.e. it works with names *or* with values. That new behaviour was needed for PrimeReactThemes where the default value is a value, not a name.



Kinder

Kommentare