archivebox.abid_utils.models
This file provides the Django ABIDField and ABIDModel base model to inherit from.
Module Contents
Classes
Abstract Base Model for other models to depend on. Provides ArchiveBox ID (ABID) interface. |
Functions
Get or create a system user with is_superuser=True to be the default owner for new DB rows |
|
Return the mapping of all ABID prefixes to their models. e.g. {‘tag_’: core.models.Tag, ‘snp_’: core.models.Snapshot, …} |
|
Find the correct prefix for a given ABID that may have be missing a prefix (slow). e.g. ABID(‘obj_01BJQMF54D093DXEAWZ6JYRPAQ’) -> ‘snp_’ |
|
Return the Django Model that corresponds to a given ABID prefix. e.g. ‘tag_’ -> core.models.Tag |
|
Shortcut for find_model_from_abid_prefix(abid.prefix) |
|
Find an object corresponding to an ABID by exhaustively searching using its random suffix (slow). e.g. ‘obj_………………..JYRPAQ’ -> Snapshot(‘snp_01BJQMF54D093DXEAWZ6JYRPAQ’) Honestly should only be used for debugging, no reason to expose this ability to users. |
|
Find an object with a given ABID by filtering possible models for a matching abid/uuid/id (fast). e.g. ‘snp_01BJQMF54D093DXEAWZ6JYRPAQ’ -> Snapshot(‘snp_01BJQMF54D093DXEAWZ6JYRPAQ’) |
Data
API
- archivebox.abid_utils.models.ABIDField
‘partial(…)’
- archivebox.abid_utils.models.get_or_create_system_user_pk(username='system')
Get or create a system user with is_superuser=True to be the default owner for new DB rows
- class archivebox.abid_utils.models.AutoDateTimeField
Bases:
django.db.models.DateTimeField
- exception archivebox.abid_utils.models.ABIDError
Bases:
Exception
- class archivebox.abid_utils.models.ABIDModel(*args: Any, **kwargs: Any)
Bases:
django.db.models.Model
Abstract Base Model for other models to depend on. Provides ArchiveBox ID (ABID) interface.
Initialization
Overriden init method ensures we have a stable creation timestamp that fields can use within initialization code pre-saving to DB.
- abid_prefix: str
None
- abid_ts_src
‘self.created_at’
- abid_uri_src
‘None’
- abid_subtype_src
‘self.class.name’
- abid_salt: str
None
- abid_drift_allowed: bool
False
- _prefetched_objects_cache: Dict[str, Any]
None
- __str__() str
- clean(abid_drift_allowed: bool | None = None) None
- save(*args: Any, abid_drift_allowed: bool | None = None, **kwargs: Any) None
Overriden save method ensures new ABID is generated while a new object is first saving.
- classmethod id_from_abid(abid: str) str
- property ABID_SOURCES: Dict[str, str]
“Get the dict of fresh ABID component values based on the live object’s properties.
- property ABID_FRESH_VALUES: Dict[str, Any]
“Get the dict of fresh ABID component values based on the live object’s properties.
- property ABID_FRESH_HASHES: Dict[str, str]
“Get the dict of fresh ABID component hashes based on the live object’s properties.
- property ABID_FRESH_DIFFS: Dict[str, Dict[str, Any]]
Get the dict of discrepancies between the existing saved ABID and a new fresh ABID computed based on the live object.
- issue_new_abid(overwrite=False) archivebox.abid_utils.abid.ABID
Issue a new ABID based on the current object’s properties, can only be called once on new objects (before they are saved to DB).
- property ABID: archivebox.abid_utils.abid.ABID
Get the object’s existing ABID (from self.abid if it’s already saved to DB, otherwise generated fresh) e.g. -> ABID(ts=’01HX9FPYTR’, uri=’E4A5CCD9’, subtype=’00’, rand=’ZYEBQE’)
- property api_url: str
Compute the REST API URL to access this object. e.g. /api/v1/core/snapshot/snp_01BJQMF54D093DXEAWZ6JYRP
- property api_docs_url: str
Compute the REST API Documentation URL to learn about accessing this object. e.g. /api/v1/docs#/Core%20Models/api_v1_core_get_snapshots
- property admin_change_url: str
- get_absolute_url()
- archivebox.abid_utils.models.find_all_abid_prefixes() Dict[str, type[django.db.models.Model]]
Return the mapping of all ABID prefixes to their models. e.g. {‘tag_’: core.models.Tag, ‘snp_’: core.models.Snapshot, …}
- archivebox.abid_utils.models.find_prefix_for_abid(abid: archivebox.abid_utils.abid.ABID) str
Find the correct prefix for a given ABID that may have be missing a prefix (slow). e.g. ABID(‘obj_01BJQMF54D093DXEAWZ6JYRPAQ’) -> ‘snp_’
- archivebox.abid_utils.models.find_model_from_abid_prefix(prefix: str) type[archivebox.abid_utils.models.ABIDModel] | None
Return the Django Model that corresponds to a given ABID prefix. e.g. ‘tag_’ -> core.models.Tag
- archivebox.abid_utils.models.find_model_from_abid(abid: archivebox.abid_utils.abid.ABID) type[django.db.models.Model] | None
Shortcut for find_model_from_abid_prefix(abid.prefix)
- archivebox.abid_utils.models.find_obj_from_abid_rand(rand: Union[archivebox.abid_utils.abid.ABID, str], model=None) List[archivebox.abid_utils.models.ABIDModel]
Find an object corresponding to an ABID by exhaustively searching using its random suffix (slow). e.g. ‘obj_………………..JYRPAQ’ -> Snapshot(‘snp_01BJQMF54D093DXEAWZ6JYRPAQ’) Honestly should only be used for debugging, no reason to expose this ability to users.
- archivebox.abid_utils.models.find_obj_from_abid(abid: archivebox.abid_utils.abid.ABID, model=None, fuzzy=False) Any
Find an object with a given ABID by filtering possible models for a matching abid/uuid/id (fast). e.g. ‘snp_01BJQMF54D093DXEAWZ6JYRPAQ’ -> Snapshot(‘snp_01BJQMF54D093DXEAWZ6JYRPAQ’)