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,10 +433,10 @@ def create_excel_file(estudantes,metas,meta): | ||
433 | for m in metas: | 433 | for m in metas: |
434 | worksheet.write(0,count_meta,u'%s' % (m.description) ) | 434 | worksheet.write(0,count_meta,u'%s' % (m.description) ) |
435 | count_meta += 1 | 435 | count_meta += 1 |
436 | - | 436 | + |
437 | for estudante in estudantes: | 437 | for estudante in estudantes: |
438 | worksheet.write(contador_estudante,0,estudante.id ) | 438 | worksheet.write(contador_estudante,0,estudante.id ) |
439 | - | 439 | + |
440 | nome = str(estudante) | 440 | nome = str(estudante) |
441 | worksheet.write(contador_estudante,1,nome) | 441 | worksheet.write(contador_estudante,1,nome) |
442 | 442 | ||
@@ -448,13 +448,13 @@ def create_excel_file(estudantes,metas,meta): | @@ -448,13 +448,13 @@ def create_excel_file(estudantes,metas,meta): | ||
448 | 448 | ||
449 | nome = str(meta.slug) + ".xls" | 449 | nome = str(meta.slug) + ".xls" |
450 | folder_path = join(path3, nome) | 450 | folder_path = join(path3, nome) |
451 | - | 451 | + |
452 | #check if the folder already exists | 452 | #check if the folder already exists |
453 | if not os.path.isdir(path3): | 453 | if not os.path.isdir(path3): |
454 | os.makedirs(path3) | 454 | os.makedirs(path3) |
455 | - | 455 | + |
456 | workbook.save(folder_path) | 456 | workbook.save(folder_path) |
457 | - | 457 | + |
458 | def read_excel_file(estudante,meta,qtd,boletim): | 458 | def read_excel_file(estudante,meta,qtd,boletim): |
459 | nome = boletim.file_content.path | 459 | nome = boletim.file_content.path |
460 | arquivo = xlrd.open_workbook(nome) | 460 | arquivo = xlrd.open_workbook(nome) |
@@ -468,9 +468,13 @@ def read_excel_file(estudante,meta,qtd,boletim): | @@ -468,9 +468,13 @@ def read_excel_file(estudante,meta,qtd,boletim): | ||
468 | continue | 468 | continue |
469 | else: | 469 | else: |
470 | linha = planilha.row_values(n) | 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 | for b in range(2,planilha.ncols): | 479 | for b in range(2,planilha.ncols): |
476 | for item in planilha.col_values(b,1,planilha.nrows): | 480 | for item in planilha.col_values(b,1,planilha.nrows): |
@@ -479,6 +483,10 @@ def read_excel_file(estudante,meta,qtd,boletim): | @@ -479,6 +483,10 @@ def read_excel_file(estudante,meta,qtd,boletim): | ||
479 | media = soma // (planilha.nrows - 1) | 483 | media = soma // (planilha.nrows - 1) |
480 | medias.append(media) | 484 | medias.append(media) |
481 | 485 | ||
486 | + if len(medias) == 0: | ||
487 | + for x in range(0,qtd): | ||
488 | + medias.append(0) | ||
489 | + | ||
482 | return alcance, medias | 490 | return alcance, medias |
483 | 491 | ||
484 | 492 |