PenParse/penparse/webui/views/__init__.py

76 lines
1.8 KiB
Python

import logging
import os
from django.contrib import messages
from django.shortcuts import redirect, render
from django.http import HttpRequest, HttpResponse
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from ..models import ImageMemo
from django.contrib.auth.decorators import login_required
logger = logging.getLogger(__name__)
from .thumbnail import document_thumbnail, document_image
from .register import register
from .upload import upload_document
from .delete import delete_document
def index(request):
# return HttpResponse("Hello, world. You're at the polls index.")
return render(request, "index.html")
__all__ = [
"index",
"document_thumbnail",
"document_image",
"register",
"dashboard",
"settings",
"view_document",
"download_document",
"upload_document",
"delete_document",
]
@login_required
def dashboard(request: HttpRequest):
documents = ImageMemo.objects.filter(author__id=request.user.id).order_by(
"-updated_at"
)
context = {"documents": documents}
return render(request, "dashboard.html", context)
@login_required
def settings(request):
return render(request, "settings.html")
@login_required
def view_document(request: HttpRequest, pk: str):
## check that the document exists and belongs to the user
# find document with given ID (pk path param) and current user id
document = ImageMemo.objects.filter(id=pk, author__id=request.user.id).first()
if not document:
logger.debug(f"No memo found for user={request.user.id} and memo_id={pk}")
return HttpResponse(content="Document not found", status=404)
return render(request, "document.html", context={"document": document})
@login_required
def download_document(request):
return render(request, "document.html")