Skip to content

Commit

Permalink
Fixing double creating of report
Browse files Browse the repository at this point in the history
  • Loading branch information
Ederporto committed Aug 13, 2024
1 parent fd79416 commit 40b6004
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion report/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def add_report(request):
operation_formset = get_operation_formset()
if request.method == "POST":
timediff = timezone.now() - datetime.timedelta(hours=24)
report_exists = Report.objects.filter(created_by__user=request.user, description=report_form.data.get("description"), created_at__lte=timediff).exists()
report_exists = Report.objects.filter(created_by__user=request.user, description=report_form.data.get("description"), created_at__gte=timediff).exists()
operation_metrics = operation_formset(request.POST, prefix='Operation')
if not report_exists:
if report_form.is_valid() and operation_metrics.is_valid():
Expand All @@ -56,6 +56,7 @@ def add_report(request):
messages.error(request, field + ": " + error[0])
else:
messages.error(request, _("It seems that you already submitted this report!"))
messages.error(request, str(request.user) + ":" + report_form.data.get("description") + ":" + str(timediff))

context = {
"directions_related_set": directions_related_set,
Expand Down

0 comments on commit 40b6004

Please sign in to comment.