sortinghat.core package¶
Subpackages¶
- sortinghat.core.migrations package
- Submodules
- sortinghat.core.migrations.0001_initial module
- sortinghat.core.migrations.0002_log module
- sortinghat.core.migrations.0003_context module
- sortinghat.core.migrations.0004_lock module
- sortinghat.core.migrations.0005_individuals module
- sortinghat.core.migrations.0006_uidentity module
- sortinghat.core.migrations.0007_rename_uuid_to_mk module
- sortinghat.core.migrations.0008_rename_id_to_uuid module
- sortinghat.core.migrations.0009_replace_django_mysql module
- sortinghat.core.migrations.0010_team module
- Module contents
- sortinghat.core.recommendations package
Submodules¶
sortinghat.core.admin module¶
sortinghat.core.api module¶
- sortinghat.core.api.add_domain(ctx, organization, domain_name, is_top_domain=True)[source]¶
Add a domain to the registry.
This function adds a new domain to a given organization. The organization must exist on the registry prior to insert the new domain. Otherwise, it will raise a NotFoundError exception. Moreover, if the given domain is already in the registry an AlreadyExistsError exception will be raised.
The new domain is set as a top domain by default. That is useful to avoid the insertion of sub-domains that belong to the same organization (i.e eu.example.com, us.example.com).
Remember that a domain can only be assigned to one (and only one) organization.
- Parameters
ctx – context from where this method is called
organization – name of the organization
domain_name – domain to add to the registry
is_top_domain – set this domain as a top domain
:returns the new domain object
- Raises
InvalidValueError – raised when domain is None or an empty string or is_top_domain does not have a boolean value
NotFoundError – raised when the given organization is not found in the registry
AlreadyExistsError – raised when the domain already exists in the registry
- sortinghat.core.api.add_identity(ctx, source, name=None, email=None, username=None, uuid=None)[source]¶
Add an identity to the registry.
This function adds a new identity to the registry. By default, a new individual will be also added and associated to the new identity.
When uuid parameter is set, it creates a new identity that will be associated to the individual defined by this identifier. Consider that any UUID of the identities of the individual is a valid identifier. Also, this identifier must exist on the registry. If it does not exist, the function will raise a NotFoundError exception.
When no uuid is given, both new individual and identity will have the same identifier.
The registry considers that two identities are distinct when any value of the tuple (source, email, name, username) is different. Thus, the identities:
id1:(‘scm’, ‘jsmith@example.com’, ‘John Smith’, ‘jsmith’) id2:(‘mls’, ‘jsmith@example.com’, ‘John Smith’, ‘jsmith’)
will be registered as different identities. An AlreadyExistError exception will be raised when the function tries to insert a tuple that exists in the registry.
The function returns the new identity associated to the new registered identity.
- Parameters
ctx – context from where this method is called
source – data source
name – full name of the identity
email – email of the identity
username – user name used by the identity
uuid – associates the new identity to the individual identified by this id
- Returns
a universal unique identifier
- Raises
InvalidValueError – when source is None or empty; when all the identity parameters are None or empty.
AlreadyExistsError – raised when the identity already exists in the registry.
NotFoundError – raised when the individual associated to the given uuid is not in the registry.
- sortinghat.core.api.add_organization(ctx, name)[source]¶
Add an organization to the registry.
This function adds an organization to the registry. It checks first whether the organization is already on the registry. When it is not found, the new organization is added. Otherwise, it raises a ‘AlreadyExistsError’ exception to notify that the organization already exists.
- Parameters
ctx – context from where this method is called
name – name of the organization
- Raises
InvalidValueError – raised when organization is None or an empty string
AlreadyExistsError – raised when the organization already exists in the registry
- sortinghat.core.api.add_team(ctx, team_name, organization=None, parent_name=None)[source]¶
Add a team to the registry.
This function creates a new team. If organization is given, the team is added to the organization. The organization must exist on the registry prior to insert the new team. Otherwise, it will raise a NotFoundError exception. Moreover, if the given team already exists in the organization, an AlreadyExistsError exception will be raised.
If a parent_name is passed to the function, the team is created as a subteam of the parent in the organization.
- Parameters
ctx – context from where this method is called
team_name – new team to be created
organization – name of the organization
parent_name – parent under which new team needs to be created
:returns the new team object
- Raises
InvalidValueError – raised when organization is an empty string or team_name is None or an empty string
NotFoundError – raised when the given organization or parent is not found in the registry
AlreadyExistsError – raised when the team already exists in the registry
- sortinghat.core.api.delete_domain(ctx, domain_name)[source]¶
Remove a domain from the registry.
This function removes the given domain from the registry. Domain must exist in the registry. Otherwise, it will raise a NotFoundError exception.
- Parameters
ctx – context from where this method is called
domain_name – name of the domain to remove
:returns the removed domain object
- Raises
NotFoundError – raised when the domain does not exist in the registry.
- sortinghat.core.api.delete_identity(ctx, uuid)[source]¶
Remove an identity from the registry.
This function removes from the registry the identity which its identifier matches with uuid. When the uuid also belongs to an individual, this entry and those identities linked to it will be removed too. The value of this identifier cannot be empty.
If the identifier is not found in the registry a ‘NotFoundError’ exception is raised.
As a result, the function will return an updated version of the individual with the identity removed. If the deleted entry was an individual, the returned value will be None because this object was wiped out.
- Parameters
ctx – context from where this method is called
uuid – identifier assigned to the identity or individual that will be removed
- Returns
an individual with the identity removed; None when the individual was also removed.
- Raises
InvalidValueError – when uuid is None or empty.
NotFoundError – when the identity does not exist in the registry.
- sortinghat.core.api.delete_organization(ctx, name)[source]¶
Remove an organization from the registry.
This function removes the given organization from the registry. Related information such as domains or enrollments are also removed. It checks first whether the organization is already on the registry. When it is found, the organization is removed. Otherwise, it will raise a ‘NotFoundError’.
- Parameters
ctx – context from where this method is called
name – name of the organization to remove
- Raises
InvalidValueError – raised when organization is None or an empty string
NotFoundError – raised when the organization does not exist in the registry
- sortinghat.core.api.delete_team(ctx, team_name, organization=None)[source]¶
Remove a team from the registry.
This function removes the given team from the registry. Deleting a team also deletes all its subteams from the registry. If the team belongs to an Organization, the organization name must be passed. Both Organization and Team must exist in the registry. Otherwise, function will raise a NotFoundError exception.
- Parameters
ctx – context from where this method is called
team_name – team to be deleted
organization – name of the organization that team belongs to
:returns the removed team object
- Raises
NotFoundError – raised when the team does not exist in the registry.
InvalidValueError – raised when the team name is None or an empty string or when organization name is invalid.
- sortinghat.core.api.enroll(ctx, uuid, organization, from_date=None, to_date=None, force=False)[source]¶
Enroll an individual in an organization.
The function enrolls an individual, identified by uuid, in the given organization. Both identity and organization must exist before adding this enrollment to the registry. Otherwise, a NotFoundError exception will be raised. As in other functions, any UUID of the identities of the individual is a valid identifier.
The period of the enrollment can be given with the parameters from_date and to_date, where from_date <= to_date. Default values for these dates are 1900-01-01 and 2100-01-01.
Existing enrollments for the same individual and organization which overlap with the new period will be merged into a single enrollment.
If the given period for that enrollment is enclosed by one already stored, the function will raise an DuplicateRangeError exception.
In case the option force is set to True, and there is an existing enrollment having a range composed by any of the default start or end dates, the range will be overwritten with the new from_date and to_date values.
The individual object with updated enrollment data is returned as the result of calling this function.
- Parameters
ctx – context from where this method is called
uuid – unique identifier
organization – name of the organization
from_date – date when the enrollment starts
to_date – date when the enrollment ends
force – overwrite default dates in case a more specific date is provided
- Returns
an individual with enrollment data updated
- Raises
NotFoundError – when either uuid or organization are not found in the registry.
InvalidValueError – raised in three cases, when either identity or organization are None or empty strings; when “from_date” < 1900-01-01 or “to_date” > 2100-01-01; when “from_date > to_date”.
DuplicateRangeError – raised when the given period for that enrollment already exists in the registry.
- sortinghat.core.api.generate_uuid(source, email=None, name=None, username=None)[source]¶
Generate a UUID related to identity data.
Based on the input data, the function will return the UUID associated to an identity. On this version, the UUID will be the SHA1 of source:email:name:username string.
This string is case insensitive, which means same values for the input parameters in upper or lower case will produce the same UUID.
The value of name will converted to its unaccent form which means same values with accent or unaccent chars (i.e ‘ö and o’) will generate the same UUID.
- For instance, these combinations will produce the same UUID:
(‘scm’, ‘jsmith@example.com’, ‘John Smith’, ‘jsmith’), (‘scm’, ‘jsmith@example,com’, ‘Jöhn Smith’, ‘jsmith’), (‘scm’, ‘jsmith@example.com’, ‘John Smith’, ‘JSMITH’), (‘scm’, ‘jsmith@example.com’, ‘john Smith’, ‘jsmith’)
- Parameters
source – data source
email – email of the identity
name – full name of the identity
username – user name used by the identity
- Returns
a universal unique identifier for Sorting Hat
- Raises
ValueError – when source is None or empty; each one of the parameters is None; or the parameters are empty.
- sortinghat.core.api.lock(ctx, uuid)[source]¶
Lock an individual so it cannot be modified.
This function locks the individual identified by uuid so this object and its related objects such as identities, enrollments or the profile cannot be modified.
- Parameters
ctx – context from where this method is called
uuid – identifier of the individual which will be locked
- Returns
an individual with its locked value updated
- Raises
InvalidValueError – raised when uuid is None or an empty string
NotFoundError – when the identity with the given uuid does not exists.
- sortinghat.core.api.merge(ctx, from_uuids, to_uuid)[source]¶
Merge one or more individuals into another.
Use this function to join a list of individuals, defined in from_uuid by any of their valid identities ids, into to_uuid individual. Identities and enrollments related to each from_uuid will be assigned to to_uuid. In addition, each from_uuid will be removed from the registry. Duplicated enrollments will be also removed from the registry while overlapped enrollments will be merged.
Take into account that individuals are identified by any of the UUIDs assigned to their identities.
This function also merges two or more profiles. When a field on to_uuid profile is None or empty, it will be updated with the value on the profile of each from_uuid. If any of the individuals was set as a bot, the new profile will also be set as a bot.
When any of the from_uuid and to_uuid are equal, or any of this two fields are None or empty, it raises an InvalidValueError.
The function raises a NotFoundError exception when either any from_uuid or to_uuid do not exist in the registry.
- Parameters
ctx – context from where this method is called
from_uuids – List of identifiers of the individuals set to merge
to_uuid – identifier of the individual where from_uuids will be merged
- Returns
a Individual object as the result of the merged individuals
- Raises
NotFoundError – raised when either one of the from_uuids or to_uuid do not exist in the registry
EqualIndividualError – raised when to_uuid is part of from_uuids
- sortinghat.core.api.move_identity(ctx, from_uuid, to_uuid)[source]¶
Move an identity to an individual.
This function shifts the identity identified by from_uuid to the individual identified by to_uuid. Take into account that any UUID of the identities of the individual is a valid identifier.
When to_uuid is an UUID of the individual that is currently related to from_uuid, the action does not have any effect.
In the case of from_uuid and to_uuid have equal values and the individual does not exist, a new individual will be created and the identity will be moved to it.
When from_uuid exists as an individual too, the function raises an InvalidValueError, as this identity cannot be moved.
The function raises a NotFoundError exception when either from_uuid or to_uuid do not exist in the registry and both identifiers are not the same.
The individual object with updated identities data is returned as the result of calling this function.
- Parameters
ctx – context from where this method is called
from_uuid – identifier of the identity set to be moved
to_uuid – identifier of the individual where ‘from_uuid’ will be moved
- Returns
an individual with identities data updated
- Raises
NotFoundError – raised when either from_uuid or to_uuid do not exist in the registry.
InvalidValueError – raised when either from_uuid’ or `to_uuid are None or empty strings,
- sortinghat.core.api.unlock(ctx, uuid)[source]¶
Unlock an individual so it can be modified.
This function unlocks the individual identified by uuid so this object and its related objects such as identities, enrollments or the profile can be modified.
- Parameters
ctx – context from where this method is called
uuid – identifier of the individual which will be unlocked
- Returns
an individual with its locked value updated
- Raises
InvalidValueError – raised when uuid is None or an empty string
NotFoundError – when the identity with the given uuid does not exists.
- sortinghat.core.api.unmerge_identities(ctx, uuids)[source]¶
Unmerge one or more identities from their corresponding individual.
Use this function to separate a list of uuid identities, creating an individual for each one. A profile for each new individual will be created using the name and email fields of the corresponding identity. Nor the enrollments or the profile from any parent individual of the input identities are modified.
When a given identity uuid is equal to the uuid from its parent individual, there will be no effect.
The function raises a NotFoundError exception when either any uuid from the list does not exist in the registry.
The function raises an InvalidValueError exception when either any uuid from the list is None or an empty string.
- Parameters
ctx – context from where this method is called
uuids – list of identifiers of the identities set to be unmerged
- Returns
a list of Individual objects as the result of unmerging the identities
- Raises
NotFoundError – raised when either any uuid from the list does not exist in the registry
InvalidValueError – raised when either any uuid from the list is None or an empty string
- sortinghat.core.api.update_enrollment(ctx, uuid, organization, from_date, to_date, new_from_date=None, new_to_date=None, force=True)[source]¶
Update one or more enrollments from an individual given a new date range.
Use this method to update atomically an individual’s enrollment or set of enrollments defined by the initial date range to a new date range.
As in the enroll method wider date ranges get merged into the wider one, this method withdraws the enrollments from the old date range and set a new enrollment with the new date range. By default, the force parameter is set to True, as it overwrites default dates in case a more specific date is provided when the updated enrollment is added.
In case any of the new dates are missing, the former value for that date will be preserved.
- Parameters
ctx – context from where this method is called
uuid – unique identifier
organization – name of the organization
from_date – date when the enrollment(s) to be updated starts
to_date – date when the enrollment(s) to be updated ends
new_from_date – date when the new enrollment starts
new_to_date – date when the new enrollment ends
force – overwrite default dates in case a more specific date is provided
- Returns
an individual with enrollment data updated
- Raises
NotFoundError – when either uuid or organization are not found in the registry or when the identity is not enrolled in that organization for the given period
InvalidValeError – raised in three cases, when either identity or organization are None or empty strings; when “from_date” < 1900-01-01 or “to_date” > 2100-01-01; when “from_date > to_date”
- sortinghat.core.api.update_profile(ctx, uuid, **kwargs)[source]¶
Update individual profile.
This function allows to edit or update the profile information of the individual identified by uuid. Take into account that any UUID of the identities of the individual is a valid identifier.
The values to update are given as keyword arguments. The allowed keys are listed below (other keywords will be ignored):
‘name’ : name of the individual
‘email’ : email address of the individual
‘gender’ : gender of the individual
- ‘gender_acc’gender accuracy (range of 1 to 100; by default,
set to 100)
- ‘is_bot’boolean value to determine whether an individual is
a bot or not. By default, this value is initialized to False.
‘country_code’ : ISO-3166 country code
The result of calling this function will be the Individual object with an updated profile.
- Parameters
ctx – context from where this method is called
uuid – identifier of the individual which its project will be updated
kwargs – keyword arguments with data to update the profile
- Returns
an individual with its profile updated
- Raises
NotFoundError – raised when either the individual or the country code do not exist in the registry.
InvalidValueError – raised when any of the keyword arguments has an invalid value.
- sortinghat.core.api.withdraw(ctx, uuid, organization, from_date=None, to_date=None)[source]¶
Withdraw an individual from an organization.
This function withdraws an individual identified by uuid from the given organization during the given period of time. As in other functions, any UUID of the identities of the individual is a valid identifier.
For example, if the individual A was enrolled from 2010-01-01 to 2018-01-01 to the organization Example, the result of withdrawing that identity from 2014-01-01 to 2016-01-01 will be two enrollments for that identity: one for the period 2010-2014 and another one for the period 2016-2018. If the period of withdrawing encloses minimum and maximum dates, all the enrollments will be removed.
Both uuid and organization must exists before being deleted. Moreover, an enrollment during the given period must exist. Otherwise, it will raise a NotFoundError exception.
The period of the enrollment can be given with the parameters from_date and to_date, where from_date <= to_date. Default values for these dates are 1900-01-01 and 2100-01-01.
The individual object with updated enrollment data is returned as the result of calling this function.
- Parameters
ctx – context from where this method is called
uuid – unique identifier
organization – name of the organization
from_date – date when the enrollment starts
to_date – date when the enrollment ends
- Returns
an individual with enrollment data updated
- Raises
NotFoundError – when either uuid or organization are not found in the registry or when the identity is not enrolled in that organization for the given period
InvalidValeError – raised in three cases, when either identity or organization are None or empty strings; when “from_date” < 1900-01-01 or “to_date” > 2100-01-01; when “from_date > to_date”
sortinghat.core.apps module¶
sortinghat.core.context module¶
sortinghat.core.db module¶
- sortinghat.core.db.add_domain(trxl, organization, domain_name, is_top_domain=True)[source]¶
Add a domain to the database.
This function adds a new domain to the database using domain_name as its identifier. The new domain will also be linked to the organization object in organization.
Values assigned to domain_name cannot be None or empty. The parameter is_top_domain only accepts bool values.
As a result, the function returns a new Domain object.
- Parameters
trxl – TransactionsLog object from the method calling this one
organization – links the new domain to this organization object
domain_name – name of the domain
is_top_domain – set this domain as a top domain
- Returns
a new domain
- Raises
ValueError – raised when domain_name is None or an empty string; when is_top_domain does not have a bool value.
- sortinghat.core.db.add_enrollment(trxl, individual, organization, start=datetime.datetime(1900, 1, 1, 0, 0, tzinfo=tzutc()), end=datetime.datetime(2100, 1, 1, 0, 0, tzinfo=tzutc()))[source]¶
Enroll an individual to an organization in the database.
The function adds a new relationship between the individual in individual and the given organization to the database.
The period of the enrollment can be given with the parameters from_date and to_date, where from_date <= to_date. Default values for these dates are MIN_PERIOD_DATE and MAX_PERIOD_DATE. These dates cannot be None.
This function returns as result a new Enrollment object.
- Parameters
trxl – TransactionsLog object from the method calling this one
individual – individual to enroll
organization – organization where the individual is enrolled
start – date when the enrollment starts
end – date when the enrollment ends
- Returns
a new enrollment
- Raises
ValueError – when either start or end are None; when start < MIN_PERIOD_DATE; or end > MAX_PERIOD_DATE or start > end.
- sortinghat.core.db.add_identity(trxl, individual, uuid, source, name=None, email=None, username=None)[source]¶
Add an identity to the database.
This function adds a new identity to the database using uuid as its identifier. The new identity will also be linked to the individual object of individual.
Neither the values given to uuid nor to source can be None or empty. Moreover, name, email or username parameters need a non empty value.
As a result, the function returns a new Identity object.
- Parameters
trxl – TransactionsLog object from the method calling this one
individual – links the new identity to this individual object
uuid – identifier for the new identity
source – data source where this identity was found
name – full name of the identity
email – email of the identity
username – user name used by the identity
- Returns
a new identity
- Raises
ValueError – when uuid and source are None or empty; when all of the data parameters are None or empty.
- sortinghat.core.db.add_individual(trxl, mk)[source]¶
Add an individual to the database.
This function adds an individual to the database with mk string as its main key (i.e main identifier). This identifier cannot be empty or None.
When the individual is added, a new empty profile for this object is created too.
As a result, the function returns a new Individual object.
- Parameters
trxl – TransactionsLog object from the method calling this one
mk – main key for the individual
- Returns
a new individual
- Raises
ValueError – when mk is None or an empty string
- sortinghat.core.db.add_organization(trxl, name)[source]¶
Add an organization to the database.
This function adds a new organization to the database, using the given name as an identifier. Name cannot be empty or None.
It returns a new Organization object.
- Parameters
trxl – TransactionsLog object from the method calling this one
name – name of the organization
- Returns
a new organization
- Raises
ValueError – when name is None or empty.
AlreadyExistsError – when an instance with the same name already exists in the database.
- sortinghat.core.db.add_team(trxl, team_name, organization=None, parent=None)[source]¶
Add a team to the database.
This function adds a new team to the database using team_name as its identifier. The new team will be created as a subteam of a parent, if parent is provided. The new team will also be linked to the organization object in organization.
Values assigned to team_name cannot be None or empty.
As a result, the function returns a new Team object.
- Parameters
trxl – TransactionsLog object from the method calling this one
team_name – name of the team
organization – links the new team to this organization object
parent – parent team of the new team
- Returns
a new team
- Raises
ValueError – raised when team_name is None or an empty string;
- sortinghat.core.db.delete_domain(trxl, domain)[source]¶
Remove a domain from the database.
Deletes from the database the domain given in domain.
- Parameters
trxl – TransactionsLog object from the method calling this one
domain – domain to remove
- sortinghat.core.db.delete_enrollment(trxl, enrollment)[source]¶
Remove an enrollment from the database.
This function removes from the database the enrollment given in enrollment.
- Parameters
trxl – TransactionsLog object from the method calling this one
enrollment – enrollment object to remove
- sortinghat.core.db.delete_identity(trxl, identity)[source]¶
Remove an identity from the database.
This function removes from the database the identity given in identity. Take into account this function does not remove individual in the case they get empty.
- Parameters
trxl – TransactionsLog object from the method calling this one
identity – identity to remove
- sortinghat.core.db.delete_individual(trxl, individual)[source]¶
Remove an individual from the database.
Function that removes from the database the individual given in individual. Data related to it will be also removed.
- Parameters
trxl – TransactionsLog object from the method calling this one
individual – individual to remove
- sortinghat.core.db.delete_organization(trxl, organization)[source]¶
Remove an organization from the database.
Function that removes from the database the organization given in organization. Data related such as domains or enrollments are also removed.
- Parameters
trxl – TransactionsLog object from the method calling this one
organization – organization to remove
- sortinghat.core.db.delete_team(trxl, team)[source]¶
Remove a team and all its subteams from the database.
Deletes from the database the team given in team as well as all teams with parent=`team`
- Parameters
trxl – TransactionsLog object from the method calling this one
team – team to remove
- sortinghat.core.db.find_domain(domain_name)[source]¶
Find a domain.
Find a domain by its name in the database. When the domain does not exist the function will raise a NotFoundError.
- Parameters
domain_name – name of the domain to find
- Returns
a domain object
- Raises
NotFoundError – when the domain with the given name does not exists.
- sortinghat.core.db.find_identity(uuid)[source]¶
Find an identity.
Find an identity by its UUID in the database. When the identity does not exist the function will raise a NotFoundError.
- Parameters
uuid – id of the identity to find
- Returns
an identity object
- Raises
NotFoundError – when the identity with the given uuid does not exists.
- sortinghat.core.db.find_individual(mk)[source]¶
Find an individual entity.
Find an individual by its main key (mk) in the database. When the individual does not exist the function will raise a NotFoundError.
- Parameters
mk – main key or id of the individual to find
- Returns
an individual object
- Raises
NotFoundError – when the individual with the given mk does not exists.
- sortinghat.core.db.find_individual_by_uuid(uuid)[source]¶
Find an individual by its identities UUIDs.
Find an individual which identities have the parameter uuid as their identifier. When such individual does not exists the function will raise a NotFoundError.
- Parameters
uuid – id to search the individual
- Returns
an individual object
- Raises
NotFoundError – when the individual does not exist.
- sortinghat.core.db.find_organization(name)[source]¶
Find an organization.
Find an organization by its name in the database. When the organization does not exist the function will raise a NotFoundError.
- Parameters
name – name of the organization to find
- Returns
an organization object
- Raises
NotFoundError – when the organization with the given name does not exists.
- sortinghat.core.db.find_team(team_name, organization=None)[source]¶
Find a team.
Finds a team by its name in the registry. If organization is passed, it looks for a team in that organization.
When the team does not exist, the function will raise a NotFoundError.
- Parameters
organization – name of the organization to which team belongs to
team_name – name of the team to find
- Returns
a team object
- Raises
NotFoundError – when the team with the given name does not exist in the organization specified.
- sortinghat.core.db.lock(trxl, individual)[source]¶
Lock a given individual.
Locks a given individual object so this object and its related objects such as identities, enrollments or its profile cannot be modified.
- Parameters
trxl – TransactionsLog object from the method calling this one
individual – individual which will be locked
- Returns
the individual with lock parameter updated
- sortinghat.core.db.move_identity(trxl, identity, individual)[source]¶
Move an identity to an individual.
Shifts identity to the individual given in individual. As a result, it will return individual object with list of identities updated.
When identity is already assigned to individual, the function will raise an ValueError exception.
- Parameters
trxl – TransactionsLog object from the method calling this one
identity – identity to be moved
individual – individual where identity will be moved
- Returns
the individual with related identities updated
- Raises
ValueError – when identity is already part of individual
- sortinghat.core.db.search_enrollments_in_period(mk, org_name, from_date=datetime.datetime(1900, 1, 1, 0, 0, tzinfo=tzutc()), to_date=datetime.datetime(1900, 1, 1, 0, 0, tzinfo=tzutc()))[source]¶
Look for enrollments in a given period.
Returns the enrollments of an individual for a given organization during period of time.
An empty list will be returned when no enrollments could be found, due to the individual or the organization do not exist, or there are not enrollments assigned for that period.
- Parameters
mk – main key of the individual
org_name – name of the organization
from_date – starting date for the period
to_date – ending date for the period
- Returns
a list of enrollment objects
- sortinghat.core.db.unlock(trxl, individual)[source]¶
Unlock a given individual.
Unlocks a given individual object so this object and its related objects such as identities, enrollments or its profile can be modified.
- Parameters
trxl – TransactionsLog object from the method calling this one
individual – individual which will be unlocked
- Returns
the individual with lock parameter updated
- sortinghat.core.db.update_profile(trxl, individual, **kwargs)[source]¶
Update individual profile.
This function allows to edit or update the profile information of the given individual. The values to update are given as keyword arguments. The allowed keys are listed below (other keywords will be ignored):
name: name of the individual
email: email address of the individual
gender: gender of the individual
gender_acc: gender accuracy (range of 1 to 100; by default, set to 100)
- is_bot: boolean value to determine whether an individual is
a bot or not. By default, this value is initialized to False.
country_code: ISO-3166 country code
As a result, it will return the Individual object with the updated data.
- Parameters
trxl – TransactionsLog object from the method calling this one
individual – individual whose profile will be updated
kwargs – parameters to edit the profile
- Returns
individual object with the updated profile
- Raises
ValueError – raised either when is_bot does not have a boolean value; gender_acc is not an int or is not in range.
sortinghat.core.decorators module¶
sortinghat.core.errors module¶
- exception sortinghat.core.errors.AlreadyExistsError(**kwargs)[source]¶
Bases:
sortinghat.core.errors.BaseError
Exception raised when an entity already exists in the registry
- code = 2¶
- message = "%(entity)s '%(eid)s' already exists in the registry"¶
- exception sortinghat.core.errors.BaseError(**kwargs)[source]¶
Bases:
Exception
Base class error.
Derived classes can overwrite error message declaring ‘message’ property.
- code = 1¶
- message = 'SortingHat unknown error'¶
- exception sortinghat.core.errors.ClosedTransactionError(**kwargs)[source]¶
Bases:
sortinghat.core.errors.BaseError
Exception raised when performing a change on a closed transaction
- code = 12¶
- message = '%(msg)s'¶
- exception sortinghat.core.errors.DuplicateRangeError(**kwargs)[source]¶
Bases:
sortinghat.core.errors.BaseError
Exception raised when setting an enrollment with an existing date range
- code = 14¶
- message = "range date '%(start)s'-'%(end)s' is part of an existing range for %(org)s"¶
- exception sortinghat.core.errors.EqualIndividualError(**kwargs)[source]¶
Bases:
sortinghat.core.errors.BaseError
Exception raised when the source and destination individual are the same
- code = 15¶
- message = '%(msg)s'¶
- exception sortinghat.core.errors.InvalidFilterError(**kwargs)[source]¶
Bases:
sortinghat.core.errors.BaseError
Exception raised when a filter is invalid
- code = 16¶
- message = 'Error in %(filter_name)s filter: %(msg)s'¶
- exception sortinghat.core.errors.InvalidValueError(**kwargs)[source]¶
Bases:
sortinghat.core.errors.BaseError
Exception raised when a value is invalid
- code = 10¶
- message = '%(msg)s'¶
- exception sortinghat.core.errors.LockedIdentityError(**kwargs)[source]¶
Bases:
sortinghat.core.errors.BaseError
Exception raised when performing a change on a locked individual
- code = 13¶
- message = 'Individual %(uuid)s is locked'¶
- exception sortinghat.core.errors.NotFoundError(**kwargs)[source]¶
Bases:
sortinghat.core.errors.BaseError
Exception raised when an entity is not found in the registry
- code = 9¶
- message = '%(entity)s not found in the registry'¶
- exception sortinghat.core.errors.RecommendationEngineError(**kwargs)[source]¶
Bases:
sortinghat.core.errors.BaseError
Exception raised when there is an error in the recommendation engine
- code = 100¶
- message = '%(msg)s'¶
sortinghat.core.jobs module¶
- sortinghat.core.jobs.affiliate(ctx, uuids=None)[source]¶
Affiliate a set of individuals using recommendations.
This function automates the affiliation process obtaining a list of recommendations where individuals can be affiliated. After that, individuals are enrolled to them. This job returns a dictionary with which individuals were enrolled and the errors generated during this process.
Individuals are defined by any of their valid keys or UUIDs. When the parameter uuids is empty, the job will take all the individuals stored in the registry.
- Parameters
ctx – context where this job is run
uuids – list of individuals identifiers
- Returns
a dictionary with which individuals were enrolled and the errors found running the job
- sortinghat.core.jobs.check_criteria(criteria)[source]¶
Check if all given criteria are valid.
Raises an error if a criterion is not in the valid criteria list (email, name and/or username).
- Parameters
criteria – list of criteria to check
- sortinghat.core.jobs.find_job(job_id)[source]¶
Find a job in the jobs registry.
Search for a job using its identifier. When the job is not found, a NotFoundError exception is raised.
- Parameters
job_id – job identifier
- Returns
a Job instance
- Raises
NotFoundError – when the job identified by job_id is not found.
- sortinghat.core.jobs.genderize(ctx, uuids=None)[source]¶
Assign a gender to a set of individuals using recommendations.
This job autocompletes the gender information (stored in the profile) of unique identities after obtaining a list of recommendations for their gender based on their name.
Individuals are defined by any of their valid keys or UUIDs. When the parameter uuids is empty, the job will take all the individuals stored in the registry.
- Parameters
ctx – context where this job is run
uuids – list of individuals identifiers
- Returns
a dictionary with which individual profiles were updated and the errors found running the job
- sortinghat.core.jobs.get_jobs()[source]¶
Get a list of all jobs
This function returns a list of all jobs found in the main queue and its registries, sorted by date.
- Returns
a list of Job instances
- sortinghat.core.jobs.recommend_affiliations(ctx, uuids=None)[source]¶
Generate a list of affiliation recommendations from a set of individuals.
This function generates a list of recommendations which include the organizations where individuals can be affiliated. This job returns a dictionary with which individuals are recommended to be affiliated to which organization.
Individuals are defined by any of their valid keys or UUIDs. When the parameter uuids is empty, the job will take all the individuals stored in the registry.
- Parameters
ctx – context where this job is run
uuids – list of individuals identifiers
- Returns
a dictionary with which individuals are recommended to be affiliated to which organization.
- sortinghat.core.jobs.recommend_gender(ctx, uuids)[source]¶
Generate a list of gender recommendations from a set of individuals.
This job generates a list of recommendations with the probable gender of the given individuals.
- Parameters
ctx – context where this job is run
uuids – list of individuals identifiers
- Returns
a dictionary with the recommended gender and accuracy of the prediction for each individual.
- sortinghat.core.jobs.recommend_matches(ctx, source_uuids, target_uuids, criteria, verbose=False)[source]¶
Generate a list of affiliation recommendations from a set of individuals.
This function generates a list of recommendations which include the matching identities from the individuals which can be merged with. This job returns a dictionary with which individuals are recommended to be merged to which individual (or which identities is verbose mode is activated).
Individuals both for source_uuids and target_uuids are defined by any of their valid keys or UUIDs. When the parameter target_uuids is empty, the recommendation engine will take all the individuals stored in the registry, so matches will be found comparing the identities from the individuals in source_uuids against all the identities on the registry.
- Parameters
ctx – context where this job is run
source_uuids – list of individuals identifiers to look matches for
target_uuids – list of individuals identifiers where to look for matches
criteria – list of fields which the match will be based on (email, name and/or username)
verbose – if set to True, the match results will be composed by individual identities (even belonging to the same individual).
- Returns
a dictionary with which individuals are recommended to be merged to which individual or which identities.
- sortinghat.core.jobs.unify(ctx, source_uuids, target_uuids, criteria)[source]¶
Unify a set of individuals by merging them using matching recommendations.
This function automates the identities unify process obtaining a list of recommendations where matching individuals can be merged. After that, matching individuals are merged. This job returns a list with the individuals which have been merged and the errors generated during this process.
Individuals both for source_uuids and target_uuids are defined by any of their valid keys or UUIDs. When the parameter target_uuids is empty, the matches and the later merges will take place comparing the identities from the individuals in source_uuids against all the identities on the registry.
- Parameters
ctx – context where this job is run
source_uuids – list of individuals identifiers to look matches for
target_uuids – list of individuals identifiers where to look for matches
criteria – list of fields which the unify will be based on (email, name and/or username)
- Returns
a list with the individuals resulting from merge operations and the errors found running the job
sortinghat.core.log module¶
- class sortinghat.core.log.TransactionsLog(trx, ctx)[source]¶
Bases:
object
Class for logging transactions and operations related with the database.
Every object of this class is created using the open class method receiving as a parameter the name of the method opening the transaction, which creates a Transaction object in the database. If the context was created by a job, the logger will add the job identifier to the name of the transaction.
The method log_operation creates a new Operation objects linked to the transaction which was generated when the object was instanced. This method receives, among other parameters, the arguments from the method logging the operation in a Python dict object which will be converted to a serialized JSON.
The close method adds a closed_at timestamp (before calling this method, this field has a NULL value in the DB) and it also sets to True the is_closed flag.
- Parameters
trx – Transaction object generated with the class method open
- Raises
ClosedTransactionError – When trying to log an operation on a closed transaction
TypeError – When the op_type is not an instance of Operation.OpType class
- log_operation(op_type, entity_type, timestamp, args, target)[source]¶
Create a new operation object and save it into the DB.
- Parameters
op_type – Type of the operation which is recorded (ADD, DELETE, UPDATE)
entity_type – Type of entity involved in the operations (UUID, ENROLLMENT, etc.)
timestamp – Datetime when the operation is created
args – Input arguments from the method creating the operation
target – Argument which the operation is directed to
- Raises
ClosedTransactionError – When trying to log an operation on a closed transaction
TypeError – When the op_type is not an instance of Operation.OpType class
- Returns
a new Operation object
- classmethod open(name, ctx)[source]¶
Create a new transaction object and save it into the DB.
When the context was created by a job, this method will add the job identifier as a suffix to the name of the transaction.
- Parameters
name – mame of the method opening the transaction
ctx – context from the method opening the transaction
- Returns
a new TransactionsLog object containing the generated Transaction object
sortinghat.core.models module¶
- class sortinghat.core.models.Country(created_at, last_modified, code, name, alpha3)[source]¶
Bases:
sortinghat.core.models.EntityBase
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- alpha3¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- code¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- name¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- profile_set¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- class sortinghat.core.models.CreationDateTimeField(*args, **kwargs)[source]¶
Bases:
django.db.models.fields.DateTimeField
Field automatically set to the current date when an object is created.
- class sortinghat.core.models.Domain(id, created_at, last_modified, domain, is_top_domain, organization)[source]¶
Bases:
sortinghat.core.models.EntityBase
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- domain¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_top_domain¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- organization¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- organization_id¶
- class sortinghat.core.models.Enrollment(id, created_at, last_modified, individual, organization, start, end)[source]¶
Bases:
sortinghat.core.models.EntityBase
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- end¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_end(*, field=<django.db.models.fields.DateTimeField: end>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_next_by_start(*, field=<django.db.models.fields.DateTimeField: start>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_end(*, field=<django.db.models.fields.DateTimeField: end>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- get_previous_by_start(*, field=<django.db.models.fields.DateTimeField: start>, is_next=False, **kwargs)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- individual¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- individual_id¶
- objects = <django.db.models.manager.Manager object>¶
- organization¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- organization_id¶
- start¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class sortinghat.core.models.EntityBase(*args, **kwargs)[source]¶
Bases:
django.db.models.base.Model
- created_at¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- last_modified¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class sortinghat.core.models.Identity(created_at, last_modified, uuid, name, email, username, source, individual)[source]¶
Bases:
sortinghat.core.models.EntityBase
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- email¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- individual¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- individual_id¶
- name¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- source¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- username¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- uuid¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class sortinghat.core.models.Individual(created_at, last_modified, mk, is_locked)[source]¶
Bases:
sortinghat.core.models.EntityBase
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- enrollments¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- identities¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- is_locked¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- mk¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- profile¶
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is aReverseOneToOneDescriptor
instance.
- class sortinghat.core.models.LastModificationDateTimeField(*args, **kwargs)[source]¶
Bases:
django.db.models.fields.DateTimeField
Field automatically set to the current date on each save() call.
- class sortinghat.core.models.MatchingBlacklist(created_at, last_modified, excluded)[source]¶
Bases:
sortinghat.core.models.EntityBase
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- excluded¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- objects = <django.db.models.manager.Manager object>¶
- class sortinghat.core.models.Operation(ouid, op_type, entity_type, target, trx, timestamp, args)[source]¶
Bases:
django.db.models.base.Model
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- class OpType(value)[source]¶
Bases:
enum.Enum
An enumeration.
- ADD = 'ADD'¶
- DELETE = 'DELETE'¶
- UPDATE = 'UPDATE'¶
- args¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- entity_type¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=True, **kwargs)¶
- get_op_type_display(*, field=<django.db.models.fields.CharField: op_type>)¶
- get_previous_by_timestamp(*, field=<django.db.models.fields.DateTimeField: timestamp>, is_next=False, **kwargs)¶
- objects = <django.db.models.manager.Manager object>¶
- op_type¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- ouid¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- target¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- timestamp¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- trx¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- trx_id¶
- class sortinghat.core.models.Organization(id, created_at, last_modified, name)[source]¶
Bases:
sortinghat.core.models.EntityBase
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- domains¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- enrollments¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- teams¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- class sortinghat.core.models.Profile(id, created_at, last_modified, individual, name, email, gender, gender_acc, is_bot, country)[source]¶
Bases:
sortinghat.core.models.EntityBase
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- country¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- country_id¶
- email¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- gender¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- gender_acc¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- individual¶
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- individual_id¶
- is_bot¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- class sortinghat.core.models.Team(id, path, depth, numchild, created_at, last_modified, name, organization)[source]¶
Bases:
treebeard.mp_tree.MP_Node
,sortinghat.core.models.EntityBase
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- get_next_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=True, **kwargs)¶
- get_next_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<sortinghat.core.models.CreationDateTimeField: created_at>, is_next=False, **kwargs)¶
- get_previous_by_last_modified(*, field=<sortinghat.core.models.LastModificationDateTimeField: last_modified>, is_next=False, **kwargs)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- organization¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- organization_id¶
- class sortinghat.core.models.Transaction(tuid, name, created_at, closed_at, is_closed, authored_by)[source]¶
Bases:
django.db.models.base.Model
- exception DoesNotExist¶
Bases:
django.core.exceptions.ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
django.core.exceptions.MultipleObjectsReturned
- authored_by¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- closed_at¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- created_at¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)¶
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)¶
- is_closed¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- operations¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- tuid¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
sortinghat.core.schema module¶
- class sortinghat.core.schema.AbstractPaginatedType(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- class sortinghat.core.schema.AddDomain(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- domain = <graphene.types.scalars.String object>¶
- is_top_domain = <graphene.types.scalars.Boolean object>¶
- organization = <graphene.types.scalars.String object>¶
- domain = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.AddIdentity(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- email = <graphene.types.scalars.String object>¶
- name = <graphene.types.scalars.String object>¶
- source = <graphene.types.scalars.String object>¶
- username = <graphene.types.scalars.String object>¶
- uuid = <graphene.types.scalars.String object>¶
- individual = <graphene.types.field.Field object>¶
- uuid = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.AddOrganization(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- organization = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.Affiliate(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- job_id = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.AffiliationRecommendationType(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- organizations = <graphene.types.structures.List object>¶
- uuid = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.AffiliationResultType(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- organizations = <graphene.types.structures.List object>¶
- uuid = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.CountryFilterType(*args, **kwargs)[source]¶
Bases:
graphene.types.inputobjecttype.InputObjectType
- code = <graphene.types.scalars.String object>¶
- term = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.CountryPaginatedType(*args, **kwargs)[source]¶
Bases:
sortinghat.core.schema.AbstractPaginatedType
- entities = <graphene.types.structures.List object>¶
- page_info = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.CountryType(*args, **kwargs)[source]¶
Bases:
graphene_django.types.DjangoObjectType
- class sortinghat.core.schema.DeleteDomain(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- domain = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.DeleteIdentity(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- individual = <graphene.types.field.Field object>¶
- uuid = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.DeleteOrganization(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- organization = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.DomainType(*args, **kwargs)[source]¶
Bases:
graphene_django.types.DjangoObjectType
- class sortinghat.core.schema.Enroll(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- force = <graphene.types.scalars.Boolean object>¶
- from_date = <graphene.types.datetime.DateTime object>¶
- organization = <graphene.types.scalars.String object>¶
- to_date = <graphene.types.datetime.DateTime object>¶
- uuid = <graphene.types.scalars.String object>¶
- individual = <graphene.types.field.Field object>¶
- uuid = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.EnrollmentType(*args, **kwargs)[source]¶
Bases:
graphene_django.types.DjangoObjectType
- class sortinghat.core.schema.GenderRecommendationType(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- accuracy = <graphene.types.scalars.Int object>¶
- gender = <graphene.types.scalars.String object>¶
- uuid = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.Genderize(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- job_id = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.GenderizeResultType(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- accuracy = <graphene.types.scalars.Int object>¶
- gender = <graphene.types.scalars.String object>¶
- uuid = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.IdentityFilterType(*args, **kwargs)[source]¶
Bases:
graphene.types.inputobjecttype.InputObjectType
- country = <graphene.types.scalars.String object>¶
- enrollment = <graphene.types.scalars.String object>¶
- enrollment_date = <graphene.types.scalars.String object>¶
- gender = <graphene.types.scalars.String object>¶
- is_bot = <graphene.types.scalars.Boolean object>¶
- is_enrolled = <graphene.types.scalars.Boolean object>¶
- is_locked = <graphene.types.scalars.Boolean object>¶
- last_updated = <graphene.types.scalars.String object>¶
- source = <graphene.types.scalars.String object>¶
- term = <graphene.types.scalars.String object>¶
- uuid = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.IdentityPaginatedType(*args, **kwargs)[source]¶
Bases:
sortinghat.core.schema.AbstractPaginatedType
- entities = <graphene.types.structures.List object>¶
- page_info = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.IdentityType(*args, **kwargs)[source]¶
Bases:
graphene_django.types.DjangoObjectType
- class sortinghat.core.schema.IndividualType(*args, **kwargs)[source]¶
Bases:
graphene_django.types.DjangoObjectType
- class sortinghat.core.schema.JobPaginatedType(*args, **kwargs)[source]¶
Bases:
sortinghat.core.schema.AbstractPaginatedType
- entities = <graphene.types.structures.List object>¶
- page_info = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.JobResultType(*args, **kwargs)[source]¶
Bases:
graphene.types.union.Union
- class sortinghat.core.schema.JobType(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- enqueued_at = <graphene.types.datetime.DateTime object>¶
- errors = <graphene.types.structures.List object>¶
- job_id = <graphene.types.scalars.String object>¶
- job_type = <graphene.types.scalars.String object>¶
- result = <graphene.types.structures.List object>¶
- status = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.Lock(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- individual = <graphene.types.field.Field object>¶
- uuid = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.MatchesRecommendationType(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- matches = <graphene.types.structures.List object>¶
- uuid = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.Merge(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- from_uuids = <graphene.types.structures.List object>¶
- to_uuid = <graphene.types.scalars.String object>¶
- individual = <graphene.types.field.Field object>¶
- uuid = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.MoveIdentity(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- from_uuid = <graphene.types.scalars.String object>¶
- to_uuid = <graphene.types.scalars.String object>¶
- individual = <graphene.types.field.Field object>¶
- uuid = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.OperationArgsType(*args, **kwargs)[source]¶
Bases:
graphene.types.generic.GenericScalar
- class sortinghat.core.schema.OperationFilterType(*args, **kwargs)[source]¶
Bases:
graphene.types.inputobjecttype.InputObjectType
- entity_type = <graphene.types.scalars.String object>¶
- from_date = <graphene.types.datetime.DateTime object>¶
- op_type = <graphene.types.scalars.String object>¶
- ouid = <graphene.types.scalars.String object>¶
- target = <graphene.types.scalars.String object>¶
- to_date = <graphene.types.datetime.DateTime object>¶
- class sortinghat.core.schema.OperationPaginatedType(*args, **kwargs)[source]¶
Bases:
sortinghat.core.schema.AbstractPaginatedType
- entities = <graphene.types.structures.List object>¶
- page_info = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.OperationType(*args, **kwargs)[source]¶
Bases:
graphene_django.types.DjangoObjectType
- class sortinghat.core.schema.OrganizationFilterType(*args, **kwargs)[source]¶
Bases:
graphene.types.inputobjecttype.InputObjectType
- name = <graphene.types.scalars.String object>¶
- term = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.OrganizationPaginatedType(*args, **kwargs)[source]¶
Bases:
sortinghat.core.schema.AbstractPaginatedType
- entities = <graphene.types.structures.List object>¶
- page_info = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.OrganizationType(*args, **kwargs)[source]¶
Bases:
graphene_django.types.DjangoObjectType
- class sortinghat.core.schema.PaginationType(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- end_index = <graphene.types.scalars.Int object>¶
- has_next = <graphene.types.scalars.Boolean object>¶
- has_prev = <graphene.types.scalars.Boolean object>¶
- num_pages = <graphene.types.scalars.Int object>¶
- page = <graphene.types.scalars.Int object>¶
- page_size = <graphene.types.scalars.Int object>¶
- start_index = <graphene.types.scalars.Int object>¶
- total_results = <graphene.types.scalars.Int object>¶
- class sortinghat.core.schema.ProfileInputType(*args, **kwargs)[source]¶
Bases:
graphene.types.inputobjecttype.InputObjectType
- country_code = <graphene.types.scalars.String object>¶
- email = <graphene.types.scalars.String object>¶
- gender = <graphene.types.scalars.String object>¶
- gender_acc = <graphene.types.scalars.Int object>¶
- is_bot = <graphene.types.scalars.Boolean object>¶
- name = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.ProfileType(*args, **kwargs)[source]¶
Bases:
graphene_django.types.DjangoObjectType
- class sortinghat.core.schema.RecommendAffiliations(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- job_id = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.RecommendGender(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- job_id = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.RecommendMatches(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- criteria = <graphene.types.structures.List object>¶
- source_uuids = <graphene.types.structures.List object>¶
- target_uuids = <graphene.types.structures.List object>¶
- verbose = <graphene.types.scalars.Boolean object>¶
- job_id = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.SortingHatMutation(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- add_domain = <graphene.types.field.Field object>¶
- add_identity = <graphene.types.field.Field object>¶
- add_organization = <graphene.types.field.Field object>¶
- affiliate = <graphene.types.field.Field object>¶
- delete_domain = <graphene.types.field.Field object>¶
- delete_identity = <graphene.types.field.Field object>¶
- delete_organization = <graphene.types.field.Field object>¶
- enroll = <graphene.types.field.Field object>¶
- genderize = <graphene.types.field.Field object>¶
- lock = <graphene.types.field.Field object>¶
- merge = <graphene.types.field.Field object>¶
- move_identity = <graphene.types.field.Field object>¶
- recommend_affiliations = <graphene.types.field.Field object>¶
- recommend_gender = <graphene.types.field.Field object>¶
- recommend_matches = <graphene.types.field.Field object>¶
- refresh_token = <graphene.types.field.Field object>¶
- token_auth = <graphene.types.field.Field object>¶
- unify = <graphene.types.field.Field object>¶
- unlock = <graphene.types.field.Field object>¶
- unmerge_identities = <graphene.types.field.Field object>¶
- update_enrollment = <graphene.types.field.Field object>¶
- update_profile = <graphene.types.field.Field object>¶
- verify_token = <graphene.types.field.Field object>¶
- withdraw = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.SortingHatQuery[source]¶
Bases:
object
- countries = <graphene.types.field.Field object>¶
- individuals = <graphene.types.field.Field object>¶
- job = <graphene.types.field.Field object>¶
- jobs = <graphene.types.field.Field object>¶
- operations = <graphene.types.field.Field object>¶
- organizations = <graphene.types.field.Field object>¶
- transactions = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.TransactionFilterType(*args, **kwargs)[source]¶
Bases:
graphene.types.inputobjecttype.InputObjectType
- authored_by = <graphene.types.scalars.String object>¶
- from_date = <graphene.types.datetime.DateTime object>¶
- is_closed = <graphene.types.scalars.Boolean object>¶
- name = <graphene.types.scalars.String object>¶
- to_date = <graphene.types.datetime.DateTime object>¶
- tuid = <graphene.types.scalars.String object>¶
- class sortinghat.core.schema.TransactionPaginatedType(*args, **kwargs)[source]¶
Bases:
sortinghat.core.schema.AbstractPaginatedType
- entities = <graphene.types.structures.List object>¶
- page_info = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.TransactionType(*args, **kwargs)[source]¶
Bases:
graphene_django.types.DjangoObjectType
- class sortinghat.core.schema.Unify(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- criteria = <graphene.types.structures.List object>¶
- source_uuids = <graphene.types.structures.List object>¶
- target_uuids = <graphene.types.structures.List object>¶
- job_id = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.UnifyResultType(*args, **kwargs)[source]¶
Bases:
graphene.types.objecttype.ObjectType
- merged = <graphene.types.structures.List object>¶
- class sortinghat.core.schema.Unlock(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- individual = <graphene.types.field.Field object>¶
- uuid = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.UnmergeIdentities(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- individuals = <graphene.types.field.Field object>¶
- uuids = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.UpdateEnrollment(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- force = <graphene.types.scalars.Boolean object>¶
- from_date = <graphene.types.datetime.DateTime object>¶
- new_from_date = <graphene.types.datetime.DateTime object>¶
- new_to_date = <graphene.types.datetime.DateTime object>¶
- organization = <graphene.types.scalars.String object>¶
- to_date = <graphene.types.datetime.DateTime object>¶
- uuid = <graphene.types.scalars.String object>¶
- individual = <graphene.types.field.Field object>¶
- mutate(info, uuid, organization, from_date, to_date, new_from_date=None, new_to_date=None, force=True)[source]¶
- uuid = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.UpdateProfile(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- data = <sortinghat.core.schema.ProfileInputType object>¶
- uuid = <graphene.types.scalars.String object>¶
- individual = <graphene.types.field.Field object>¶
- uuid = <graphene.types.field.Field object>¶
- class sortinghat.core.schema.Withdraw(*args, **kwargs)[source]¶
Bases:
graphene.types.mutation.Mutation
- class Arguments[source]¶
Bases:
object
- from_date = <graphene.types.datetime.DateTime object>¶
- organization = <graphene.types.scalars.String object>¶
- to_date = <graphene.types.datetime.DateTime object>¶
- uuid = <graphene.types.scalars.String object>¶
- individual = <graphene.types.field.Field object>¶
- uuid = <graphene.types.field.Field object>¶
- sortinghat.core.schema.convert_json_field_to_generic_scalar(field, registry=None)[source]¶
Convert the content of a JSONField loading it as an object
- sortinghat.core.schema.parse_date_filter(filter_value)[source]¶
Extract the filter terms from a date filter
The accepted formats are controlled by regular expressions matching two patterns: a comparison operator (>, >=, <, <=) and a date OR a range operator (..) between two dates.
The accepted date format is ISO 8601, YYYY-MM-DDTHH:MM:SSZ, also accepting microseconds and time zone offset (YYYY-MM-DDTHH:MM:SS.ms+HH:HH).
- Parameters
filter_value – String containing the filter value
- Returns
A dictionary including an operator and the datetime values
sortinghat.core.utils module¶
- sortinghat.core.utils.merge_datetime_ranges(dates, exclude_limits=False)[source]¶
Merge datetime ranges.
Generator that merges overlapped datetime ranges. For example, assuming all dates where set to the same time and are in UTC timezone, these are some expected results:
[(1900-01-01, 2010-01-01), (2008-01-01, 2100-01-01)] –> [(1900-01-01, 2100-01-01)]
[(1900-01-01, 2010-01-01), (2008-01-01, 2010-01-01), (2010-01-02, 2100-01-01)] –> [(1900-01-01, 2010-01-01), (2011-01-02, 2100-01-01)]
[(1900-01-01, 2010-01-01), (2010-01-02, 2100-01-01)] –> [(1900-01-01, 2010-01-01), (2010-01-02, 2100-01-01)]
Default init and end dates (1900-01-01 and 2100-01-01) are considered range limits. These will be removed when a set of ranges overlaps and exclude_limits is set. Compare the next examples with the ones from above:
[(1900-01-01, 2010-01-01), (2008-01-01, 2100-01-01)] –> [(2008-01-01, 2010-01-01)]
[(1900-01-01, 2010-01-01), (2008-01-01, 2010-01-01), (2010-01-02, 2100-01-01)] –> [(2008-01-01, 2010-01-01), (2010-01-02, 2100-01-01)]
[(1900-01-01, 2010-01-01), (2010-01-02, 2100-01-01)] –> [(1900-01-01, 2010-01-01), (2010-01-02, 2100-01-01)]
The condition MIN_PERIOD_DATE <= dt <= MAX_PERIOD_DATE must be true for each date. Otherwise, the generator will raise a ValueError exception.
- Parameters
dates – sequence of datetime ranges where each range is a (start_date, end_date) tuple
exclude_limits – remove MIN_PERIOD_DATE and MAX_PERIOD_DATE from overlapped ranges
- Returns
a generator of merged datetime ranges where each range is a (start_date, end_date) tuple
- Raises
ValueError – when a value of the data range is out of bounds
TypeError – when timezone info is not set in any datetime object
- sortinghat.core.utils.unaccent_string(unistr)[source]¶
Convert a Unicode string to its canonical form without accents.
This allows to convert Unicode strings which include accent characters to their unaccent canonical form. For instance, characters ‘Ê, ê, é, ë’ are considered the same character as ‘e’; characters ‘Ĉ, ć’ are the same as ‘c’.
- Parameters
unistr – Unicode string to unaccent
- Returns
Unicode string on its canonical form
- sortinghat.core.utils.validate_field(name, value, allow_none=False)[source]¶
Validate a given string field following a set of rules.
The conditions to validate value consists on checking if its value is None and if this is allowed or not; if its value is not an empty string or if it is not composed only by whitespaces and/or tabs.
- Parameters
name – name of the field to validate
value – value of the field to validate
allow_none – True if None values are permitted, False otherwise
- Raises
ValueError – when a condition to validate the string is not satisfied
TypeError – when the input value is not a string and not None