From 8c27f60861d6437cfa0e38b0571befdef2f4e5de Mon Sep 17 00:00:00 2001 From: Nilanchala Date: Wed, 10 Jan 2024 21:03:06 +0000 Subject: [PATCH] Fixed broken validation --- bloggy/templates/pages/user_profile.html | 2 +- bloggy/templates/profile/my_dashboard_view.html | 4 +--- bloggy/templates/widgets/feedback-form.html | 2 +- bloggy/views/my_dashboard_view.py | 5 ++--- bloggy_api/views/feedback_api.py | 14 ++++++++++++-- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bloggy/templates/pages/user_profile.html b/bloggy/templates/pages/user_profile.html index 7921d05..ddbdb5d 100644 --- a/bloggy/templates/pages/user_profile.html +++ b/bloggy/templates/pages/user_profile.html @@ -40,7 +40,7 @@

{{ userProfile.username }}

My articles(so far)

{% if posts|length <= 0 %} -

Currently, there are no published posts.

+

Currently, there are no published posts.

{% else %} {% for post in posts %}
{% include "partials/post_list_item.html" with post=post cssClass="" %}
diff --git a/bloggy/templates/profile/my_dashboard_view.html b/bloggy/templates/profile/my_dashboard_view.html index 02edf66..9665ecc 100644 --- a/bloggy/templates/profile/my_dashboard_view.html +++ b/bloggy/templates/profile/my_dashboard_view.html @@ -12,10 +12,8 @@

Dashboard

- - {% if posts|length <= 0 %} -

Currently, there are no published posts.

+

Currently, there are no published posts.

{% else %} {% for post in posts %} {% include 'partials/article_row_list.html' with post=post %} diff --git a/bloggy/templates/widgets/feedback-form.html b/bloggy/templates/widgets/feedback-form.html index ba0d776..91fad43 100644 --- a/bloggy/templates/widgets/feedback-form.html +++ b/bloggy/templates/widgets/feedback-form.html @@ -26,7 +26,7 @@

Give Feedback

- + {% if user.is_authenticated %} diff --git a/bloggy/views/my_dashboard_view.py b/bloggy/views/my_dashboard_view.py index 670b45f..a117327 100644 --- a/bloggy/views/my_dashboard_view.py +++ b/bloggy/views/my_dashboard_view.py @@ -11,8 +11,7 @@ class DashboardView(DetailView): DEFAULT_PAGE_SIZE = 12 def get_object(self, **kwargs): - username = self.request.user # self.kwargs.get("username") - return get_object_or_404(User, username=username) + return get_object_or_404(User, username=self.request.user.username) def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) @@ -40,4 +39,4 @@ def get_context_data(self, *args, **kwargs): if user.profile_photo: context['meta_image'] = settings.SITE_LOGO - return context \ No newline at end of file + return context diff --git a/bloggy_api/views/feedback_api.py b/bloggy_api/views/feedback_api.py index 588a837..86aed47 100644 --- a/bloggy_api/views/feedback_api.py +++ b/bloggy_api/views/feedback_api.py @@ -8,12 +8,22 @@ class FeedbackApi(viewsets.ViewSet): - def feedback(self, request): message = request.POST["message"] + + honeypot = request.POST.get("honeypot", None) + if honeypot: + return HttpResponse( + json.dumps({'success': False, + 'message': "This is a community for learners! " + "We encourage genuine engagement and learning. " + "Please refrain from using automated bots or cheating methods. " + "Let's keep this space focused on authentic educational experiences."}), + content_type="application/json" + ) + if StringUtils.is_not_blank(message): subject = 'New Feedback' - message_content = (f'Name: {request.POST.get("name", "-")}' f'\n\nEmail: {request.POST.get("email", "-")}' f'\n\nMessage: {message}'