Пример #1
0
def display_children(request, obj_type, obj_ref, obj_revi):
    """
    BOM view.

    That view displays the children of the selected object that must be a part.

    :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/bom-child/`

    .. include:: views_params.txt

    **Template:**

    :file:`parts/bom.html`

    **Context:**

    ``RequestContext``

    ``children``
        a list of :class:`.Child`

    ``display_form``
        a :class:`.DisplayChildrenForm`

    ``extra_columns``
        a list of extra columns that are displayed

    ``extension_data``

    ``decomposition_msg``
        a html message to decompose the part (may be empty)

    ``decomposable_children``
        a set of child part ids that are decomposable
    """
    if "diff" in request.GET:
        query = request.GET.urlencode() + "&compact=on"
        return HttpResponseRedirect("%sdiff/?%s" % (request.path, query))
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)

    if not hasattr(obj, "get_children"):
        return HttpResponseBadRequest("object must be a part")
    date = None
    level = "first"
    state = "all"
    show_documents = show_alternates = False
    if request.GET:
        display_form = forms.DisplayChildrenForm(request.GET)
        if display_form.is_valid():
            date = display_form.cleaned_data["date"]
            level = display_form.cleaned_data["level"]
            state = display_form.cleaned_data["state"]
            show_documents = display_form.cleaned_data["show_documents"]
            show_alternates = display_form.cleaned_data["show_alternates"]
    else:
        display_form = forms.DisplayChildrenForm(initial={"date" : timezone.now(),
            "level" : "first", "state":"all"})
    ctx.update(obj.get_bom(date, level, state, show_documents, show_alternates))
    # decomposition
    if DecomposersManager.count() > 0:
        children_ids = (c.link.child_id for c in ctx["children"])
        decomposable_children = DecomposersManager.get_decomposable_parts(children_ids)
        decomposition_msg = DecomposersManager.get_decomposition_message(obj)
    else:
        decomposition_msg = ""
        decomposable_children = []
    ctx.update({'current_page' : 'BOM-child',
                'decomposition_msg' : decomposition_msg,
                'decomposable_children' : decomposable_children,
                "display_form" : display_form,
                })
    return r2r('parts/bom.html', ctx, request)
Пример #2
0
def display_children(request, obj_type, obj_ref, obj_revi):
    """
    BOM view.

    That view displays the children of the selected object that must be a part.

    :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/bom-child/`

    .. include:: views_params.txt

    **Template:**

    :file:`parts/bom.html`

    **Context:**

    ``RequestContext``

    ``children``
        a list of :class:`.Child`

    ``display_form``
        a :class:`.DisplayChildrenForm`

    ``extra_columns``
        a list of extra columns that are displayed

    ``extension_data``

    ``decomposition_msg``
        a html message to decompose the part (may be empty)

    ``decomposable_children``
        a set of child part ids that are decomposable
    """
    if "diff" in request.GET:
        query = request.GET.urlencode() + "&compact=on"
        return HttpResponseRedirect("%sdiff/?%s" % (request.path, query))
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)

    if not hasattr(obj, "get_children"):
        return HttpResponseBadRequest("object must be a part")
    date = None
    level = "first"
    state = "all"
    show_documents = show_alternates = False
    if request.GET:
        display_form = forms.DisplayChildrenForm(request.GET)
        if display_form.is_valid():
            date = display_form.cleaned_data["date"]
            level = display_form.cleaned_data["level"]
            state = display_form.cleaned_data["state"]
            show_documents = display_form.cleaned_data["show_documents"]
            show_alternates = display_form.cleaned_data["show_alternates"]
    else:
        display_form = forms.DisplayChildrenForm(initial={
            "date": timezone.now(),
            "level": "first",
            "state": "all"
        })
    ctx.update(obj.get_bom(date, level, state, show_documents,
                           show_alternates))
    # decomposition
    if DecomposersManager.count() > 0:
        children_ids = (c.link.child_id for c in ctx["children"])
        decomposable_children = DecomposersManager.get_decomposable_parts(
            children_ids)
        decomposition_msg = DecomposersManager.get_decomposition_message(obj)
    else:
        decomposition_msg = ""
        decomposable_children = []
    ctx.update({
        'current_page': 'BOM-child',
        'decomposition_msg': decomposition_msg,
        'decomposable_children': decomposable_children,
        "display_form": display_form,
    })
    return r2r('parts/bom.html', ctx, request)
Пример #3
0
                    decomposable=True).values_list("stp__document", "stp"))
                for doc_id, part_id in links:
                    if (doc_id not in valid_docs) or (part_id in decomposable):
                        continue
                    stp = pmodels.DocumentFile.objects.only("document", "filename").get(id=valid_docs[doc_id])
                    if stp.checkout_valid:
                        decomposable.add(part_id)
        return decomposable

    def get_message(self):
        if self.decompose_valid:
            return render_to_string("decompose_msg.html", { "part" : self.part,
                "decomposable_docs" : self.decompose_valid })
        return ""

DecomposersManager.register(StepDecomposer)

PartDoc = namedtuple("PartDoc", "part_type qty_form cforms name is_assembly prefix ref")
Assembly = namedtuple("Assembly", ("part_docs", "name", "visited", "depth", "type"))

INVALID_TIME_ERROR = "Error: document has been modified since the beginning of this task."

@handle_errors
def display_decompose(request, obj_type, obj_ref, obj_revi, stp_id):


    """
    :param obj_type: Type of the :class:`.Part` from which we want to realize the decomposition
    :param obj_ref: Reference of the :class:`.Part` from which we want to realize the decomposition
    :param obj_revi: Revision of the :class:`.Part` from which we want to realize the decomposition
    :param stp_id: Id that identify the :class:`.DocumentFile` contained in a :class:`.Document3D` attached to the :class:`.Part` (identified by **obj_type**, **obj_ref**, **obj_revi**) that we will decompose