Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
lino.mixins.dupable¶
Defines the Dupable model mixin and related functionality
to assist users in finding unwanted duplicate database records.
Don’t mix up this module with lino.mixins.. Models
are “” if users may want to duplicate some instance
thereof, while “dupable” implies that the duplicates are unwanted.
To dupe somebody means “to make a dupe of; deceive; delude; trick.”
(reference.com), and
to dupe something means to duplicate it (eventually in order to
cheat somebody e.g. by making a cheap copy of a valuable object).
This plugin requires the metafone package (a successor of fuzzy, which isn’t yet ported to Python 3). Applications that use this mixin must themselves add metafone to their install_requires.
The current implementation uses a helper table with “phonetic words” and the Double Metaphone algorithm. Read also Doug Hellmann about Using Fuzzy Matching to Search by Sound with Python (2012-03-22) and Phonetic Similarity of Words: A Vectorized Approach in Python by Frank Hofmann (2018-02-12)
Classes
|
Like the standard |
|
Base class for models that can be "dupable". |
|
Checks for the following repairable problem: |
|
Base class for the table of phonetic words of a given dupable model. |
|
Shows the other objects that are similar to this one. |
- class lino.mixins.dupable.CheckedSubmitInsert(label=None, **kwargs)¶
Bases:
SubmitInsertLike the standard
lino.core.actions.SubmitInsert, but adds a confirmation if there is a possible duplicate record.
- class lino.mixins.dupable.PhoneticWordBase(*args, **kwargs)¶
Bases:
ModelBase class for the table of phonetic words of a given dupable model. For every (non-abstract) dupable model there must be a subclass of PhoneticWordBase. The subclass must define a field
ownerwhich points to the Dupable, and the Dupable’sdupable_word_modelmust point to its subclass of PhoneticWordBase.
- class lino.mixins.dupable.Dupable(*args, **kwargs)¶
Bases:
ModelBase class for models that can be “dupable”.
This mixin is to be used on models for which there is a danger of having unwanted duplicate records. It is both for avoiding such duplicates on new records and for detecting existing duplicates.
Note that adding
Dupableto your model’s base classes does not yet activate any functionality, it just declares that model as being dupable. In order to activate verification, you must also define a model which implementsPhoneticWordBaseand setDupable.dupable_word_modelto point to that model. This is done by plugins likelino_xl.lib.dupable_partnersorlino_welfare.modlib.dupable_clients- submit_insert¶
A dupable model has its
submit_insertaction overridden byCheckedSubmitInsert, a extended variant of the action which checks for duplicate rows and asks a user confirmation when necessary.
- dupable_words_field = 'name'¶
The name of a CharField on this model which holds the full-text description that is being tested for duplicates.
- dupable_word_model = None¶
Full name of the model used to hold dupable words for instances of this model. Applications can specify a string which will be resolved at startup to the model’s class object.
- classmethod on_analyze(site)¶
Setup the
dupable_word_modelattribute. This will be called only on concrete subclasses.
- dupable_matches_required()¶
Return the minimum number of words that must sound alike before two rows should be considered similar.
- update_dupable_words(really=True)¶
Update the phonetic words of this row.
- find_similar_instances(limit=None, **kwargs)¶
Return a queryset or yield a list of similar objects.
If limit is specified, we never want to see more than limit duplicates.
Note that an overridden version of this method might return a list or generator instead of a Django queryset.
- class lino.mixins.dupable.DupableChecker(**kwargs)¶
Bases:
CheckerChecks for the following repairable problem:
Must update phonetic words.
- class lino.mixins.dupable.SimilarObjects(*args, **kw)¶
Bases:
VirtualTableShows the other objects that are similar to this one.