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.last_seen = timezone.now()
|
||||||
user_room.save()
|
user_room.save()
|
||||||
|
|
||||||
|
room_url = reverse("chat", kwargs={"room_id": room.id})
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return JsonResponse({"room": room.id, "other_user_id": other_user.id})
|
return JsonResponse(
|
||||||
return HttpResponseRedirect(reverse("chat", kwargs={"room_id": room.id}))
|
{
|
||||||
|
"room": room.id,
|
||||||
|
"other_user_id": other_user.id,
|
||||||
|
"url": room_url,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return HttpResponseRedirect(room_url)
|
||||||
|
|
||||||
|
|
||||||
def get_unread_count(rooms, user):
|
def get_unread_count(rooms, user):
|
||||||
|
|
|
@ -489,6 +489,7 @@ urlpatterns = [
|
||||||
reverse("all_user_submissions", args=[user])
|
reverse("all_user_submissions", args=[user])
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
url(r"^/toggle_follow/", user.toggle_follow, name="user_toggle_follow"),
|
||||||
url(
|
url(
|
||||||
r"^/$",
|
r"^/$",
|
||||||
lambda _, user: HttpResponsePermanentRedirect(
|
lambda _, user: HttpResponsePermanentRedirect(
|
||||||
|
|
|
@ -288,19 +288,6 @@ class UserAboutPage(UserPage):
|
||||||
|
|
||||||
return context
|
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):
|
class UserProblemsPage(UserPage):
|
||||||
template_name = "user/user-problems.html"
|
template_name = "user/user-problems.html"
|
||||||
|
@ -590,3 +577,17 @@ def toggle_darkmode(request):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
request.session["darkmode"] = not request.session.get("darkmode", False)
|
request.session["darkmode"] = not request.session.get("darkmode", False)
|
||||||
return HttpResponseRedirect(path)
|
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 {
|
.contest-participation-operation {
|
||||||
float: right;
|
margin-left: auto;
|
||||||
|
|
||||||
.fa {
|
.fa {
|
||||||
color: #444;
|
color: #444;
|
||||||
|
@ -282,7 +282,7 @@ form.contest-join-pseudotab {
|
||||||
padding-left: 1px;
|
padding-left: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
padding: 0 5px;
|
padding-left: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#add-clarification {
|
#add-clarification {
|
||||||
|
|
|
@ -59,7 +59,7 @@ th.header.rank {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rank, .points, .problems, .user-name {
|
.rank, .points, .problems {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
max-width: 20em;
|
max-width: 20em;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
|
@ -28,8 +28,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-name {
|
.user-name {
|
||||||
position: relative;
|
padding-left: 1em !important;
|
||||||
padding-left: 2em !important;
|
padding-right: 1em !important;
|
||||||
|
display: flex;
|
||||||
|
min-width: max-content;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.organization-column {
|
.organization-column {
|
||||||
|
|
|
@ -79,6 +79,19 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js_media %}
|
{% 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 %}
|
{% block user_js_media %}{% endblock %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -90,7 +103,7 @@
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
{% if request.user != user.user %}
|
{% if request.user != user.user %}
|
||||||
<form method="post">
|
<form method="post" action="{{ url('user_toggle_follow', user.username) }}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button class="small {{ 'unfollow' if followed else 'follow' }}" style="width:145px">
|
<button class="small {{ 'unfollow' if followed else 'follow' }}" style="width:145px">
|
||||||
{% if followed %}
|
{% if followed %}
|
||||||
|
@ -105,19 +118,15 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
<form action="{{ url('all_user_submissions', user.user.username) }}">
|
<a href="{{ url('all_user_submissions', user.username) }}" class="button small" style="width:145px">
|
||||||
<input type="submit" value="{{ _('View submissions') }}" class="small" style="width:145px; padding-left: 1px; padding-right: 1px">
|
{{ _('View submissions') }}
|
||||||
</form>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<button class="small btn-midnightblue" style="width:145px" id="message-button">
|
||||||
<form action="{{ url('get_or_create_room') }}" method="POST">
|
{{ _('Send message') }}
|
||||||
{% csrf_token %}
|
</button>
|
||||||
<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>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if ratings %}
|
{% if ratings %}
|
||||||
|
|
Loading…
Reference in a new issue