mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-04-28 10:41:23 +08:00
Implement major changes
This commit is contained in:
parent
60eadbed64
commit
63f3bd0eab
16 changed files with 357 additions and 40 deletions
|
@ -0,0 +1,28 @@
|
|||
# Generated by Django 5.1.3 on 2025-01-17 15:41
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("document_requests", "0004_rename_denied_remarks_documentrequest_remarks"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="documentrequest",
|
||||
name="status",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
("pending", "Pending"),
|
||||
("approved", "Approved"),
|
||||
("denied", "Denied"),
|
||||
("claimed", "Claimed"),
|
||||
("unclaimed", "Unclaimed"),
|
||||
],
|
||||
default="pending",
|
||||
max_length=32,
|
||||
),
|
||||
),
|
||||
]
|
|
@ -25,6 +25,8 @@ class DocumentRequest(models.Model):
|
|||
("pending", "Pending"),
|
||||
("approved", "Approved"),
|
||||
("denied", "Denied"),
|
||||
("claimed", "Claimed"),
|
||||
("unclaimed", "Unclaimed"),
|
||||
)
|
||||
|
||||
remarks = models.TextField(max_length=512, blank=True, null=True)
|
||||
|
|
|
@ -182,23 +182,30 @@ class DocumentRequestUpdateSerializer(serializers.ModelSerializer):
|
|||
read_only_fields = ["id"]
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
print(validated_data)
|
||||
if instance.status == "denied" or instance.status == "approved":
|
||||
raise serializers.ValidationError(
|
||||
{
|
||||
"error": "Already approved/denied requests cannot be updated. You should instead create a new request and approve it from there"
|
||||
}
|
||||
)
|
||||
elif "status" not in validated_data:
|
||||
if "status" not in validated_data:
|
||||
raise serializers.ValidationError(
|
||||
{
|
||||
"error": "No status value update provided"
|
||||
}
|
||||
)
|
||||
elif instance.status == "denied" or instance.status == "claimed":
|
||||
raise serializers.ValidationError(
|
||||
{
|
||||
"error": "Already claimed/denied requests cannot be updated. You should instead create a new request and approve it from there"
|
||||
}
|
||||
)
|
||||
elif validated_data["status"] == instance.status:
|
||||
raise serializers.ValidationError(
|
||||
{"error": "Request form status provided is the same as current status"}
|
||||
)
|
||||
elif instance.status == "approved" and validated_data["status"] not in ["claimed", "unclaimed"]:
|
||||
raise serializers.ValidationError(
|
||||
{"error": "Approved request forms can only be marked as claimed or unclaimed"}
|
||||
)
|
||||
elif instance.status == "unclaimed" and validated_data["status"] not in ["claimed"]:
|
||||
raise serializers.ValidationError(
|
||||
{"error": "Unclaimed request forms can only be marked as claimed"}
|
||||
)
|
||||
elif validated_data["status"] == "denied" and "remarks" not in validated_data:
|
||||
raise serializers.ValidationError(
|
||||
{"error": "Request denial requires remarks"}
|
||||
|
@ -208,10 +215,11 @@ class DocumentRequestUpdateSerializer(serializers.ModelSerializer):
|
|||
# Send an email on request status update
|
||||
try:
|
||||
email = RequestUpdateEmail()
|
||||
email.context = {"request_status": validated_data["status"]}
|
||||
if validated_data["status"] == "denied":
|
||||
email.context = {"request_status": "denied"}
|
||||
email.context = {"remarks": validated_data["remarks"]}
|
||||
else:
|
||||
email.context = {"request_status": "approved"}
|
||||
email.context = {"remarks": "N/A"}
|
||||
email.send(to=[instance.requester.email])
|
||||
except:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue