0

My knowledge of front end it is not so good, and I don't know how to send array of ids to back end which will get all data and will be open it into new page. pls help

there my function:

@has_session_params('tin')
def print_documents(request):
    doc_ids = request.POST.getlist('doc_ids[]')
    tin = request.session['tin']
    params = dict()
    template = 'documents/documents_to_print.html'
    params['Docs'] = docs
    params['pb'] = pb
    params['is_pdf'] = request.GET.get('is_pdf', 'false')
    params['host'] = request.scheme + "://" + request.META["HTTP_HOST"]
    params['url'] = settings.SITE_URL + request.get_full_path()
    params['doc_type'] = INVOICE_TYPE
    invoice_list = list()
    for doc_id in doc_ids:
        response = proxy.get_invoice_by_id(invoice_id=doc_id, tin=tin)
        if response.status.code != pb.ResponseStatus.OK:
            response = proxy.get_invoice_draft_by_id(
                invoice_draft_id=doc_id, tin=tin)
        invoice_list.append(response.invoice)
    params['invoices'] = invoice_list
    return render(request, template, params)

I know how to get one object by id, it will be like:

def print_document(request, doc_id):

and something like that, and where url for function will be look like that:

url(r'^print_documents/(?P<doc_id>[a-z\d]{24})/$', invoices.print_documents, name='print_documents')

and new page link will be like that localhost:8000/documents/print_documents/{doc_id}

and this method I can just call like :

<a href="{url documents:print_documents doc_id}">print</a>

but now I want to select several documents and send doc_ids, and I know that I can to like method above but I don't want big link. And how I can send array of ids to back end correctly?

now I have something like that:

printAll.on("click", function(){
var invoicesID = [];
$('input.select-inv-check:checked').each(function() {
    invoicesID.push($(this).data('docid'));
});

var url = Globals.printAll;

$.post( url, { doc_ids: invoicesID } ).done(function(result) {
    console.log("result", result[0].Docs);
     if(result.code == 0){

     }else{
         alert(result.message);  
     }
});
});

And I know that it doesn't correct! pls help

Baktiyar Bekbergen
  • 374
  • 2
  • 4
  • 24

0 Answers0