Assumes fields in LCI fields are all already in lowercase. No efforts are currently made to manipulate these fields. Enforcing lowercase during the migration is doable if required, but the existing implementation of these fields use get_db_prep_save to guarantee only lowercase data is written.
Email fields are migrated to models.EmailField. Case insensitivity is not preserved.
Needs (much) more testing.
Implementation details:
Creates two LowerCase-fields to replace the LCI-fields, LowerCaseCharField and LowerCaseDNSField. The latter inherits from the former. These fields will, like the LCI fields before them, save their data in lowercase by using get_db_prep_save.
Uses a manager to hook into the calls to objects.get, objects.filter, and objects.exclude to ensure they all use lowercase searches into the LowerCase fields. This functionality relies on all fields that are to use lowercase inherit from mreg.fields.LowerCaseCharField.
Uses a mixin for views to overload get_object for relevant detail views.
Noise:
Overloaded get_queryset() usage with prefetching has to manually use lower() on the relevant input due to the manager not applying to querysets. For django-filter, this is solvable by mixing in a filter class that does the lowercasing were applicable, but url_filter does not support this easily.
coverage: 98.937% (-0.06%) from 98.998%
when pulling 313aaac23a7dc033dd2738774faeb324749b3771 on terjekv:migrate-away-from-ci-fields
into 0decba30566dec4f982c225a4363a30f6fe42432 on unioslo:master.
Caveats:
get_db_prep_save
to guarantee only lowercase data is written.Implementation details:
LowerCaseCharField
andLowerCaseDNSField
. The latter inherits from the former. These fields will, like the LCI fields before them, save their data in lowercase by usingget_db_prep_save
.Noise:
Fixes #489