Skip to content

Commit

Permalink
chore(diary): improve the diary commit message validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hojagulyyev committed Dec 12, 2023
1 parent 8ca3124 commit c90d9ad
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apps/diaries/interactors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect
from django.contrib import messages
Expand Down Expand Up @@ -32,6 +34,21 @@ def create_commit(request, diary_id: int):
f"?message={message}"
)

if (
DiaryCommit.objects
.filter(
diary=diary,
message=message,
created_datetime__date=datetime.date.today()
)
.exists()
):
messages.error(request, message="this message already exists for today")
return redirect(
f"{reverse(viewname='diaries:detail_view', kwargs={'id': diary.id})}"
f"?message={message}"
)

# ===== PROCESS

diary_commit = DiaryCommit()
Expand Down

0 comments on commit c90d9ad

Please sign in to comment.