Previous topic

5.1.7. controllers.group — Controllers for groups

Next topic

5.1.9. controllers.plmobject — Controllers for plmobjects

This Page

Languages

Previous versions

1.2
1.1

5.1.8. controllers.part — Controllers for parts

class plmapp.controllers.part.Child

Bases: tuple

Child(level, link)

level

itemgetter(item, ...) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After, f=itemgetter(2), the call f(r) returns r[2]. After, g=itemgetter(2,5,3), the call g(r) returns (r[2], r[5], r[3])

itemgetter(item, ...) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After, f=itemgetter(2), the call f(r) returns r[2]. After, g=itemgetter(2,5,3), the call g(r) returns (r[2], r[5], r[3])

class plmapp.controllers.part.Parent

Bases: tuple

Parent(level, link)

level

itemgetter(item, ...) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After, f=itemgetter(2), the call f(r) returns r[2]. After, g=itemgetter(2,5,3), the call g(r) returns (r[2], r[5], r[3])

itemgetter(item, ...) –> itemgetter object

Return a callable object that fetches the given item(s) from its operand. After, f=itemgetter(2), the call f(r) returns r[2]. After, g=itemgetter(2,5,3), the call g(r) returns (r[2], r[5], r[3])

plmapp.controllers.part.unique_justseen(iterable, key=None)[source]

List unique elements, preserving order. Remember only the element just seen.

plmapp.controllers.part.flatten_bom(data)[source]
plmapp.controllers.part.get_last_children(children)[source]
class plmapp.controllers.part.PartController(*args, **kwargs)[source]

Bases: openPLM.plmapp.controllers.plmobject.PLMObjectController

Controller for Part.

This controller adds methods to manage Parent-Child links between two Parts.

can_add_child2
check_add_child(child)[source]

Checks if child can be added to self. If child can not be added, an exception is raised.

Parameters:child (Part) – child to be added
Raises :ValueError if child is already a child or a parent.
Raises :PermissionError if _user is not the owner of object.
precompute_can_add_child2()[source]
can_add_child(child)[source]

Returns True if child can be added to self.

add_child(child, quantity, order, unit='-', **extension_data)[source]

Adds child to self.

Parameters:
  • child (Part) – added child
  • quantity (positive float) – amount of child
  • order (positive int) – order
  • unit – a valid unit

Extra arguments are used to create relevant ParentChildLinkExtension.

Raises :ValueError if child is already a child or a parent.
Raises :ValueError if quantity or order are negative.
Raises :PermissionError if _user is not the owner of object.
Raises :PermissionError if object is not editable.
delete_child(child)[source]

Deletes child from current children and records this action in the history.

Note

The link is not destroyed: its ParentChildLink.end_time is set to now.

Raises :PermissionError if _user is not the owner of object.
Raises :PermissionError if object is not editable.
modify_child(child, new_quantity, new_order, new_unit, **extension_data)[source]

Modifies information about child.

Parameters:
  • child (Part) – added child
  • new_quantity (positive float) – amount of child
  • new_order (positive int) – order

Extra arguments are used to modify relevant ParentChildLinkExtension.

Raises :PermissionError if _user is not the owner of object.
Raises :PermissionError if object is not editable.
replace_child(link, new_child)[source]

Replaces a child by another one.

Parameters:
  • link (ParentChildLink) – link being replaced, its data (extensions included) are copied
  • new_child (Part) – the new child
Raises :

ValueError if the link is invalid (already completed or its parent is not the current object)

Raises :

all permission errors raised by check_add_child()

get_children(max_level=1, date=None, related=('child', 'child__state', 'child__lifecycle'), only_official=False, only=None)[source]

Returns a list of all children at time date.

Parameters:
  • max_level – maximum level of children, -1 returns all descendants, 1 returns direct children
  • related – a list of related fields that are given to retrieve the ParentChildLink
  • only_official – True if the result should be pruned to only include official children
  • only – a list of fields that are given to limit the retrieved field of the ParentChildLink
Return type:

list of Child

is_ancestor(part)[source]

Returns True if part is an ancestor of the current object.

is_ancestor2(part)[source]
get_parents(max_level=1, date=None, related=('parent', 'parent__state', 'parent__lifecycle'), only_official=False, only=None)[source]

Returns a list of all parents at time date.

Parameters:
  • max_level – maximum level of parents, -1 returns all ancestors, 1 returns direct parents
  • related – a list of related fields that are given to retrieve the ParentChildLink
  • only_official – True if the result should be pruned to only include official parents
  • only – a list of fields that are given to limit the retrieved field of the ParentChildLink
Return type:

list of Parent

update_children(formset)[source]

Updates children informations with data from formset

Parameters:formset (a modelfactory_formset of ModifyChildForm) –
Raises :PermissionError if _user is not the owner of object.
Raises :PermissionError if object is not editable.
get_bom(date, level, state='all', show_documents=False, show_alternates=False)[source]

