Commit 7647abe47bb870b4fcc97d42702e11c2537ea710
1 parent
327a5316
Exists in
master
and in
2 other branches
Modified read excel file function to avoid errors
Showing
1 changed file
with
16 additions
and
8 deletions
Show diff stats
bulletin/views.py
... | ... | @@ -433,10 +433,10 @@ def create_excel_file(estudantes,metas,meta): |
433 | 433 | for m in metas: |
434 | 434 | worksheet.write(0,count_meta,u'%s' % (m.description) ) |
435 | 435 | count_meta += 1 |
436 | - | |
436 | + | |
437 | 437 | for estudante in estudantes: |
438 | 438 | worksheet.write(contador_estudante,0,estudante.id ) |
439 | - | |
439 | + | |
440 | 440 | nome = str(estudante) |
441 | 441 | worksheet.write(contador_estudante,1,nome) |
442 | 442 | |
... | ... | @@ -448,13 +448,13 @@ def create_excel_file(estudantes,metas,meta): |
448 | 448 | |
449 | 449 | nome = str(meta.slug) + ".xls" |
450 | 450 | folder_path = join(path3, nome) |
451 | - | |
451 | + | |
452 | 452 | #check if the folder already exists |
453 | 453 | if not os.path.isdir(path3): |
454 | 454 | os.makedirs(path3) |
455 | - | |
455 | + | |
456 | 456 | workbook.save(folder_path) |
457 | - | |
457 | + | |
458 | 458 | def read_excel_file(estudante,meta,qtd,boletim): |
459 | 459 | nome = boletim.file_content.path |
460 | 460 | arquivo = xlrd.open_workbook(nome) |
... | ... | @@ -468,9 +468,13 @@ def read_excel_file(estudante,meta,qtd,boletim): |
468 | 468 | continue |
469 | 469 | else: |
470 | 470 | linha = planilha.row_values(n) |
471 | - | |
472 | - for x in range(2,2+qtd): | |
473 | - alcance.append(int(linha[x])) | |
471 | + if int(linha[0]) == int(estudante.id): | |
472 | + for x in range(2,2+qtd): | |
473 | + alcance.append(int(linha[x])) | |
474 | + break | |
475 | + if len(alcance) == 0: | |
476 | + for x in range(0,qtd): | |
477 | + alcance.append(0) | |
474 | 478 | |
475 | 479 | for b in range(2,planilha.ncols): |
476 | 480 | for item in planilha.col_values(b,1,planilha.nrows): |
... | ... | @@ -479,6 +483,10 @@ def read_excel_file(estudante,meta,qtd,boletim): |
479 | 483 | media = soma // (planilha.nrows - 1) |
480 | 484 | medias.append(media) |
481 | 485 | |
486 | + if len(medias) == 0: | |
487 | + for x in range(0,qtd): | |
488 | + medias.append(0) | |
489 | + | |
482 | 490 | return alcance, medias |
483 | 491 | |
484 | 492 | ... | ... |