Ejemplo n.º 1
0
def display_doc_cad(request, obj_type, obj_ref, obj_revi):
    """
    Attached documents view.

    That view displays the documents attached to the selected object that must be a part.

    :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/doc-cad/`

    .. include:: views_params.txt

    **Template:**

    :file:`parts/doccad.html`

    **Context:**

    ``RequestContext``

    ``documents``
        a queryset of :class:`.DocumentPartLink` bound to the part

    ``archive_formats``
        list of available archive formats

    ``docs_formset``
        a formset to detach documents

    ``forms``
        a dictionary (link_id -> form) to get the form related to a link
        (a document may not be "detachable")

    """
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)

    if not hasattr(obj, "get_attached_documents"):
        return HttpResponseBadRequest("object must be a part")
    if request.method == "POST":
        formset = forms.get_doc_cad_formset(obj, request.POST)
        if formset.is_valid():
            obj.update_doc_cad(formset)
            return HttpResponseRedirect(".")
    else:
        formset = forms.get_doc_cad_formset(obj)
    dforms = dict((form.instance.id, form) for form in formset.forms)
    documents = obj.get_attached_documents()
    ctx.update({
        'current_page': 'doc-cad',
        'documents': documents,
        'forms': dforms,
        'archive_formats': ARCHIVE_FORMATS,
        'docs_formset': formset,
    })
    ctx.update(get_id_card_data([d.document.id for d in documents]))
    return r2r('parts/doccad.html', ctx, request)
Ejemplo n.º 2
0
def display_doc_cad(request, obj_type, obj_ref, obj_revi):
    """
    Attached documents view.

    That view displays the documents attached to the selected object that must be a part.

    :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/doc-cad/`

    .. include:: views_params.txt

    **Template:**

    :file:`parts/doccad.html`

    **Context:**

    ``RequestContext``

    ``documents``
        a queryset of :class:`.DocumentPartLink` bound to the part

    ``archive_formats``
        list of available archive formats

    ``docs_formset``
        a formset to detach documents

    ``forms``
        a dictionary (link_id -> form) to get the form related to a link
        (a document may not be "detachable")

    """
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)

    if not hasattr(obj, "get_attached_documents"):
        return HttpResponseBadRequest("object must be a part")
    if request.method == "POST":
        formset = forms.get_doc_cad_formset(obj, request.POST)
        if formset.is_valid():
            obj.update_doc_cad(formset)
            return HttpResponseRedirect(".")
    else:
        formset = forms.get_doc_cad_formset(obj)
    dforms = dict((form.instance.id, form) for form in formset.forms)
    documents = obj.get_attached_documents()
    ctx.update({'current_page':'doc-cad',
                'documents': documents,
                'forms' : dforms,
                'archive_formats' : ARCHIVE_FORMATS,
                'docs_formset': formset,
    })
    ctx.update(get_id_card_data([d.document.id for d in documents]))
    return r2r('parts/doccad.html', ctx, request)
Ejemplo n.º 3
0
def display_parts(request, obj_type, obj_ref, obj_revi):
    """
    Attached parts view.

    That view displays the parts attached to the selected object that must be a document.

    :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/parts/`

    .. include:: views_params.txt

    **Template:**

    :file:`documents/parts.html`

    **Context:**

    ``RequestContext``

    ``parts``
        a queryset of :class:`.DocumentPartLink` bound to the document

    ``parts_formset``
        a formset to detach parts

    ``forms``
        a dictionary (link_id -> form) to get the form related to a link
        (a part may not be "detachable")
    """
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)

    if not hasattr(obj, "get_attached_parts"):
        return HttpResponseBadRequest("object must be a document")
    if request.method == "POST":
        formset = forms.get_rel_part_formset(obj, request.POST)
        if formset.is_valid():
            obj.update_rel_part(formset)
            return HttpResponseRedirect(".")
    else:
        formset = forms.get_rel_part_formset(obj)
    rforms = dict((form.instance.id, form) for form in formset.forms)
    parts = obj.get_attached_parts()
    ctx.update({'current_page':'parts',
                'parts': parts,
                'forms' : rforms,
                'parts_formset': formset})
    if request.session.get("as_table"):
        ctx.update(get_id_card_data([p.id for p in parts]))
    return r2r('documents/parts.html', ctx, request)
Ejemplo n.º 4
0
def display_parts(request, obj_type, obj_ref, obj_revi):
    """
    Attached parts view.

    That view displays the parts attached to the selected object that must be a document.

    :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/parts/`

    .. include:: views_params.txt

    **Template:**

    :file:`documents/parts.html`

    **Context:**

    ``RequestContext``

    ``parts``
        a queryset of :class:`.DocumentPartLink` bound to the document

    ``parts_formset``
        a formset to detach parts

    ``forms``
        a dictionary (link_id -> form) to get the form related to a link
        (a part may not be "detachable")
    """
    obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi)

    if not hasattr(obj, "get_attached_parts"):
        return HttpResponseBadRequest("object must be a document")
    if request.method == "POST":
        formset = forms.get_rel_part_formset(obj, request.POST)
        if formset.is_valid():
            obj.update_rel_part(formset)
            return HttpResponseRedirect(".")
    else:
        formset = forms.get_rel_part_formset(obj)
    rforms = dict((form.instance.id, form) for form in formset.forms)
    parts = obj.get_attached_parts()
    ctx.update({"current_page": "parts", "parts": parts, "forms": rforms, "parts_formset": formset})
    if request.session.get("as_table"):
        ctx.update(get_id_card_data([p.id for p in parts]))
    return r2r("documents/parts.html", ctx, request)
