Table des matières

Sujet précédent

5.11. mail — Tools to send mails

Sujet suivant

5.13. navigate — Tools to generate navigation’s graph

Cette page

Autres langues

5.12. models — models for openPLM

5.12.1. Introduction

Models for openPLM

This module contains openPLM’s main models.

There are 5 kinds of models:

5.12.2. Inheritance diagrams

5.12.2.1. Users and groups

Inheritance diagram of openPLM.plmapp.models.user, openPLM.plmapp.models.group

5.12.2.2. Lifecycles

Inheritance diagram of openPLM.plmapp.models.lifecycle

5.12.2.3. PLMObjects

Inheritance diagram of openPLM.plmapp.models.plmobject, openPLM.plmapp.models.part, openPLM.plmapp.models.document

5.12.2.4. Histories

Inheritance diagram of openPLM.plmapp.models.history

5.12.3. Classes and functions

Note

This module imports all the following functions and classes.

openPLM.plmapp.models.import_models(force_reload=False)[source]

Imports recursively all modules in directory plmapp/customized_models

5.12.4. models.user

class openPLM.plmapp.models.user.UserProfile(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Profile for a User

is_administrator = None

True if user is an administrator

is_contributor = None

True if user is a contributor

can_publish = None

Introduit dans la version 1.1: True if user can publish a plmobject

restricted = None

Introduit dans la version 1.1: True if user has a restricted account

language = None

language

is_viewer[source]

True if user is just a viewer, i.e: not an adminstrator and not a contributor.

rank[source]

Rank of the user: “administrator”, “contributor” or “viewer”

attributes[source]

Attributes to display in Attributes view

openPLM.plmapp.models.user.add_profile(sender, instance, created, **kwargs)[source]

function called when a user is created to add his profile

5.12.5. models.group

class openPLM.plmapp.models.group.GroupInfo(*args, **kwargs)[source]

Bases: django.contrib.auth.models.Group

Class that stores additional data on a Group.

attributes[source]

Attributes to display in Attributes view

menu_items[source]

menu items to choose a view

classmethod get_creation_fields()[source]

Returns fields which should be displayed in a creation form.

classmethod get_modification_fields()[source]

Returns fields which should be displayed in a modification form

class openPLM.plmapp.models.group.Invitation(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Invitation(group_id, owner_id, guest_id, state, ctime, validation_time, guest_asked, token)

5.12.6. models.lifecycle

class openPLM.plmapp.models.lifecycle.State(*args, **kwargs)[source]

Bases: django.db.models.base.Model

State : object which represents a state in a lifecycle

name

name of the state, must be unique

class openPLM.plmapp.models.lifecycle.Lifecycle(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Lifecycle : object which represents a lifecycle

name

name of the lifecycle, must be unique

official_state

official State of the lifecycle

Note

A Lifecycle is iterable and each iteration returns a string of the next state.

Voir aussi

LifecycleList A class that simplifies the usage of a LifeCycle

to_states_list()[source]

Converts a Lifecycle to a LifecycleList (a list of strings)

classmethod from_lifecyclelist(cycle)[source]

Builds a Lifecycle from cycle. The built object is save in the database. This function creates states which were not in the database

Paramètres:cycle (LifecycleList) – the cycle used to build the Lifecycle
Retourne:a Lifecycle
class openPLM.plmapp.models.lifecycle.LifecycleStates(*args, **kwargs)[source]

Bases: django.db.models.base.Model

A LifecycleStates links a Lifecycle and a State.

The link is made with a field rank to order the states.

openPLM.plmapp.models.lifecycle.get_default_lifecycle()[source]

Returns the default Lifecycle used when instanciate a PLMObject

openPLM.plmapp.models.lifecycle.get_cancelled_lifecycle()[source]

Returns the “cancelled” Lifecycle.

openPLM.plmapp.models.lifecycle.get_cancelled_state()[source]

Returns the “cancelled” State.

openPLM.plmapp.models.lifecycle.get_default_state(lifecycle=None)[source]

Returns the default State used when instanciate a PLMObject. It’s the first state of the default lifecycle.

5.12.7. models.plmobject

openPLM.plmapp.models.plmobject.cache_lifecycle_stuff(func)[source]

A decorator that caches the result of func.

func must take one argument: a PLMObject and its returned value should only depends on the state and the lifecycle of the given PLMObject (and not its type).

The maximum cache size will be the number of LifecycleStates. Each key of the cache is a tuple (state’s name, lifecycle’s name).

class openPLM.plmapp.models.plmobject.PLMObjectQuerySet(model=None, query=None, using=None)[source]

Bases: django.db.models.query.QuerySet

A QuerySet with extra methods to filter results by their state.

officials()[source]

Retrieves only official PLMObject.

exclude_cancelled()[source]

Excludes cancelled PLMObject.

class openPLM.plmapp.models.plmobject.PLMObjectManager[source]

Bases: django.db.models.manager.Manager

Manager for PLMObject. Uses a PLMObjectQuerySet.

officials()[source]

Retrieves only official PLMObject.

exclude_cancelled()[source]

Excludes cancelled PLMObject.

class openPLM.plmapp.models.plmobject.AbstractPLMObject(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Abstract model that redefines the PLMObject.objects manager.

This model is abstract so that child classes inherits the manager.

class openPLM.plmapp.models.plmobject.PLMObject(*args, **kwargs)[source]

Bases: openPLM.plmapp.models.plmobject.AbstractPLMObject

Base class for Part and Document.

A PLMObject is identified by a triplet reference/type/revision

Key attributes:
reference

Reference of the PLMObject, for example YLTG00

type

Type of the PLMObject, for example Game

revision

Revision of the PLMObject, for example a

Other attributes:
 
name

Name of the product, for example Game of life

creator

User who created the PLMObject

creator

User who owns the PLMObject

ctime

date of creation of the object (default value : current time)

mtime

date of last modification of the object (automatically field at each save)

lifecycle

Lifecycle of the object

state

Current State of the object

group

GroupInfo that owns the object

published

Introduit dans la version 1.1.

True if the object is published (accessible to anonymous user)

reference_number

Introduit dans la version 1.1.

number found in the reference if it matches PART_|DOC_\d+

description

Introduit dans la version 1.3.

a short description of the object. This field is optional and is a richtext field.

Note

This class is abstract, to create a PLMObject, see Part and Document.

Modifié dans la version 1.1: published and reference_number added.

_is_promotable()[source]

Returns True if the object’s state is the last state of its lifecycle.

is_promotable()[source]

Returns True if object is promotable

Note

This method is abstract and raises NotImplementedError. This method must be overriden.

_get_promotion_errors()[source]

Returns an ErrorList of promotion errors. Calls is_promotable() if it has not already been called.

promotion_errors

Returns an ErrorList of promotion errors. Calls is_promotable() if it has not already been called.

is_cloneable[source]

Introduit dans la version 1.1.

Return true by default. This property may be overriden by custom Part or Document

is_editable[source]

True if the object is not in a non editable state

is_proposed[source]

True if the object is in a state prior to the official state but not draft.

Note

The result of this function is cached with _cache_lifecycle_stuff().

is_cancelled[source]

True if the object is cancelled.

Note

The result of this function is cached with _cache_lifecycle_stuff().

is_deprecated[source]

True if the object is deprecated.

Note

The result of this function is cached with _cache_lifecycle_stuff().

is_official[source]

Returns True if object is official.

Note

The result of this function is cached with _cache_lifecycle_stuff().

is_draft[source]

Returns True if the object is a draft.

Note

The result of this function is cached with _cache_lifecycle_stuff().

get_current_sign_level(plmobject)[source]

Returns the current sign level that a user must have to promote this object.

Note

The result of this function is cached with _cache_lifecycle_stuff().

get_previous_sign_level(plmobject)[source]

Returns the current sign level that a user must have to demote this object.

Note

The result of this function is cached with _cache_lifecycle_stuff().

is_part[source]

True if the plmobject is a part.

is_document[source]

True if the plmobject is a document.

attributes[source]

Attributes to display in Attributes view

published_attributes[source]

Introduit dans la version 1.1.

Attributes that are visible to everyone if the object has been published.

menu_items[source]

Menu items to choose a view

classmethod excluded_creation_fields()[source]

Returns fields which should not be available in a creation form

classmethod get_creation_fields()[source]

Returns fields which should be displayed in a creation form.

By default, it returns attributes less attributes returned by excluded_creation_fields()

classmethod excluded_modification_fields()[source]

Returns fields which should not be available in a modification form

classmethod get_modification_fields()[source]

Returns fields which should be displayed in a modification form

By default, it returns attributes less attributes returned by excluded_modification_fields()

openPLM.plmapp.models.plmobject.get_all_plmobjects()[source]

Returns a dict<name, class> of all available PLMObject subclasses

5.12.8. models.part

class openPLM.plmapp.models.part.PartQuerySet(model=None, query=None, using=None)[source]

Bases: openPLM.plmapp.models.plmobject.PLMObjectQuerySet

A PLMObjectQuerySet with extra methods to annotate results with the number of children or parents.

with_children_counts()[source]

Annotates results with the number of children (field num_children).

with_parents_counts()[source]

Annotates results with the number of parents (field num_parents).

class openPLM.plmapp.models.part.PartManager[source]

Bases: openPLM.plmapp.models.plmobject.PLMObjectManager

Manager for Part. Uses a PartQuerySet.

with_children_counts()[source]

Shorcut for self.get_query_set().with_children_counts(). See PartQuerySet.with_children_counts().

with_parents_counts()[source]

Shorcut for self.get_query_set().with_parents_counts(). See PartQuerySet.with_parents_counts().

class openPLM.plmapp.models.part.TopAssemblyManager[source]

Bases: openPLM.plmapp.models.part.PartManager

A PartManager that returns only top assemblies. A top assemblies is a part with at least one child and no parents.

class openPLM.plmapp.models.part.AbstractPart(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Abstract model that defines two managers:

objects

default manager, a PartManager

top_assemblies:

a TopAssemblyManager

class openPLM.plmapp.models.part.Part(*args, **kwargs)[source]

Bases: openPLM.plmapp.models.part.AbstractPart, openPLM.plmapp.models.plmobject.PLMObject

Model for parts

is_promotable()[source]

Returns True if the part is promotable.

A part is promotable if:

  1. its state is not the last state of its lifecycle

  2. if the part is official.

  3. the part is draft or proposed and:

    1. there is a next state in its lifecycle and if its children

      which have the same lifecycle are in a state as mature as the object’s state.

    2. if the part has no children, there is at least one official document attached to it.

openPLM.plmapp.models.part.get_all_parts()[source]

Returns a dict<part_name, part_class> of all available Part classes

5.12.9. models.document

class openPLM.plmapp.models.document.DocumentStorage(location=None, base_url=None)[source]

Bases: django.core.files.storage.FileSystemStorage

File system storage which stores files with a specific name

get_available_name(name)[source]

Returns a path for a file name, the path always refers to a file which does not already exist.

The path is computed as follow:
  1. a directory which name is the last extension of name. For example, it is .gz if name is .a.tar.gz. If name does not have an extension, the directory is .no_ext/.

  2. a file name with 4 parts:
    1. the md5 sum of name
    2. a dash separator: -
    3. a random part with 7 characters in [a-z0-9]
    4. the extension, like .gz

For example, if name is .my_file.tar.gz, a possible output is:

.gz/c7bfe8d00ea6e7138215ebfafff187af-jj6789g.gz

If name is .my_file, a possible output is:

.no_ext/59c211e8fc0f14b21c78c87eafe1ab72-dhh5555
openPLM.plmapp.models.document.docfs = <openPLM.plmapp.models.document.DocumentStorage object at 0x4de1610>

DocumentStorage instance which stores files in settings.DOCUMENTS_DIR

openPLM.plmapp.models.document.thumbnailfs = <django.core.files.storage.FileSystemStorage object at 0x4de1690>

FileSystemStorage instance which stores thumbnails in settings.THUMBNAILS_DIR

class openPLM.plmapp.models.document.DocumentFile(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Modifié dans la version 1.2: New attributes: ctime, end_time, deleted, revision, previous_revision, last_revision

Model which stores informations of a file bounded to a Document

Model attributes:
 
filename

original filename

file

file stored in docfs

size

size of the file in Byte

locked

True if the file is locked

locker

User who locked the file, None, if the file is not locked

document

Document bounded to the file (required)

ctime

date of creation of the document file

end_time

date of creation of the next revision or None if it is the last revision

revision

revision number (starts at 1)

previous_revision

DocumentFile or None if it’s the first revision

last_revision

foreign key to the last revision (DocumentFile) or None it it’is the last_revision

deleted

True if the file has been physically removed

Returns the native DocumentFile related to this DocumentFile if settings.ENABLE_NATIVE_FILE_MANAGEMENT is True.

Returns False if there are no native DocumentFile related.

checkout_valid[source]

Returns False if DocumentFile has a native related locked file and settings.ENABLE_NATIVE_FILE_MANAGEMENT is True.

class openPLM.plmapp.models.document.PrivateFile(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Introduit dans la version 1.2.

Model which stores informations of a private file only readable by its creator.

There are no revision, locker, deleted or similar attributes. A private file is not shared, and it is temporary. It is created to store a file before a document creation.

Private files are created when a user uploads files and then creates a document containing these files.

Model attributes:
 
filename

original filename

file

file stored in docfs

size

size of the file in Byte

creator

User who created the file,

ctime
date of creation of the file
class openPLM.plmapp.models.document.Document(*args, **kwargs)[source]

Bases: openPLM.plmapp.models.plmobject.PLMObject

Model for documents

files[source]

Queryset of all non deprecated DocumentFile linked to self

deprecated_files[source]

Queryset of all deprecated DocumentFile linked to self

is_promotable()[source]

Returns True if the object is promotable. A document is promotable if there is a next state in its lifecycle and if it has at least one file and if none of its files are locked.

classmethod get_creation_score(files)[source]

Introduit dans la version 1.3.

Returns a score (an integer) computed from files. files is a list of PrivateFile uploaded by a user who wants to create a document with all files.

The class which returns the highest score is chosen has the default type after an upload.

The default implementation returns 10 if the current class is Document and 0 otherwise.

For example, Document3D returns 50 if a CAD file has been uploaded. Document3D is so preferred when a STEP file is uploaded.

openPLM.plmapp.models.document.get_all_documents()[source]

Returns a dict<doc_name, doc_class> of all available Document classes

openPLM.plmapp.models.document.get_all_subtype_documents(subtype)[source]

Returns a dict<doc_name, doc_class> of all available subtype classes

openPLM.plmapp.models.document.get_best_document_type(files)[source]

Introduit dans la version 1.3.

Returns the document type (str) which returns the highest creation score for the uploaded files (list of PrivateFile).

5.12.10. models.history

class openPLM.plmapp.models.history.AbstractHistory(*args, **kwargs)[source]

Bases: django.db.models.base.Model

History model. This model records all events related to PLMObject

Model attributes:
 
plmobject

PLMObject of the event

action

type of action (see ACTIONS)

details

type of action (see ACTIONS)

date

date of the event

user

User who maded the event

Class attribute:
 
ACTIONS = (('Create', 'Create'), ('Delete', 'Delete'), ('Modify', 'Modify'), ('Revise', 'Revise'), ('Promote', 'Promote'), ('Demote', 'Demote'), ('Cancel', 'Cancel'), ('Publish', 'Publish'), ('Unpublish', 'Unpublish'))

some actions available in the admin interface

class openPLM.plmapp.models.history.History(*args, **kwargs)[source]

Bases: openPLM.plmapp.models.history.AbstractHistory

History(id, action, details, date, user_id, plmobject_id)

class openPLM.plmapp.models.history.UserHistory(*args, **kwargs)[source]

Bases: openPLM.plmapp.models.history.AbstractHistory

UserHistory(id, action, details, date, user_id, plmobject_id)

class openPLM.plmapp.models.history.GroupHistory(*args, **kwargs)[source]

Bases: openPLM.plmapp.models.history.AbstractHistory

GroupHistory(id, action, details, date, user_id, plmobject_id)

class openPLM.plmapp.models.history.StateHistoryQuerySet(model=None, query=None, using=None)[source]

Bases: django.db.models.query.QuerySet

QuerySet with utility methods to filter StateHistory alive at a given time.

now()[source]

Filters state histories: keeps only alive state histories (end_time is null).

at(time)[source]

Filters state histories: keeps alive state histories at time time.

Paramètres:time – a datetime or None
officials()[source]

Filters only official state histories.

class openPLM.plmapp.models.history.StateHistoryManager[source]

Bases: django.db.models.manager.Manager

state histories manager, returns a StateHistoryQuerySet.

now()[source]

Shorcut for self.get_query_set().now(). See StateHistoryQuerySet.now().

at(time)[source]

Shorcut for self.get_query_set().at(time). See StateHistoryQuerySet.at().

officials()[source]

Shorcut for self.get_query_set().officials(). See StateHistoryQuerySet.officials().

class openPLM.plmapp.models.history.StateHistory(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Models that tracks the promotions and demotions of a PLMObject.

Model attributes:
 
plmobject

PLMObject that has been promoted/demoted.

start_time

date of the promotion/demotion

end_time

date of the next promotion/demotion, None if the promotion is the latest promotion

state

State of plmobject at t, if start_time <= t < end_time

lifecycle

Lifecycle of plmobject at t, if start_time <= t < end_time

state_category

state’s category of plmobject at t, if start_time <= t < end_time. This field is redundant with the tuple (state, lifecycle) but it allows fast queries to check if an object was official at a given time. This attribute is automatically set when the object is saved.

Valid state’s categories are:

DRAFT

set if PLMObject.is_draft() returns True

PROPOSED

set if PLMObject.is_proposed() returns True

OFFICIAL

set if PLMObject.is_official() returns True

DEPRECATED

set if PLMObject.is_deprecated() returns True

CANCELLED

set if PLMObject.is_cancelled() returns True

openPLM.plmapp.models.history._save_comment_history(sender, comment, request, **kwargs)[source]

Save an history line when a comment is posted.