Skip to content

Commit 3b1520e

Browse files
committed
Add detailed PPTX extraction logging for debugging
1 parent b36de5e commit 3b1520e

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

questionbank/ai_tools/views.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ def post(self, request):
484484

485485
uploaded_file = request.FILES['file']
486486
filename = uploaded_file.name.lower()
487+
print(f"[ExtractFile] Received file: {uploaded_file.name}, size: {uploaded_file.size}")
487488

488489
try:
489490
if filename.endswith('.pptx'):
@@ -498,19 +499,27 @@ def post(self, request):
498499
status=status.HTTP_400_BAD_REQUEST
499500
)
500501

502+
print(f"[ExtractFile] Extracted {len(content)} chars from {uploaded_file.name}")
501503
return Response({
502504
'content': content,
503505
'filename': uploaded_file.name,
504506
'chars': len(content)
505507
})
506508
except Exception as e:
509+
import traceback
510+
print(f"[ExtractFile] Error: {str(e)}")
511+
traceback.print_exc()
507512
return Response({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
508513

509514
def _extract_pptx(self, file):
510515
from pptx import Presentation
511-
from pptx.enum.shapes import MSO_SHAPE_TYPE
512516

513-
prs = Presentation(io.BytesIO(file.read()))
517+
file_bytes = file.read()
518+
print(f"[PPTX] Read {len(file_bytes)} bytes from file")
519+
520+
prs = Presentation(io.BytesIO(file_bytes))
521+
print(f"[PPTX] Presentation loaded, {len(prs.slides)} slides")
522+
514523
slides_content = []
515524

516525
for slide_num, slide in enumerate(prs.slides, 1):
@@ -523,19 +532,23 @@ def _extract_pptx(self, file):
523532
slide_text.append(shape.text.strip())
524533

525534
# Tables
526-
if shape.has_table:
535+
if hasattr(shape, "has_table") and shape.has_table:
527536
for row in shape.table.rows:
528537
row_text = [cell.text.strip() for cell in row.cells if cell.text.strip()]
529538
if row_text:
530539
slide_text.append(" | ".join(row_text))
531540

532541
# Extract notes
533-
if slide.has_notes_slide and slide.notes_slide.notes_text_frame:
534-
notes = slide.notes_slide.notes_text_frame.text.strip()
535-
if notes:
536-
slide_text.append(f"\n[Notes: {notes}]")
542+
if hasattr(slide, "has_notes_slide") and slide.has_notes_slide:
543+
if slide.notes_slide and hasattr(slide.notes_slide, "notes_text_frame"):
544+
notes_frame = slide.notes_slide.notes_text_frame
545+
if notes_frame and hasattr(notes_frame, "text"):
546+
notes = notes_frame.text.strip()
547+
if notes:
548+
slide_text.append(f"\n[Notes: {notes}]")
537549

538550
if slide_text:
539551
slides_content.append(f"--- Slide {slide_num} ---\n" + "\n".join(slide_text))
552+
print(f"[PPTX] Slide {slide_num}: {len(slide_text)} text items")
540553

541554
return "\n\n".join(slides_content)

0 commit comments

Comments
 (0)