mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-01-18 17:13:00 +08:00
Add email template for request status update, fix admin view for request unit view, and add initial app for questionnaires
This commit is contained in:
parent
ba19412d31
commit
8bd8df9042
15 changed files with 79 additions and 7 deletions
|
@ -88,6 +88,7 @@ INSTALLED_APPS = [
|
|||
"corsheaders",
|
||||
"drf_spectacular",
|
||||
"drf_spectacular_sidecar",
|
||||
"emails",
|
||||
"accounts",
|
||||
"documents",
|
||||
"document_requests",
|
||||
|
@ -110,7 +111,9 @@ ROOT_URLCONF = "config.urls"
|
|||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [],
|
||||
"DIRS": [
|
||||
BASE_DIR / "emails/templates/",
|
||||
],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
|
|
|
@ -12,7 +12,7 @@ class DocumentRequestUnitAdmin(ModelAdmin):
|
|||
list_display = ["id", "get_document_title", "copies"]
|
||||
|
||||
def get_document_title(self, obj):
|
||||
return obj.documents.title # Assuming the Document model has a 'title' field
|
||||
return obj.document.name
|
||||
|
||||
get_document_title.short_description = "Document"
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ from rest_framework import serializers
|
|||
from documents.models import Document
|
||||
from documents.serializers import DocumentSerializer, DocumentFileSerializer
|
||||
from accounts.models import CustomUser
|
||||
from emails.templates import RequestUpdateEmail
|
||||
from .models import DocumentRequest, DocumentRequestUnit
|
||||
|
||||
|
||||
|
@ -116,4 +117,13 @@ class DocumentRequestUpdateSerializer(serializers.ModelSerializer):
|
|||
{"error": "Request form status provided is the same as current status"}
|
||||
)
|
||||
|
||||
return super().update(instance, validated_data)
|
||||
representation = super().update(instance, validated_data)
|
||||
|
||||
# Send an email on request status update
|
||||
email = RequestUpdateEmail()
|
||||
email.context = {
|
||||
"request_status": instance.status
|
||||
}
|
||||
email.send(to=[instance.requester.email])
|
||||
|
||||
return representation
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
from rest_framework import serializers
|
||||
from config import settings
|
||||
from .models import Document
|
||||
|
||||
|
||||
class DocumentUploadSerializer(serializers.ModelSerializer):
|
||||
# For staff
|
||||
# For staff document uploads
|
||||
file = serializers.FileField()
|
||||
date_uploaded = serializers.DateTimeField(
|
||||
format="%m-%d-%Y %I:%M %p", read_only=True
|
||||
|
@ -30,14 +29,15 @@ class DocumentDeleteSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class DocumentSerializer(serializers.ModelSerializer):
|
||||
# Read-only serializer
|
||||
# Read-only serializer without link to the file
|
||||
date_uploaded = serializers.DateTimeField(
|
||||
format="%m-%d-%Y %I:%M %p", read_only=True
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Document
|
||||
fields = ["id", "name", "document_type", "number_pages", "date_uploaded"]
|
||||
fields = ["id", "name", "document_type",
|
||||
"number_pages", "date_uploaded"]
|
||||
read_only_fields = [
|
||||
"id",
|
||||
"name",
|
||||
|
|
0
docmanager_backend/emails/__init__.py
Normal file
0
docmanager_backend/emails/__init__.py
Normal file
6
docmanager_backend/emails/apps.py
Normal file
6
docmanager_backend/emails/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class EmailsConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "emails"
|
0
docmanager_backend/emails/migrations/__init__.py
Normal file
0
docmanager_backend/emails/migrations/__init__.py
Normal file
13
docmanager_backend/emails/templates.py
Normal file
13
docmanager_backend/emails/templates.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from djoser import email
|
||||
from config.settings import FRONTEND_URL
|
||||
|
||||
|
||||
class RequestUpdateEmail(email.BaseEmailMessage):
|
||||
template_name = "request_approved.html"
|
||||
|
||||
def get_context_data(self):
|
||||
context = super().get_context_data()
|
||||
context["request_status"] = context.get("request_status")
|
||||
context["url"] = FRONTEND_URL
|
||||
context.update(self.context)
|
||||
return context
|
25
docmanager_backend/emails/templates/request_approved.html
Normal file
25
docmanager_backend/emails/templates/request_approved.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
{% load i18n %}
|
||||
|
||||
{% block subject %}
|
||||
{% blocktrans %}USTP - Document Request Form Update{% endblocktrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block text_body %}
|
||||
{% blocktrans %}You're receiving this email because your document request has been {{ request_status }}.{% endblocktrans %}
|
||||
|
||||
{% trans 'Please visit the site to check your request:' %}
|
||||
{{ url|safe }}
|
||||
{% endblock %}
|
||||
|
||||
{% block html_body %}
|
||||
<p>
|
||||
{% blocktrans %}You're receiving this email because your document request has been {{ request_status }}.{% endblocktrans %}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{% trans 'Please visit the site to check your request:' %}
|
||||
</p>
|
||||
<p>
|
||||
<a href="{{ url|safe }}"></a>
|
||||
</p>
|
||||
{% endblock %}
|
0
docmanager_backend/questionnaires/__init__.py
Normal file
0
docmanager_backend/questionnaires/__init__.py
Normal file
3
docmanager_backend/questionnaires/admin.py
Normal file
3
docmanager_backend/questionnaires/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
docmanager_backend/questionnaires/apps.py
Normal file
6
docmanager_backend/questionnaires/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class QuestionnairesConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "questionnaires"
|
0
docmanager_backend/questionnaires/migrations/__init__.py
Normal file
0
docmanager_backend/questionnaires/migrations/__init__.py
Normal file
3
docmanager_backend/questionnaires/models.py
Normal file
3
docmanager_backend/questionnaires/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
docmanager_backend/questionnaires/views.py
Normal file
3
docmanager_backend/questionnaires/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Loading…
Reference in a new issue