New in version 1.2.

Returns some data about children that will be displayed in BOM view.

Parameters:
  • date – date of the BOM (see get_children())
  • level – level of the BOM, valid options are "first", "all" and "last".
  • state – set to "official" to hide unofficial parts and document
  • show_documents – True if attached document are displayed

It returns a dictionary containing the following keys:

children
list of Child, see get_children()
extra_columens
list of extra column headers (field name, verbose name): its the list of BOMs extensions bound to the object
extension_data
dictionary (link id -> extension values)
level
the given level
documents
dictionary (part id -> document)
states
dictionary (plmobject id -> state) containing the state (str) of displayed objects at date date
obj
this controller
cmp_bom(date1, date2, level='first', state='all', show_documents=False, show_alternates=False)[source]

New in version 1.2.

Compares two BOMs at date date1 and date2.

dates, level, state and show_documents are described in get_bom().

It returns a dictionary containing the following keys:

diff
diff result, it is a sequence of tuples (tag, first BOM rows, second BOM rows) (see difflib.SequenceMatcher.get_opcodes())
boms
tuple of BOMs (at date date1 and date date2)
revise(new_revision, child_links=None, documents=(), parents=(), **kwargs)[source]

Revises the part. Does the same thing as PLMObjectController.revise() and:

  • copies all ParentChildLink of child_links, with the new revision as the new parent. If child_links is None (the default), all current children are copied. If an empty sequence is given, no links are copied.
  • attaches all document of documents, by default, no documents are attached. The method get_suggested_documents() returns a list of documents that should be interesting.
  • replaces all parent links in parents. This arguments must be a list of tuples (link (an instance of ParentChildLink), parent (an instance of PLMObject)) where parent is the parent whose the bom will be modified and link is the source of data (quantity, unit, order...). link will be ended if parent is a parent of the current part. The method get_suggested_parents() returns a list of tuples that may interest the user who revises this part.
get_suggested_documents()[source]

Returns a QuerySet of documents that should be suggested when the user revises the part.

A document is suggested if:

  1. it is attached to the current part and:

    1. it is a draft and its superior revisions, if they exist, are not attached to the part

      or

    2. it is official and its superior revisions, if they exist, are not attached to the part

      or

    3. it is official and a superior revision is attached and another superior revision is not attached to the part

  2. it is not attached to the current part, an inferior revision is attached to the part and:

    1. it is a draft

      or

    2. it is official

get_suggested_parents()[source]

Returns a list of suggested parents that should be suggested when the part is revised.

This method returns a list of tuple (link (an instance of ParentChildLink), parent (an instance of PLMObject)). It does not returns a list of links, since it may suggest a part that is not a parent but whose one of its previous revision is a parent. We need a link to copy its data (order, quantity, unit and extensions).

A part is suggested as a parent if:

  1. it is already a parent and:

    1. no superior revisions are a parent and its state is draft or official

      or

    2. no superior revisions exist and its state is proposed.

  2. it is not a parent, a previous revision is a parent, its state is a draft or a parent. In that case, the link of the most superior parent revision is used.

attach_to_document(document)[source]

Links document (a Document) with object.

Raises :PermissionError if _user is not the owner of object.
detach_document(document)[source]

Delete link between document (a Document) and object.

Raises :PermissionError if _user is not the owner of object.
get_attached_documents(time=None)[source]

Returns all Document attached to object.

get_detachable_documents()[source]

Returns all attached documents the user can detach.

is_document_attached(document)[source]

Returns True if document is attached to the current part.

check_attach_document(document, detach=False)[source]
can_attach_document(document)[source]

Returns True if document can be attached to the current part.

can_detach_document(document)[source]

Returns True if document can be detached.

update_doc_cad(formset)[source]

Updates doc_cad informations with data from formset

Parameters:formset (a modelfactory_formset of ModifyChildForm) –
Raises :ValueError if one of the document is not detachable.
cancel()[source]

Cancels the object:

check_cancel(raise_=True)[source]
clone(form, user, child_links, documents, block_mails=False, no_index=False)[source]

Clones the object :

calls PLMObjectController.clone()

Parameters:
  • child_links – list of ParentChildLink selected to be cloned with the new part as parent
  • documents – list of Document selected to be attached to the new part

Return true if the part :

  • is a parent or a child
  • is attached to at least one document
get_cad_files()[source]

Returns an iterable of all DocumentFile related to part that contain a CAD file. It retrieves all non deprecated files of all documents parts to part and its children and filters these files according to their extension (see is_cad_file()).

check_add_alternate(part, check_perm=True)[source]
add_alternate(part, check_perm=True)[source]
can_add_alternate(part)[source]
is_alternate(part)[source]
delete_alternate(part)[source]
end_alternate()[source]
get_alternates(date=None)[source]
promote(*args, **kwargs)[source]
promote_assembly(*args, **kwargs)[source]
object