archivebox.base_models.models
This file provides the Django ABIDField and ABIDModel base model to inherit from.
Module Contents
Classes
Base class for models that have some read-only fields enforced by .save(). |
|
Abstract Base Model for other models to depend on. Provides ArchiveBox ID (ABID) interface and other helper methods. |
|
Very simple Model that adds a notes field to any model. |
|
Base Model that adds a config property to any ABIDModel. This config is retrieved by abx.pm.hook.get_scope_config(…) later whenever this model is used. |
|
Base Model that adds an output_dir property to any ABIDModel. |
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) |
|
This is a huge hack and should only be used for debugging, never use this in real code / expose this 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.base_models.models.DEFAULT_ICON[source]
‘<img src=”data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAgCAYAAAAMq2gFAAAAAXNSR0IArs4c6QAAAIRl…’
- archivebox.base_models.models.get_or_create_system_user_pk(username='system')[source]
Get or create a system user with is_superuser=True to be the default owner for new DB rows
- class archivebox.base_models.models.AutoDateTimeField[source]
Bases:
django.db.models.DateTimeField
- class archivebox.base_models.models.ModelWithReadOnlyFields[source]
Bases:
django.db.models.Model
Base class for models that have some read-only fields enforced by .save().
- class archivebox.base_models.models.ModelWithUUID[source]
Bases:
archivebox.base_models.models.ModelWithReadOnlyFields
,tags.models.ModelWithKVTags
- default_json_keys: ClassVar[tuple[str, ...]][source]
(‘TYPE’, ‘id’, ‘abid’, ‘str’, ‘modified_at’, ‘created_at’, ‘created_by_id’, ‘status’, ‘retry_at’, ‘n…
- class archivebox.base_models.models.ModelWithSerializers[source]
Bases:
archivebox.base_models.models.ModelWithUUID
- as_csv_row(keys: Iterable[str] = (), separator: str = ',') str [source]
Get the object’s properties as a csv string
- as_jsonl_row(keys: Iterable[str] = (), **json_kwargs) str [source]
Get the object’s properties as a jsonl string
- class archivebox.base_models.models.ABIDModel(*args: Any, **kwargs: Any)[source]
Bases:
archivebox.base_models.models.ModelWithReadOnlyFields
,archivebox.base_models.models.ModelWithUUID
Abstract Base Model for other models to depend on. Provides ArchiveBox ID (ABID) interface and other helper methods.
Initialization
Overriden init method ensures we have a stable creation timestamp that fields can use within initialization code pre-saving to DB.
- save(*args: Any, abid_drift_allowed: bool | None = None, **kwargs: Any) None [source]
Overriden save method ensures new ABID is generated while a new object is first saving.
- property ABID_SOURCES: Dict[str, str][source]
“Get the dict of fresh ABID component values based on the live object’s properties.
- property ABID_FRESH_VALUES: Dict[str, Any][source]
“Get the dict of fresh ABID component values based on the live object’s properties.
- property ABID_FRESH_HASHES: Dict[str, str][source]
“Get the dict of fresh ABID component hashes based on the live object’s properties.
- property ABID_FRESH_DIFFS: Dict[str, Dict[str, Any]][source]
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.base_models.abid.ABID [source]
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). TODO: eventually we should move this to a separate service that makes sure they’re all unique and monotonic perhaps it could be moved to a KVTag as well, and we could just use the KVTag service + Events to issue new ABIDs
- property ABID: archivebox.base_models.abid.ABID[source]
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’)
- class archivebox.base_models.models.ModelWithNotes[source]
Bases:
django.db.models.Model
Very simple Model that adds a notes field to any model.
- class archivebox.base_models.models.ModelWithConfig[source]
Bases:
django.db.models.Model
Base Model that adds a config property to any ABIDModel. This config is retrieved by abx.pm.hook.get_scope_config(…) later whenever this model is used.
- class archivebox.base_models.models.ModelWithOutputDir(*args: Any, **kwargs: Any)[source]
Bases:
ModelsWithSerializers
,archivebox.base_models.models.ModelWithUUID
,archivebox.base_models.models.ABIDModel
Base Model that adds an output_dir property to any ABIDModel.
It creates the directory on .save(with_indexes=True), automatically migrating any old data if needed. It then writes the indexes to the output_dir on .save(write_indexes=True). It also makes sure the output_dir is in sync with the model.
Initialization
Overriden init method ensures we have a stable creation timestamp that fields can use within initialization code pre-saving to DB.
- property output_dir_parent: str[source]
Get the model type parent directory name that holds this object’s data e.g. ‘archiveresults’
- property output_dir_name: str[source]
Get the subdirectory name for the filesystem directory that holds this object’s data e.g. ‘snp_2342353k2jn3j32l4324’
- property output_dir_str: str[source]
Get relateive the filesystem directory Path that holds that data for this object e.g. ‘snapshots/snp_2342353k2jn3j32l4324’
- archivebox.base_models.models.find_all_abid_prefixes() Dict[str, type[django.db.models.Model]] [source]
Return the mapping of all ABID prefixes to their models. e.g. {‘tag_’: core.models.Tag, ‘snp_’: core.models.Snapshot, …}
- archivebox.base_models.models.find_prefix_for_abid(abid: archivebox.base_models.abid.ABID) str [source]
Find the correct prefix for a given ABID that may have be missing a prefix (slow). e.g. ABID(‘obj_01BJQMF54D093DXEAWZ6JYRPAQ’) -> ‘snp_’
- archivebox.base_models.models.find_model_from_abid_prefix(prefix: str) type[archivebox.base_models.models.ABIDModel] | None [source]
Return the Django Model that corresponds to a given ABID prefix. e.g. ‘tag_’ -> core.models.Tag
- archivebox.base_models.models.find_model_from_abid(abid: archivebox.base_models.abid.ABID) type[django.db.models.Model] | None [source]
Shortcut for find_model_from_abid_prefix(abid.prefix)
- archivebox.base_models.models.find_obj_from_abid_rand(rand: Union[archivebox.base_models.abid.ABID, str], model=None) List[archivebox.base_models.models.ABIDModel] [source]
This is a huge hack and should only be used for debugging, never use this in real code / expose this to users.
Find an object corresponding to an ABID by exhaustively searching using its random suffix (slow). e.g. ‘obj_………………..JYRPAQ’ -> Snapshot(‘snp_01BJQMF54D093DXEAWZ6JYRPAQ’)
- archivebox.base_models.models.find_obj_from_abid(abid: archivebox.base_models.abid.ABID, model=None, fuzzy=False) Any [source]
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’)