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.duplicable. Models are "duplicable" 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 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)

(This module's source code is available here.)

Classes

CheckedSubmitInsert([label])

Like the standard lino.core.actions.SubmitInsert, but adds a confirmation if there is a possible duplicate record.

Dupable(*args, **kwargs)

Base class for models that can be "dupable".

DupableChecker()

Checks for the following repairable problem:

PhoneticWordBase(*args, **kwargs)

Base class for the table of phonetic words of a given dupable model.

SimilarObjects(*args, **kw)

Shows the other objects which are similar to this one.

class lino.mixins.dupable.CheckedSubmitInsert(label=None, **kw)

Bases: lino.core.actions.SubmitInsert

Like 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: lino.core.model.Model

Base 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 owner which points to the Dupable, and the Dupable's dupable_word_model must point to its subclass of PhoneticWordBase.

class lino.mixins.dupable.Dupable(*args, **kwargs)

Bases: lino.core.model.Model

Base 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 Dupable to 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 implements PhoneticWordBase and set Dupable.dupable_word_model to point to that model. This is done by plugins like lino_xl.lib.dupable_partners or lino_welfare.modlib.dupable_clients

submit_insert

A dupable model has its submit_insert action overridden by CheckedSubmitInsert, 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_model attribute. 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

Bases: lino.modlib.checkdata.choicelists.Checker

Checks for the following repairable problem:

  • Must update phonetic words.

model

alias of Dupable

class lino.mixins.dupable.SimilarObjects(*args, **kw)

Bases: lino.core.tables.VirtualTable

Shows the other objects which are similar to this one.

master

alias of lino.core.model.Model