diff options
| author | Bobby <[email protected]> | 2023-06-04 22:16:43 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-06-04 22:16:43 -0400 |
| commit | 27c29e7084d13960eb692aff87cdc91e53fc4809 (patch) | |
| tree | f2622d5aa5cde65ee5bd7775c9084439027e2cef | |
| parent | bb0767641d548a16a8ccab871ffcf8c3f17acfda (diff) | |
| download | thatcomputerscientist-27c29e7084d13960eb692aff87cdc91e53fc4809.tar.xz thatcomputerscientist-27c29e7084d13960eb692aff87cdc91e53fc4809.zip | |
Update status icons and fix broken commenting
| -rw-r--r-- | blog/views.py | 56 | ||||
| -rw-r--r-- | static/css/styles.css | 3 | ||||
| -rw-r--r-- | static/images/site/check.png | bin | 72200 -> 1084 bytes | |||
| -rw-r--r-- | static/images/site/unknown.png | bin | 118845 -> 1395 bytes | |||
| -rw-r--r-- | templates/blog/post.html | 6 |
5 files changed, 34 insertions, 31 deletions
diff --git a/blog/views.py b/blog/views.py index 14318a46..126c4355 100644 --- a/blog/views.py +++ b/blog/views.py @@ -189,7 +189,7 @@ def comment(request, slug): if request.method == 'POST': if request.user.is_authenticated: try: - # check for spam first + # check for spam first user_ip = request.META.get('HTTP_X_FORWARDED_FOR') if user_ip: user_ip = user_ip.split(',')[0] @@ -226,6 +226,11 @@ def anon_comment(request, slug): # not allowed this is anonymous comment form return redirect(reverse('blog:post', kwargs={'slug': slug})) else: + anonymous_name = request.POST.get('anonymous-name') + anonymous_email = request.POST.get('anonymous-email') + anonymous_token, at = request.POST.get('anonymous-token'), request.POST.get('anonymous-token') + new_anonymous_token = request.POST.get('new-anonymous-token') + anonymous_comment = request.POST.get('anonymous-comment') # check for spam first user_ip = request.META.get('HTTP_X_FORWARDED_FOR') if user_ip: @@ -239,11 +244,6 @@ def anon_comment(request, slug): return redirect(reverse('blog:post', kwargs={'slug': slug}) + '#new-comment') # now continue with the comment - anonymous_name = request.POST.get('anonymous-name') - anonymous_email = request.POST.get('anonymous-email') - anonymous_token, at = request.POST.get('anonymous-token'), request.POST.get('anonymous-token') - new_anonymous_token = request.POST.get('new-anonymous-token') - anonymous_comment = request.POST.get('anonymous-comment') if not anonymous_name: messages.error(request, 'Please enter a name!') return redirect(reverse('blog:post', kwargs={'slug': slug})) @@ -298,20 +298,20 @@ def anon_comment(request, slug): def edit_comment(request, slug): if request.method == 'POST': if request.user.is_authenticated: - # check for spam first - user_ip = request.META.get('HTTP_X_FORWARDED_FOR') - if user_ip: - user_ip = user_ip.split(',')[0] - else: - user_ip = request.META.get('REMOTE_ADDR') - user_agent_string = request.META.get('HTTP_USER_AGENT', '') - user_agent = parse(user_agent_string) - if check_spam(user_ip=user_ip, user_agent=user_agent, comment=request.POST.get('body'), author=request.user.username): - messages.error(request, request.POST.get('body'), extra_tags='spam') - return redirect(reverse('blog:post', kwargs={'slug': slug}) + '#comment-' + str(comment.id)) try: comment = Comment.objects.get(id=request.POST.get('comment_id')) + # check for spam first + user_ip = request.META.get('HTTP_X_FORWARDED_FOR') + if user_ip: + user_ip = user_ip.split(',')[0] + else: + user_ip = request.META.get('REMOTE_ADDR') + user_agent_string = request.META.get('HTTP_USER_AGENT', '') + user_agent = parse(user_agent_string) + if check_spam(user_ip=user_ip, user_agent=user_agent, comment=request.POST.get('body'), author=request.user.username): + messages.error(request, request.POST.get('body'), extra_tags='spam') + return redirect(reverse('blog:post', kwargs={'slug': slug}) + '#comment-' + str(comment.id)) if comment.user == request.user: comment.body = request.POST.get('body') comment.edited = True @@ -333,17 +333,6 @@ def anon_edit_comment(request, slug): # not allowed this is anonymous comment form return redirect(reverse('blog:post', kwargs={'slug': slug})) else: - # check for spam first - user_ip = request.META.get('HTTP_X_FORWARDED_FOR') - if user_ip: - user_ip = user_ip.split(',')[0] - else: - user_ip = request.META.get('REMOTE_ADDR') - user_agent_string = request.META.get('HTTP_USER_AGENT', '') - user_agent = parse(user_agent_string) - if check_spam(user_ip=user_ip, user_agent=user_agent, comment=request.POST.get('body'), author=comment.anonymous_user.name): - messages.error(request, request.POST.get('body'), extra_tags='spam') - return redirect(reverse('blog:post', kwargs={'slug': slug}) + '#comment-' + str(comment.id)) anonymous_token = request.COOKIES.get('anonymous_token') if not anonymous_token: @@ -351,6 +340,17 @@ def anon_edit_comment(request, slug): try: anonymous_token = hashlib.sha256(anonymous_token.encode('utf-8')).hexdigest() comment = Comment.objects.get(id=request.POST.get('comment_id')) + # check for spam first + user_ip = request.META.get('HTTP_X_FORWARDED_FOR') + if user_ip: + user_ip = user_ip.split(',')[0] + else: + user_ip = request.META.get('REMOTE_ADDR') + user_agent_string = request.META.get('HTTP_USER_AGENT', '') + user_agent = parse(user_agent_string) + if check_spam(user_ip=user_ip, user_agent=user_agent, comment=request.POST.get('body'), author=comment.anonymous_user.name): + messages.error(request, request.POST.get('body'), extra_tags='spam') + return redirect(reverse('blog:post', kwargs={'slug': slug}) + '#comment-' + str(comment.id)) if comment.anonymous_user.token == anonymous_token: comment.body = request.POST.get('body') comment.edited = True diff --git a/static/css/styles.css b/static/css/styles.css index 50672ddf..8408cd10 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -56,7 +56,10 @@ a, img.little-staus { height: 24px; + border-radius: 50%; position: relative; + top: -18px; + left: 28px; } #fake-banner-ad { diff --git a/static/images/site/check.png b/static/images/site/check.png Binary files differindex f34ae14f..217f212e 100644 --- a/static/images/site/check.png +++ b/static/images/site/check.png diff --git a/static/images/site/unknown.png b/static/images/site/unknown.png Binary files differindex 85180ba9..26b4c3d5 100644 --- a/static/images/site/unknown.png +++ b/static/images/site/unknown.png diff --git a/templates/blog/post.html b/templates/blog/post.html index 422e4a3d..ebf6a366 100644 --- a/templates/blog/post.html +++ b/templates/blog/post.html @@ -96,11 +96,11 @@ <table> <tr> <td style="width: 60px; vertical-align: top;"> - <img src="{% static 'images/avatars/' %}{{ comment.avatar_url }}.gif" alt="Profile Picture" style="width: 50px;"> + <img src="{% static 'images/avatars/' %}{{ comment.avatar_url }}.gif" alt="Profile Picture" style="width: 50px; border-radius: 50%;"> {% if not comment.user %} - <img src="{% static 'images/site/unknown.png' %}" alt="Anonymous User" class="little-staus" style="top: -20px; left: 24px;"> + <img src="{% static 'images/site/unknown.png' %}" alt="Anonymous User" class="little-staus"> {% else %} - <img src="{% static 'images/site/check.png' %}" alt="Registered User" class="little-staus" style="top: -24px; left: 28px;"> + <img src="{% static 'images/site/check.png' %}" alt="Registered User" class="little-staus" style=""> {% endif %} </td> <td style="vertical-align: top; width: 668px;"> |
