Changeset 65 in main for trunk/openPLM/plmapp/views.py


Ignore:
Timestamp:
07/05/10 13:22:31 (11 years ago)
Author:
pjoulaud
Message:

Addition of files upload/deletion in a document

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/views.py

    r61 r65  
    402402    context_dict.update(var_dict) 
    403403    return render_to_response('DisplayObjectDocCad.htm', context_dict) 
     404     
     405     
     406 
     407    if not hasattr(obj, "get_attached_parts"): 
     408        # TODO 
     409        raise TypeError() 
     410    if request.method == "POST": 
     411        print request.POST.items() 
     412        formset = get_rel_part_formset(obj, request.POST) 
     413        if formset.is_valid(): 
     414            obj.update_rel_part(formset) 
     415            return HttpResponseRedirect(".") 
     416    else: 
     417        formset = get_rel_part_formset(obj) 
     418    object_rel_part_list = obj.get_attached_parts() 
     419    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value) 
     420    context_dict.update({'current_page':'parts', 'class4div': class_for_div, 'object_menu': menu_list, 'object_rel_part': object_rel_part_list, 'rel_part_formset': formset}) 
     421    var_dict, request_dict = display_global_page(request) 
     422    request.session.update(request_dict) 
     423    context_dict.update(var_dict) 
     424    return render_to_response('DisplayObjectRelPart.htm', context_dict) 
     425 
    404426 
    405427##########################################################################################     
     
    446468        class_for_div="NavigateBox4Part" 
    447469    menu_list = obj.menu_items 
    448  
    449470    if not hasattr(obj, "get_attached_parts"): 
    450471        # TODO 
     
    458479    else: 
    459480        formset = get_rel_part_formset(obj) 
    460  
    461481    object_rel_part_list = obj.get_attached_parts() 
    462482    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value) 
     
    510530        class_for_div="NavigateBox4Part" 
    511531    menu_list = obj.menu_items 
    512     object_files_list = [('essais-endurance.pdf', 120, False), ('rapport-essais.odf', 45, True)] 
    513     context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value) 
    514     context_dict.update({'current_page':'files', 'class4div': class_for_div, 'object_menu': menu_list, 'object_files': object_files_list}) 
     532 
     533    if not hasattr(obj, "files"): 
     534        # TODO 
     535        raise TypeError() 
     536    if request.method == "POST": 
     537        formset = get_file_formset(obj, request.POST) 
     538        if formset.is_valid(): 
     539            obj.update_file(formset) 
     540            return HttpResponseRedirect(".") 
     541    else: 
     542        formset = get_file_formset(obj) 
     543 
     544    object_files_list = obj.files 
     545    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value) 
     546    context_dict.update({'current_page':'files', 'class4div': class_for_div, 'object_menu': menu_list, 'object_files': object_files_list, 'file_formset': formset}) 
    515547    var_dict, request_dict = display_global_page(request) 
    516548    request.session.update(request_dict) 
     
    518550    return render_to_response('DisplayObjectFiles.htm', context_dict) 
    519551 
     552########################################################################################## 
     553@login_required 
     554def add_file(request, object_type_value, object_reference_value, object_revision_value): 
     555    """ Manage html page for file addition in the document""" 
     556    context_dict = init_context_dict(object_type_value, object_reference_value, object_revision_value) 
     557    obj = get_obj(object_type_value, object_reference_value, object_revision_value) 
     558    if isinstance(obj, DocumentController): 
     559        class_for_div="NavigateBox4Doc" 
     560    else: 
     561        class_for_div="NavigateBox4Part" 
     562    menu_list = obj.menu_items 
     563    var_dict, request_dict = display_global_page(request) 
     564    request.session.update(request_dict) 
     565    context_dict.update(var_dict) 
     566    if request.POST: 
     567        print request.FILES 
     568        add_file_form_instance = AddFileForm(request.POST, request.FILES) 
     569        if add_file_form_instance.is_valid(): 
     570            obj.add_file(request.FILES["filename"]) 
     571            context_dict.update({'object_menu': menu_list, 'add_file_form': add_file_form_instance, }) 
     572            return HttpResponseRedirect("/object/%s/%s/%s/files/" \ 
     573                                        % (object_type_value, object_reference_value, object_revision_value) ) 
     574        else: 
     575            add_file_form_instance = AddFileForm(request.POST) 
     576            context_dict.update({'class4search_div': True, 'class4div': class_for_div, 'object_menu': menu_list, 'add_file_form': add_file_form_instance, }) 
     577            return render_to_response('DisplayRelPartAdd.htm', context_dict) 
     578    else: 
     579        add_file_form_instance = AddFileForm() 
     580        context_dict.update({'class4search_div': True, 'class4div': class_for_div, 'object_menu': menu_list, 'add_file_form': add_file_form_instance, }) 
     581        return render_to_response('DisplayFileAdd.htm', context_dict) 
    520582 
    521583########################################################################################## 
Note: See TracChangeset for help on using the changeset viewer.