link.document
Document()
Bases: Data
Representation of a Bip document.
A Document is a part of an Item. It can be seen as the representation of a group of files. For example, in a CG production, the modelling scenes of an asset can be represented as a Document. A Document has versions, which are represented by the smallest entity of Bip, the Version object.
Documents are defined by DocumentModels, which define a set of rules and behaviours for the Document. For example the model controls the naming convention.
Info
This class inherits from Data, like Project, Item and Version, since they share similar behaviour.
See bip.link.data.Data
for inherited methods.
Attributes:
Name | Type | Description |
---|---|---|
uid |
str
|
Bip unique identifier (uuid4). Edition is forbidden if this is an persistent (saved) entity. |
slug |
str
|
Human-readable unique identifier, namespaced in the parent model scope. |
name |
str
|
Name of the project. |
description |
str
|
Short description of the item. |
model |
DocumentModel
|
Bip item model object. |
Source code in client/bip/link/document.py
67 68 69 70 71 72 73 74 75 76 77 78 |
|
children_count: int
property
Number of Versions parented to the Document.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Versions count. |
has_children: bool
property
Does the Document have Versions.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the Document has Versions, False otherwise. |
latest_version_number: int
property
Version number of the latest (highest) Version of the Document.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
version number. |
new_version_number: int
property
Next version number.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
next version number. |
parent: Item
property
path: str
property
Dynamic path of the document directory.
The path is dynamically generated by the running Bip client, based on the working directory.
Warning
The path may differ from a machine to another since the path uses the working_directory
local setting, which might vary between machines, depending on the client config.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path of the document directory. |
task: Union[Task, None]
property
Task associated to the Document.
Returns:
Type | Description |
---|---|
Union[Task, None]
|
Union[Task, None]: Task if found, None otherwise. |
add_version(files, number=None, author=None, published=False, auto_save=True, **kwargs)
Convenient class implementation of: bip.link.version.new_version
.
Warning
The signature of Item.new_version()
and bip.link.version.new_version
are different since Item.new_version()
passes itself to the function as document=self
.
Source code in client/bip/link/document.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
delete(safe=True)
Deletes the Document.
By default, if the Document has Versions parented to it, the deletion won't be accepted,
unless safe
is set to True.
Deleting the Document deletes any downstream entity: Version, Group (children only) and Attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
safe |
bool
|
bool: Prevents the deletion if the Document has children (Versions) (Default value = True) |
True
|
Raises:
Type | Description |
---|---|
ValueError
|
If safe is True and the Document has children. |
Source code in client/bip/link/document.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
generate(model, item, task=None, groups=(), element=None, auto_save=True, **kwargs)
classmethod
Generates a Document object.
By default, the generated Document is saved straight after creation. In some cases, it can be useful to get the
floating (not recorded on the database) object in order to perform further operation, and save after that.
That can be achieved by setting auto_save
to False.
Todo
- Check if Task is owned by the Item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str: Name of the new document. |
required | |
item |
Item
|
Item: Parent item. |
required |
groups |
Optional[List[Group]]
|
Union[List, Tuple]: If the DocumentModel has required_memberships, list of the mandatory groups (Default value = ()) |
()
|
task |
Optional[Task]
|
Optional[Task]: Associated task. The Task must be owned by the Item. |
None
|
model |
DocumentModel
|
Optional[Union[DocumentModel, str]]: Model of the new document. Can be left to None if the project
has a |
required |
auto_save |
bool
|
bool: If True, the returned object is saved. Otherwise it is floating. (Default value = True) |
True
|
**kwargs |
Any non-mandatory valid attribute of Item can be passed. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
Failed validation, if auto_save is True. |
TypeError
|
Failed validation, if auto_save is True. |
Returns:
Name | Type | Description |
---|---|---|
Document |
Document
|
Generated Document. |
Source code in client/bip/link/document.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
|
generate_filename(version_number, ext=None, suffix=None)
Generate a filename from the model pattern.
If the DocumentModel has a filename_pattern set, it is used to generate a filename.
This is useful for saving or creating new files and naming them automatically, by the Projects specifications.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ext |
Optional[str]
|
Optional[str]: File extension. If None specified, the filename has no extension. |
None
|
suffix |
Optional[str]
|
Optional[str]: Custom suffix. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If the DocumentModel has no filename_pattern set. |
Returns:
Name | Type | Description |
---|---|---|
str |
Generated filename. |
Source code in client/bip/link/document.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
get_children()
Alias for: Document.get_versions
.
Source code in client/bip/link/document.py
356 357 358 |
|
get_from_filename(filename, item)
classmethod
Get all the Documents with a version containing the given filename.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
str: Looked up filename. |
required |
item |
Item
|
Item: parent Item to look into. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
List[Document]
|
Collection of matching Documents. |
Source code in client/bip/link/document.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
get_latest_version(published_only=False)
Convenient class implementation of: bip.link.version.get_latest_version
.
Warning
The signature of Document.get_latest_version()
and bip.link.version.get_latest_version()
are different since Document.get_latest_version()
passes itself to the function as document=self
.
Source code in client/bip/link/document.py
335 336 337 338 339 340 341 342 |
|
get_version(number)
Convenient class implementation of: bip.link.version.get_version
.
Warning
The signature of Document.get_version()
and bip.link.version.get_version()
are different since Document.get_version()
passes itself to the function as document=self
.
Source code in client/bip/link/document.py
326 327 328 329 330 331 332 333 |
|
get_versions()
Convenient class implementation of: bip.link.version.get_versions
.
Warning
The signature of Document.get_versions()
and bip.link.version.get_versions()
are different since Document.get_versions()
passes itself to the function as document=self
.
Source code in client/bip/link/document.py
344 345 346 347 348 349 350 351 |
|
save()
Saves the Document to the database.
If the Document is floating, saving makes it persistent.
Attributes changes are not applied to the database at modification. Saving the Document does.
Raises:
Type | Description |
---|---|
ValueError
|
Failed validation. |
TypeError
|
Failed validation. |
Source code in client/bip/link/document.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
DocumentModel()
Bases: BipObject
Representation of a Bip item model.
The ItemModel is a template, which sets some rules that any Item modelged with this model must follow.
Attributes:
Name | Type | Description |
---|---|---|
uid |
str
|
Bip unique identifier (uuid4). Edition is forbidden if this is an persistent (saved) entity. |
slug |
str
|
Human-readable unique identifier. |
name |
str
|
Name of the model. |
plural |
int
|
Plural of the name. |
path_pattern |
str
|
Path pattern for Documents path generation. |
requires_task |
bool
|
If True, Documents with this model must be associated with a task. |
version_prefix |
str
|
Version prefix. (default: "v") |
version_padding |
int
|
Version padding. (default: 3) |
collapsed |
bool
|
Used for path generation. If True, the versions |
has_element |
bool
|
If True, Documents with this model must be associated with an element Elements will be entities attached to an item. They define its content, if it is not self-contained. This is the former item-list. Elements are simple entities, with a link [:SOURCE_IS] to the item they represent, and an attribute for the number |
Source code in client/bip/link/document.py
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
|
children_count: int
property
Number of Documents linked to the DocumentModel.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Document count. |
has_children: bool
property
Does the DocumentModel have Documents.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the DocumentModel has Items, False otherwise. |
has_memberships: bool
property
Does the DocumentModel has memberships.
Lightweight method avoiding querying the database.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the DocumentModel has memberships, False otherwise. |
has_optional_memberships: bool
property
Does the DocumentModel has optional memberships.
This utility method does not query the database, and is a helper for checking if it is necessary to get the optional memberships.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the DocumentModel has optional memberships, False otherwise. |
has_required_memberships: bool
property
Does the DocumentModel requires memberships.
This utility method does not query the database, and is a helper for checking if it is necessary to get the required memberships.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the DocumentModel requires memberships, False otherwise. |
project: Project
property
add_membership(group_model, required=True)
Adds a required or optional membership.
Tip
Required or optional memberships are GroupModel that any new Project created with the current ProjectModel must or can be member of in order to be saved.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group_model |
GroupModel
|
GroupModel: GroupModel. |
required |
required |
bool |
True
|
Raises:
Type | Description |
---|---|
ValueError
|
Failed validation. |
TypeError
|
Failed validation. |
Source code in client/bip/link/document.py
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 |
|
delete(safe=True)
Deletes the DocumentModel.
By default, if the DocumentModel has Documents parented to it, the deletion won't be accepted,
unless safe
is set to True.
Deleting the DocumentModel deletes any downstream entity: Document, Version and Attribute.
Warning
If the project has a locked model, the operation is not allowed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
safe |
bool
|
bool: Prevents the deletion if the DocumentModel has children (Documents) (Default value = True) |
True
|
Raises:
Type | Description |
---|---|
ValueError
|
If safe is True and the Documents has children. |
Source code in client/bip/link/document.py
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 |
|
format_version_number(number)
Format a version number according to the rules of the model.
For example, if version_prefix is set to v
and version_padding is set to 3
,
this method would return v003
.
Source code in client/bip/link/document.py
958 959 960 961 962 963 964 965 966 967 968 969 |
|
generate(name, project, auto_save=True, **kwargs)
classmethod
Generates a DocumentModel object.
By default, the generated DocumentModel is saved straight after creation.
In some cases, it can be useful to get the floating (not recorded on the database)
object in order to perform further operation, and save after that.
That can be achieved by setting auto_save
to False.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
str: Name of the new model. |
required |
project |
Project
|
str: Parent Project of the new model. |
required |
auto_save |
bool
|
bool: If True, the returned object is saved. Otherwise it is floating. (Default value = True) |
True
|
**kwargs |
Any non-mandatory valid attribute of DocumentModel can be passed. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
Failed validation, if auto_save is True. |
TypeError
|
Failed validation, if auto_save is True. |
Returns:
Name | Type | Description |
---|---|---|
DocumentModel |
DocumentModel
|
Generated DocumentModel. |
Source code in client/bip/link/document.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 |
|
get(project, slug=None, uid=None)
classmethod
Get a specific DocumentModel or all ProjectModels.
It is possible to get a specific DocumentModel from its uid
or its slug
.
When providing one, the other can be left to None. If none of these two parameters are filled,
The getter becomes a global getter and returns a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
Project
|
str: Parent Project. |
required |
slug |
Optional[str]
|
Optional[str]: Slug of a DocumentModel. If specified, |
None
|
uid |
Optional[str]
|
Optional[str]: Uid of a DocumentModel. If specified, |
None
|
Raises:
Type | Description |
---|---|
LookupError
|
No matching DocumentModel found. |
Returns:
Type | Description |
---|---|
Union[DocumentModel, List[DocumentModel]]
|
|
Union[DocumentModel, List[DocumentModel]]
|
|
Source code in client/bip/link/document.py
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 |
|
get_documents(item)
Convenient class implementation of: bip.link.document.get_items
.
Warning
The signature of DocumentModel.get_documents()
and bip.link.document.get_documents()
are different since DocumentModel.get_documents()
passes itself to the function as model=self
.
Source code in client/bip/link/document.py
888 889 890 891 892 893 894 895 |
|
get_path(item)
Dynamic path of the document model.
The path is dynamically generated by the running Bip client, based on the working directory.
Warning
The path may differ from a machine to another since the path uses the working_directory
local setting, which might vary between machines, depending on the client config.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path of the item model directory. |
Source code in client/bip/link/document.py
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 |
|
save()
Saves the DocumentModel to the database.
If the DocumentModel is floating, saving makes it persistent.
Attributes changes are not applied to the database at modification. Saving the DocumentModel does.
Warning
If the project has a locked model, the operation is not allowed.
Raises:
Type | Description |
---|---|
ValueError
|
Failed validation. |
TypeError
|
Failed validation. |
PermissionError
|
The Project doesn't allow post-creation changes of its data model. |
Source code in client/bip/link/document.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 |
|
get_default_document_model(item)
Get the default DocumentModel of the Bip server, if any.
Returns:
Type | Description |
---|---|
Union[None, DocumentModel]
|
Union[None, DocumentModel]: DocumentModel if a default is set, None otherwise. |
Source code in client/bip/link/document.py
1173 1174 1175 1176 1177 1178 1179 1180 |
|
get_document(model, item, task=None, groups=(), element=None)
Convenient shortcut to Document.get
for getting a specific Document.
Raises:
Type | Description |
---|---|
ValueError
|
No slug and no uid provided. |
Source code in client/bip/link/document.py
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 |
|
get_documents(model, item)
Convenient shortcut to Document.get
for getting all Documents.
Source code in client/bip/link/document.py
1112 1113 1114 |
|
get_from_filename(filename, item)
Convenient shortcut to DocumentModel.generate
.
Source code in client/bip/link/document.py
1183 1184 1185 |
|
get_from_item(item, uid=None)
Convenient shortcut to Document.get_from_item
for getting a
specific Document or all Documents from an Item.
Source code in client/bip/link/document.py
1117 1118 1119 1120 1121 1122 |
|
get_model(project, slug=None, uid=None)
Convenient shortcut to DocumentModel.get
for specific DocumentModel.
Raises:
Type | Description |
---|---|
ValueError
|
No slug and no uid provided. |
Source code in client/bip/link/document.py
1151 1152 1153 1154 1155 1156 1157 1158 1159 |
|
get_models(project)
Convenient shortcut to DocumentModel.get
for all DocumentModels.
Source code in client/bip/link/document.py
1162 1163 1164 |
|
new(model, item, task=None, groups=(), element=None, auto_save=True, **kwargs)
Convenient shortcut to Document.generate
.
Source code in client/bip/link/document.py
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 |
|
new_document(model, item, task=None, groups=(), element=None, auto_save=True, **kwargs)
Convenient shortcut to Document.generate
.
Source code in client/bip/link/document.py
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 |
|
new_model(name, project, auto_save=True, **kwargs)
Convenient shortcut to DocumentModel.generate
.
Source code in client/bip/link/document.py
1167 1168 1169 |
|