Rewrite user follow + fix some css
This commit is contained in:
parent
04877b47c1
commit
361d3fc33a
7 changed files with 52 additions and 31 deletions
|
@ -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):
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,)))
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -79,6 +79,19 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block js_media %}
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$("#message-button").on("click", function() {
|
||||
$.get("{{ url('get_or_create_room') }}", {
|
||||
"other": "{{ chat_param(request.profile, user) }}"
|
||||
}, function(response) {
|
||||
window.location.href = response.url;
|
||||
}).fail(function(error) {
|
||||
console.log("Error: ", error);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% block user_js_media %}{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -90,7 +103,7 @@
|
|||
</div>
|
||||
<br>
|
||||
{% if request.user != user.user %}
|
||||
<form method="post">
|
||||
<form method="post" action="{{ url('user_toggle_follow', user.username) }}">
|
||||
{% csrf_token %}
|
||||
<button class="small {{ 'unfollow' if followed else 'follow' }}" style="width:145px">
|
||||
{% if followed %}
|
||||
|
@ -105,19 +118,15 @@
|
|||
{% endif %}
|
||||
<br>
|
||||
<div>
|
||||
<form action="{{ url('all_user_submissions', user.user.username) }}">
|
||||
<input type="submit" value="{{ _('View submissions') }}" class="small" style="width:145px; padding-left: 1px; padding-right: 1px">
|
||||
</form>
|
||||
<a href="{{ url('all_user_submissions', user.username) }}" class="button small" style="width:145px">
|
||||
{{ _('View submissions') }}
|
||||
</a>
|
||||
</div>
|
||||
{% if request.user.is_authenticated %}
|
||||
<br>
|
||||
<div>
|
||||
<form action="{{ url('get_or_create_room') }}" method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" value="{{ chat_param(request.profile, user) }}" name="other">
|
||||
<input type="submit" value="{{ _('Send message') }}" style="width:145px" class="small btn-midnightblue">
|
||||
</form>
|
||||
</div>
|
||||
<button class="small btn-midnightblue" style="width:145px" id="message-button">
|
||||
{{ _('Send message') }}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
{% if ratings %}
|
||||
|
|
Loading…
Reference in a new issue