Skip to content

Commit

Permalink
feat(dev): time checker (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
eugena committed Apr 30, 2024
1 parent 052c5dc commit 409a476
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions acesta/static/js/time.checker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Checks whether enough time has passed since the page loaded
setTimeout(() => {
$('.time_checker').each(function(i, obj) {$(this).val(1)});
}, 5000)
1 change: 1 addition & 0 deletions acesta/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ <h5 class="modal-title text-nowrap fw-bolder" id="privacyLabel">Политика
<script src="{% static 'js/jquery.mask.min.js' %}"></script>
<script src="{% static 'js/user.clear.phone.mask.js' %}"></script>
<script src="{% static 'js/channel.selector.js' %}"></script>
<script src="{% static 'js/time.checker.js' %}"></script>
{% block messages %}
{% if messages %}
{% include "include/messages.html" %}
Expand Down
1 change: 1 addition & 0 deletions acesta/templates/include/request_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ <h5 class="modal-title" id="{{ subject }}Label"><svg fill="#464646" class="me-2"
<div class="mt-3">
<textarea required class="form-control" name="comment" id="{{ subject }}TextMessage" rows="3" autocomplete="off" placeholder="{% if subject == REQUEST_CONSULTATION %}Комментарий{% else %}Цель{% endif %}"></textarea>
<div id="{{ subject }}MessageHelp" class="form-text text-muted ms-2">{% if subject == REQUEST_CONSULTATION %}В какое время и&nbsp;каким способом удобно получить консультацию{% else %}Расскажите нам, какие задачи собираетесь решать при&nbsp;помощи сервиса{% endif %}</div>
<input required hidden class="form-control time_checker" name="time_checker" id="{{ subject }}TimeChecker" value="0">
</div>
{% if subject == REQUEST_CONSULTATION %}
{{ consultation_form.user }}
Expand Down
10 changes: 8 additions & 2 deletions acesta/user/views/communications.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ def visitor_request(request: HttpRequest) -> HttpResponse or FileResponse:
data["time"] = timezone.now() + relativedelta(minutes=60)
request_form = RequestForm(data=data)

if request_form.is_valid() and request.user.is_authenticated:
try:
is_time_check = bool(int(request.POST.get("time_checker", default=False)))
except ValueError:
is_time_check = False

if is_time_check and request_form.is_valid() and request.user.is_authenticated:
request_form.save()
if is_consultation:
messages.add_message(
Expand All @@ -55,7 +60,8 @@ def visitor_request(request: HttpRequest) -> HttpResponse or FileResponse:
messages.ERROR,
"Не удалось отправить запрос, попробуйте позже или&nbsp;обратитесь в&nbsp;техподдержку",
)
send_message(f"Ошибка при добавлении сообщения {request_form.errors}")
if is_time_check:
send_message(f"Ошибка при добавлении сообщения {request_form.errors}")

if request.POST["subject"] == settings.REQUEST_CONSULTATION:
return redirect(request.META["HTTP_REFERER"])
Expand Down

0 comments on commit 409a476

Please sign in to comment.