Implement notifications

This commit is contained in:
Keannu Christian Bernasol 2025-01-21 13:57:31 +08:00
parent 63f3bd0eab
commit 298501b973
16 changed files with 293 additions and 1 deletions

View file

@ -20,6 +20,7 @@ from ollama import Client
from pydantic import BaseModel
from datetime import date
from typing import Optional
from notifications.models import Notification
class PDFHandler(FileSystemEventHandler):
@ -223,6 +224,7 @@ class PDFHandler(FileSystemEventHandler):
# If that fails, just use regular OCR read the title as a dirty fix/fallback
except Exception as e:
document_subject = "placeholder_document_name"
document_type = "other"
sent_from = "N/A"
document_month = "no_month"
@ -232,6 +234,11 @@ class PDFHandler(FileSystemEventHandler):
self.logger.warning(
"Ollama OCR offload failed. Using defaults for missing values")
Notification.objects.create(
type="warning",
audience="staff",
content=f"Ollama OCR failed for document {document_subject}. Please check if the Ollama API is reachable.")
metadata += text
# Open the file for instance creation
@ -257,9 +264,18 @@ class PDFHandler(FileSystemEventHandler):
document_type}'. sent_from: {sent_from}, document_month: {document_month}, document_year: {document_year}"
)
Notification.objects.create(
type="info",
audience="staff",
content=f"New Document Scanned: {document_subject}.")
else:
self.logger.info(
f"Document '{document_subject}' already exists.")
Notification.objects.create(
type="info",
audience="staff",
content=f"Skipping Scanned Document {document_subject}: Already exists.")
os.remove(file_path)
except Exception as e: