From 361d3fc33abd61f4e1de9b8ee81dd5c0c63ad26b Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Thu, 11 Apr 2024 23:56:58 -0500 Subject: [PATCH] Rewrite user follow + fix some css --- chat_box/views.py | 11 +++++++++-- dmoj/urls.py | 1 + judge/views/user.py | 27 +++++++++++++------------- resources/contest.scss | 4 ++-- resources/users.scss | 2 +- templates/contest/ranking-css.html | 7 +++++-- templates/user/user-base.html | 31 +++++++++++++++++++----------- 7 files changed, 52 insertions(+), 31 deletions(-) diff --git a/chat_box/views.py b/chat_box/views.py index 5bcabd1..5214725 100644 --- a/chat_box/views.py +++ b/chat_box/views.py @@ -501,9 +501,16 @@ def get_or_create_room(request): user_room.last_seen = timezone.now() user_room.save() + room_url = reverse("chat", kwargs={"room_id": room.id}) if request.method == "GET": - return JsonResponse({"room": room.id, "other_user_id": other_user.id}) - return HttpResponseRedirect(reverse("chat", kwargs={"room_id": room.id})) + return JsonResponse( + { + "room": room.id, + "other_user_id": other_user.id, + "url": room_url, + } + ) + return HttpResponseRedirect(room_url) def get_unread_count(rooms, user): diff --git a/dmoj/urls.py b/dmoj/urls.py index 82d0925..d9dcb92 100644 --- a/dmoj/urls.py +++ b/dmoj/urls.py @@ -489,6 +489,7 @@ urlpatterns = [ reverse("all_user_submissions", args=[user]) ), ), + url(r"^/toggle_follow/", user.toggle_follow, name="user_toggle_follow"), url( r"^/$", lambda _, user: HttpResponsePermanentRedirect( diff --git a/judge/views/user.py b/judge/views/user.py index 01aa7d6..b47eb03 100644 --- a/judge/views/user.py +++ b/judge/views/user.py @@ -288,19 +288,6 @@ class UserAboutPage(UserPage): return context - # follow/unfollow user - def post(self, request, user, *args, **kwargs): - try: - if not request.profile: - raise Exception("You have to login") - if request.profile.username == user: - raise Exception("Cannot make friend with yourself") - - following_profile = Profile.objects.get(user__username=user) - Friend.toggle_friend(request.profile, following_profile) - finally: - return HttpResponseRedirect(request.path_info) - class UserProblemsPage(UserPage): template_name = "user/user-problems.html" @@ -590,3 +577,17 @@ def toggle_darkmode(request): return HttpResponseBadRequest() request.session["darkmode"] = not request.session.get("darkmode", False) return HttpResponseRedirect(path) + + +@login_required +def toggle_follow(request, user): + if request.method != "POST": + raise Http404() + + profile_to_follow = get_object_or_404(Profile, user__username=user) + + if request.profile.id == profile_to_follow.id: + raise Http404() + + Friend.toggle_friend(request.profile, profile_to_follow) + return HttpResponseRedirect(reverse("user_page", args=(user,))) diff --git a/resources/contest.scss b/resources/contest.scss index cfdd478..1b5ed1e 100644 --- a/resources/contest.scss +++ b/resources/contest.scss @@ -272,7 +272,7 @@ form.contest-join-pseudotab { } .contest-participation-operation { - float: right; + margin-left: auto; .fa { color: #444; @@ -282,7 +282,7 @@ form.contest-join-pseudotab { padding-left: 1px; } - padding: 0 5px; + padding-left: 5px; } #add-clarification { diff --git a/resources/users.scss b/resources/users.scss index a94e32f..669d296 100644 --- a/resources/users.scss +++ b/resources/users.scss @@ -59,7 +59,7 @@ th.header.rank { vertical-align: middle; } - .rank, .points, .problems, .user-name { + .rank, .points, .problems { white-space: nowrap; max-width: 20em; overflow: hidden; diff --git a/templates/contest/ranking-css.html b/templates/contest/ranking-css.html index 0c51968..0711fc6 100644 --- a/templates/contest/ranking-css.html +++ b/templates/contest/ranking-css.html @@ -28,8 +28,11 @@ } .user-name { - position: relative; - padding-left: 2em !important; + padding-left: 1em !important; + padding-right: 1em !important; + display: flex; + min-width: max-content; + align-items: center; } .organization-column { diff --git a/templates/user/user-base.html b/templates/user/user-base.html index b7c545e..b7ad984 100644 --- a/templates/user/user-base.html +++ b/templates/user/user-base.html @@ -79,6 +79,19 @@ {% endblock %} {% block js_media %} + {% block user_js_media %}{% endblock %} {% endblock %} @@ -90,7 +103,7 @@
{% if request.user != user.user %} -
+ {% csrf_token %}
{% endif %} {% if ratings %}