Ejemplo n.º 5
0
def revise_document(obj, ctx, request):
    """
    View to revise a document.

    :param obj: displayed document
    :type obj: :class:`.DocumentController`
    :param ctx: initial context
    :type ctx: dict
    :param request: riven request

    This view can create a new revision of the document, it required
    the following POST parameters:

    :post params:
        revision
            new revision of the document
        a valid :class:`.SelectPartFormset`
            Only required if *confirmation* is True, see below.


    A revised document may be attached to some parts.
    These parts are given by :meth:`.DocumentController.get_suggested_parts`.
    If there is at least one suggested part, a confirmation of which
    parts will be attached to the new document is required.

    **Template:**

    :file:`documents/revisions.html`

    **Context:**

    ``RequestContext``

    ``confirmation``
        True if a confirmation is required to revise the document.

    ``revisions``
        list of revisions of the document

    ``add_revision_form``
        form to revise the document. Only set if the document is revisable.

    ``part_formset``
        a :class:`.SelectPartFormset` of parts that the new revision
        may be attached to. Only set if *confirmation* is True.
    """
    confirmation = False
    add_form = ctx["add_revision_form"]
    if add_form is not None:
        parts = obj.get_suggested_parts()
        confirmation = bool(parts)

        if request.method == "POST" and request.POST:
            selected_parts = []
            valid_forms = True
            if confirmation:
                part_formset = forms.SelectPartFormset(request.POST)
                ctx["part_formset"] = part_formset
                if part_formset.is_valid():
                    for form in part_formset.forms:
                        part = form.instance
                        if part not in parts:
                            # invalid data
                            # a user should not be able to go here if he
                            # does not write by hand its post request
                            # so we do not need to generate an error message
                            valid_forms = False
                            break
                        if form.cleaned_data["selected"]:
                            selected_parts.append(part)
                else:
                    valid_forms = False
            if add_form.is_valid() and valid_forms:
                obj.revise(add_form.cleaned_data["revision"], selected_parts,
                        group=add_form.cleaned_data["group"])
                return HttpResponseRedirect(".")
        else:
            if confirmation:
                ctx["part_formset"] = forms.SelectPartFormset(queryset=parts)
    ctx["confirmation"] = confirmation
    revisions = obj.get_all_revisions()

    ctx.update(get_id_card_data([r.id for r in revisions]))
    ctx.update({'current_page' : 'revisions',
                'revisions' : revisions,
                })
    return r2r('documents/revisions.html', ctx, request)
Ejemplo n.º 6
0
def revise_document(obj, ctx, request):
    """
    View to revise a document.

    :param obj: displayed document
    :type obj: :class:`.DocumentController`
    :param ctx: initial context
    :type ctx: dict
    :param request: riven request

    This view can create a new revision of the document, it required
    the following POST parameters:

    :post params:
        revision
            new revision of the document
        a valid :class:`.SelectPartFormset`
            Only required if *confirmation* is True, see below.


    A revised document may be attached to some parts.
    These parts are given by :meth:`.DocumentController.get_suggested_parts`.
    If there is at least one suggested part, a confirmation of which
    parts will be attached to the new document is required.

    **Template:**

    :file:`documents/revisions.html`

    **Context:**

    ``RequestContext``

    ``confirmation``
        True if a confirmation is required to revise the document.

    ``revisions``
        list of revisions of the document

    ``add_revision_form``
        form to revise the document. Only set if the document is revisable.

    ``part_formset``
        a :class:`.SelectPartFormset` of parts that the new revision
        may be attached to. Only set if *confirmation* is True.
    """
    confirmation = False
    add_form = ctx["add_revision_form"]
    if add_form is not None:
        parts = obj.get_suggested_parts()
        confirmation = bool(parts)

        if request.method == "POST" and request.POST:
            selected_parts = []
            valid_forms = True
            if confirmation:
                part_formset = forms.SelectPartFormset(request.POST)
                ctx["part_formset"] = part_formset
                if part_formset.is_valid():
                    for form in part_formset.forms:
                        part = form.instance
                        if part not in parts:
                            # invalid data
                            # a user should not be able to go here if he
                            # does not write by hand its post request
                            # so we do not need to generate an error message
                            valid_forms = False
                            break
                        if form.cleaned_data["selected"]:
                            selected_parts.append(part)
                else:
                    valid_forms = False
            if add_form.is_valid() and valid_forms:
                obj.revise(add_form.cleaned_data["revision"], selected_parts,
                        group=add_form.cleaned_data["group"])
                return HttpResponseRedirect(".")
        else:
            if confirmation:
                ctx["part_formset"] = forms.SelectPartFormset(queryset=parts)
    ctx["confirmation"] = confirmation
    revisions = obj.get_all_revisions()

    ctx.update(get_id_card_data([r.id for r in revisions]))
    ctx.update({'current_page' : 'revisions',
                'revisions' : revisions,
                })
    return r2r('documents/revisions.html', ctx, request)