Fix recently visited organization

This commit is contained in:
Zhao-Linux 2022-10-18 05:08:12 +07:00
parent 512bc92116
commit 87eb082a18
6 changed files with 104 additions and 85 deletions

View file

@ -39,7 +39,7 @@ from judge.models.problem_data import (
problem_data_storage, problem_data_storage,
problem_directory_file, problem_directory_file,
) )
from judge.models.profile import Organization, OrganizationRequest, Profile, Friend from judge.models.profile import Organization, OrganizationRequest, Profile, Friend, OrganizationProfile
from judge.models.runtime import Judge, Language, RuntimeVersion from judge.models.runtime import Judge, Language, RuntimeVersion
from judge.models.submission import ( from judge.models.submission import (
SUBMISSION_RESULT, SUBMISSION_RESULT,

View file

@ -9,7 +9,6 @@ from django.urls import reverse
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.timezone import now from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from requests import delete
from fernet_fields import EncryptedCharField from fernet_fields import EncryptedCharField
from sortedm2m.fields import SortedManyToManyField from sortedm2m.fields import SortedManyToManyField
@ -438,35 +437,24 @@ class OrganizationProfile(models.Model):
verbose_name=_("organization"), verbose_name=_("organization"),
related_name="last_vist", related_name="last_vist",
on_delete=models.CASCADE, on_delete=models.CASCADE,
db_index=True,
) )
last_visit = models.AutoField( last_visit = models.AutoField(
verbose_name=_("last visit"), verbose_name=_("last visit"),
primary_key=True, primary_key=True,
) )
@classmethod
def is_organization(self, users, organization):
return (
self.objects.filter(users=users)
.filter(organization=organization)
.exists()
)
@classmethod @classmethod
def remove_organization(self, users, organization): def remove_organization(self, users, organization):
organizationprofile = self.objects.filter(users=users).filter( organizationprofile = self.objects.filter(users=users, organization=organization)
organization=organization if organizationprofile.exists():
) organizationprofile.delete()
organizationprofile.delete()
@classmethod @classmethod
def add_organization(self, users, organization): def add_organization(self, users, organization):
if self.is_organization(users, organization): self.remove_organization(users, organization)
self.remove_organization(users, organization)
new_organization = OrganizationProfile(users=users, organization=organization) new_organization = OrganizationProfile(users=users, organization=organization)
new_organization.save() new_organization.save()
@classmethod @classmethod
def get_organization(self, users): def get_most_recent_organizations(self, users):
return self.objects.filter(users=users).order_by("-last_visit")[:5] return self.objects.filter(users=users).order_by("-last_visit")[:5]

View file

@ -80,7 +80,7 @@ class FeedView(ListView):
start_time__lte=now, end_time__gt=now start_time__lte=now, end_time__gt=now
) )
context["future_contests"] = visible_contests.filter(start_time__gt=now) context["future_contests"] = visible_contests.filter(start_time__gt=now)
context["recent_organizations"] = OrganizationProfile.get_organization(self.request.profile) context["recent_organizations"] = OrganizationProfile.get_most_recent_organizations(self.request.profile)
context["top_rated"] = Profile.objects.filter(is_unlisted=False).order_by( context["top_rated"] = Profile.objects.filter(is_unlisted=False).order_by(
"-rating" "-rating"
)[:10] )[:10]

View file

@ -35,7 +35,6 @@ from django.views.generic.detail import (
SingleObjectTemplateResponseMixin, SingleObjectTemplateResponseMixin,
) )
from django.core.paginator import Paginator from django.core.paginator import Paginator
from judge.models.profile import OrganizationProfile
from reversion import revisions from reversion import revisions
from judge.forms import ( from judge.forms import (
@ -58,6 +57,7 @@ from judge.models import (
Contest, Contest,
Notification, Notification,
ContestProblem, ContestProblem,
OrganizationProfile,
) )
from judge import event_poster as event from judge import event_poster as event
from judge.utils.ranker import ranker from judge.utils.ranker import ranker

View file

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: lqdoj2\n" "Project-Id-Version: lqdoj2\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-10-16 00:26+0700\n" "POT-Creation-Date: 2022-10-18 05:05+0700\n"
"PO-Revision-Date: 2021-07-20 03:44\n" "PO-Revision-Date: 2021-07-20 03:44\n"
"Last-Translator: Icyene\n" "Last-Translator: Icyene\n"
"Language-Team: Vietnamese\n" "Language-Team: Vietnamese\n"
@ -21,6 +21,7 @@ msgstr ""
#: chat_box/models.py:31 chat_box/models.py:52 chat_box/models.py:63 #: chat_box/models.py:31 chat_box/models.py:52 chat_box/models.py:63
#: judge/admin/interface.py:150 judge/models/contest.py:622 #: judge/admin/interface.py:150 judge/models/contest.py:622
#: judge/models/contest.py:815 judge/models/profile.py:354 #: judge/models/contest.py:815 judge/models/profile.py:354
#: judge/models/profile.py:430
msgid "user" msgid "user"
msgstr "người dùng" msgstr "người dùng"
@ -474,7 +475,7 @@ msgstr "Đăng ký để nhận thông báo về các kỳ thi"
msgid "Enable experimental features" msgid "Enable experimental features"
msgstr "Sử dụng các tính năng thử nghiệm" msgstr "Sử dụng các tính năng thử nghiệm"
#: judge/forms.py:108 judge/views/organization.py:513 #: judge/forms.py:108 judge/views/organization.py:514
#: judge/views/register.py:68 #: judge/views/register.py:68
#, python-brace-format #, python-brace-format
msgid "You may not be part of more than {count} public groups." msgid "You may not be part of more than {count} public groups."
@ -1765,7 +1766,7 @@ msgid ""
msgstr "Ảnh này sẽ thay thế logo mặc định khi ở trong tổ chức." msgstr "Ảnh này sẽ thay thế logo mặc định khi ở trong tổ chức."
#: judge/models/profile.py:125 judge/models/profile.py:154 #: judge/models/profile.py:125 judge/models/profile.py:154
#: judge/models/profile.py:360 #: judge/models/profile.py:360 judge/models/profile.py:437
msgid "organization" msgid "organization"
msgstr "" msgstr ""
@ -1899,6 +1900,12 @@ msgstr "đơn đăng ký tham gia"
msgid "organization join requests" msgid "organization join requests"
msgstr "đơn đăng ký tham gia" msgstr "đơn đăng ký tham gia"
#: judge/models/profile.py:442
#, fuzzy
#| msgid "last seen"
msgid "last visit"
msgstr "xem lần cuối"
#: judge/models/runtime.py:21 #: judge/models/runtime.py:21
msgid "short identifier" msgid "short identifier"
msgstr "tên ngắn" msgstr "tên ngắn"
@ -2448,16 +2455,16 @@ msgstr "Giới thiệu"
msgid "Custom Checker Sample" msgid "Custom Checker Sample"
msgstr "Hướng dẫn viết trình chấm" msgstr "Hướng dẫn viết trình chấm"
#: judge/views/blog.py:111 #: judge/views/blog.py:114
#, python-format #, python-format
msgid "Page %d of Posts" msgid "Page %d of Posts"
msgstr "Trang %d" msgstr "Trang %d"
#: judge/views/blog.py:166 #: judge/views/blog.py:169
msgid "Ticket feed" msgid "Ticket feed"
msgstr "Báo cáo" msgstr "Báo cáo"
#: judge/views/blog.py:184 #: judge/views/blog.py:187
msgid "Comment feed" msgid "Comment feed"
msgstr "Bình luận" msgstr "Bình luận"
@ -2473,8 +2480,8 @@ msgstr "Bạn phải giải ít nhất 1 bài trước khi được vote."
msgid "You already voted." msgid "You already voted."
msgstr "Bạn đã vote." msgstr "Bạn đã vote."
#: judge/views/comment.py:155 judge/views/organization.py:813 #: judge/views/comment.py:155 judge/views/organization.py:814
#: judge/views/organization.py:959 judge/views/organization.py:1124 #: judge/views/organization.py:960 judge/views/organization.py:1125
msgid "Edited from site" msgid "Edited from site"
msgstr "Chỉnh sửa từ web" msgstr "Chỉnh sửa từ web"
@ -2652,91 +2659,91 @@ msgstr "Runtimes"
msgid "Notifications (%d unseen)" msgid "Notifications (%d unseen)"
msgstr "Thông báo (%d chưa xem)" msgstr "Thông báo (%d chưa xem)"
#: judge/views/organization.py:140 judge/views/organization.py:146 #: judge/views/organization.py:142 judge/views/organization.py:148
msgid "No such organization" msgid "No such organization"
msgstr "Không có tổ chức như vậy" msgstr "Không có tổ chức như vậy"
#: judge/views/organization.py:141 #: judge/views/organization.py:143
#, python-format #, python-format
msgid "Could not find an organization with the key \"%s\"." msgid "Could not find an organization with the key \"%s\"."
msgstr "Không tìm thấy tổ chức với mã \"%s\"." msgstr "Không tìm thấy tổ chức với mã \"%s\"."
#: judge/views/organization.py:147 #: judge/views/organization.py:149
msgid "Could not find such organization." msgid "Could not find such organization."
msgstr "" msgstr ""
#: judge/views/organization.py:165 #: judge/views/organization.py:167
msgid "Can't edit organization" msgid "Can't edit organization"
msgstr "Không thể chỉnh sửa tổ chức" msgstr "Không thể chỉnh sửa tổ chức"
#: judge/views/organization.py:166 #: judge/views/organization.py:168
msgid "You are not allowed to edit this organization." msgid "You are not allowed to edit this organization."
msgstr "Bạn không được phép chỉnh sửa tổ chức này." msgstr "Bạn không được phép chỉnh sửa tổ chức này."
#: judge/views/organization.py:178 judge/views/organization.py:323 #: judge/views/organization.py:180 judge/views/organization.py:324
#, fuzzy #, fuzzy
#| msgid "Can't edit organization" #| msgid "Can't edit organization"
msgid "Can't access organization" msgid "Can't access organization"
msgstr "Không thể chỉnh sửa tổ chức" msgstr "Không thể chỉnh sửa tổ chức"
#: judge/views/organization.py:179 judge/views/organization.py:324 #: judge/views/organization.py:181 judge/views/organization.py:325
msgid "You are not allowed to access this organization." msgid "You are not allowed to access this organization."
msgstr "Bạn không được phép chỉnh sửa tổ chức này." msgstr "Bạn không được phép chỉnh sửa tổ chức này."
#: judge/views/organization.py:237 judge/views/register.py:49 #: judge/views/organization.py:239 judge/views/register.py:49
#: judge/views/stats.py:184 templates/contest/list.html:87 #: judge/views/stats.py:184 templates/contest/list.html:87
#: templates/problem/list-base.html:104 templates/stats/site.html:33 #: templates/problem/list-base.html:104 templates/stats/site.html:33
#: templates/user/user-left-sidebar.html:4 templates/user/user-list-tabs.html:6 #: templates/user/user-left-sidebar.html:4 templates/user/user-list-tabs.html:6
msgid "Groups" msgid "Groups"
msgstr "Nhóm" msgstr "Nhóm"
#: judge/views/organization.py:330 #: judge/views/organization.py:331
#, python-format #, python-format
msgid "%s Members" msgid "%s Members"
msgstr "%s Thành viên" msgstr "%s Thành viên"
#: judge/views/organization.py:469 #: judge/views/organization.py:470
#, python-brace-format #, python-brace-format
msgid "All submissions in <a href=\"{1}\">{0}</a>" msgid "All submissions in <a href=\"{1}\">{0}</a>"
msgstr "Bài nộp trong <a href=\"{1}\">{0}</a>" msgstr "Bài nộp trong <a href=\"{1}\">{0}</a>"
#: judge/views/organization.py:499 judge/views/organization.py:505 #: judge/views/organization.py:500 judge/views/organization.py:506
#: judge/views/organization.py:512 #: judge/views/organization.py:513
msgid "Joining group" msgid "Joining group"
msgstr "Tham gia nhóm" msgstr "Tham gia nhóm"
#: judge/views/organization.py:500 #: judge/views/organization.py:501
msgid "You are already in the group." msgid "You are already in the group."
msgstr "Bạn đã ở trong nhóm." msgstr "Bạn đã ở trong nhóm."
#: judge/views/organization.py:505 #: judge/views/organization.py:506
msgid "This group is not open." msgid "This group is not open."
msgstr "Nhóm này là nhóm kín." msgstr "Nhóm này là nhóm kín."
#: judge/views/organization.py:528 #: judge/views/organization.py:529
msgid "Leaving group" msgid "Leaving group"
msgstr "Rời nhóm" msgstr "Rời nhóm"
#: judge/views/organization.py:529 #: judge/views/organization.py:530
#, python-format #, python-format
msgid "You are not in \"%s\"." msgid "You are not in \"%s\"."
msgstr "Bạn không ở trong \"%s\"." msgstr "Bạn không ở trong \"%s\"."
#: judge/views/organization.py:554 #: judge/views/organization.py:555
#, python-format #, python-format
msgid "Request to join %s" msgid "Request to join %s"
msgstr "Đăng ký tham gia %s" msgstr "Đăng ký tham gia %s"
#: judge/views/organization.py:585 #: judge/views/organization.py:586
msgid "Join request detail" msgid "Join request detail"
msgstr "Chi tiết đơn đăng ký" msgstr "Chi tiết đơn đăng ký"
#: judge/views/organization.py:633 #: judge/views/organization.py:634
#, python-format #, python-format
msgid "Managing join requests for %s" msgid "Managing join requests for %s"
msgstr "Quản lý đơn đăng ký cho %s" msgstr "Quản lý đơn đăng ký cho %s"
#: judge/views/organization.py:673 #: judge/views/organization.py:674
#, python-format #, python-format
msgid "" msgid ""
"Your organization can only receive %d more members. You cannot approve %d " "Your organization can only receive %d more members. You cannot approve %d "
@ -2745,96 +2752,96 @@ msgstr ""
"Tổ chức chỉ có thể chứa %d thành viên. Bạn không thể chấp thuận nhiều hơn %d " "Tổ chức chỉ có thể chứa %d thành viên. Bạn không thể chấp thuận nhiều hơn %d "
"người." "người."
#: judge/views/organization.py:691 #: judge/views/organization.py:692
#, python-format #, python-format
msgid "Approved %d user." msgid "Approved %d user."
msgid_plural "Approved %d users." msgid_plural "Approved %d users."
msgstr[0] "Đã chấp thuận %d người." msgstr[0] "Đã chấp thuận %d người."
#: judge/views/organization.py:694 #: judge/views/organization.py:695
#, python-format #, python-format
msgid "Rejected %d user." msgid "Rejected %d user."
msgid_plural "Rejected %d users." msgid_plural "Rejected %d users."
msgstr[0] "Đã từ chối %d người." msgstr[0] "Đã từ chối %d người."
#: judge/views/organization.py:734 #: judge/views/organization.py:735
#, python-format #, python-format
msgid "Add member for %s" msgid "Add member for %s"
msgstr "Thêm thành viên cho %s" msgstr "Thêm thành viên cho %s"
#: judge/views/organization.py:746 #: judge/views/organization.py:747
#, fuzzy #, fuzzy
#| msgid "Edited from site" #| msgid "Edited from site"
msgid "Added members from site" msgid "Added members from site"
msgstr "Chỉnh sửa từ web" msgstr "Chỉnh sửa từ web"
#: judge/views/organization.py:766 judge/views/organization.py:774 #: judge/views/organization.py:767 judge/views/organization.py:775
msgid "Can't kick user" msgid "Can't kick user"
msgstr "Không thể đuổi" msgstr "Không thể đuổi"
#: judge/views/organization.py:767 #: judge/views/organization.py:768
msgid "The user you are trying to kick does not exist!" msgid "The user you are trying to kick does not exist!"
msgstr "" msgstr ""
#: judge/views/organization.py:775 #: judge/views/organization.py:776
#, python-format #, python-format
msgid "The user you are trying to kick is not in organization: %s." msgid "The user you are trying to kick is not in organization: %s."
msgstr "" msgstr ""
#: judge/views/organization.py:796 judge/views/organization.py:948 #: judge/views/organization.py:797 judge/views/organization.py:949
#, fuzzy, python-format #, fuzzy, python-format
#| msgid "Editing %s" #| msgid "Editing %s"
msgid "Edit %s" msgid "Edit %s"
msgstr "Đang chỉnh sửa %s" msgstr "Đang chỉnh sửa %s"
#: judge/views/organization.py:824 templates/organization/list.html:59 #: judge/views/organization.py:825 templates/organization/list.html:59
msgid "Create group" msgid "Create group"
msgstr "Tạo nhóm" msgstr "Tạo nhóm"
#: judge/views/organization.py:839 #: judge/views/organization.py:840
msgid "Exceeded limit" msgid "Exceeded limit"
msgstr "" msgstr ""
#: judge/views/organization.py:840 #: judge/views/organization.py:841
#, python-format #, python-format
msgid "You created too many groups. You can only create at most %d groups" msgid "You created too many groups. You can only create at most %d groups"
msgstr "" msgstr ""
#: judge/views/organization.py:845 judge/views/organization.py:870 #: judge/views/organization.py:846 judge/views/organization.py:871
#: judge/views/organization.py:1014 #: judge/views/organization.py:1015
msgid "Added from site" msgid "Added from site"
msgstr "Thêm từ web" msgstr "Thêm từ web"
#: judge/views/organization.py:861 #: judge/views/organization.py:862
#: templates/organization/org-right-sidebar.html:55 #: templates/organization/org-right-sidebar.html:55
msgid "Add contest" msgid "Add contest"
msgstr "Thêm kỳ thi" msgstr "Thêm kỳ thi"
#: judge/views/organization.py:904 judge/views/organization.py:1066 #: judge/views/organization.py:905 judge/views/organization.py:1067
msgid "Permission denied" msgid "Permission denied"
msgstr "Truy cập bị từ chối" msgstr "Truy cập bị từ chối"
#: judge/views/organization.py:905 #: judge/views/organization.py:906
#, fuzzy #, fuzzy
#| msgid "You are not allowed to edit this organization." #| msgid "You are not allowed to edit this organization."
msgid "You are not allowed to edit this contest" msgid "You are not allowed to edit this contest"
msgstr "Bạn không được phép chỉnh sửa tổ chức này." msgstr "Bạn không được phép chỉnh sửa tổ chức này."
#: judge/views/organization.py:1003 #: judge/views/organization.py:1004
#, python-format #, python-format
msgid "Add blog for %s" msgid "Add blog for %s"
msgstr "Thêm bài đăng cho %s" msgstr "Thêm bài đăng cho %s"
#: judge/views/organization.py:1067 #: judge/views/organization.py:1068
msgid "Not allowed to edit this blog" msgid "Not allowed to edit this blog"
msgstr "Bạn không được phép chỉnh sửa bài đăng này." msgstr "Bạn không được phép chỉnh sửa bài đăng này."
#: judge/views/organization.py:1099 #: judge/views/organization.py:1100
#, python-format #, python-format
msgid "Edit blog %s" msgid "Edit blog %s"
msgstr "Chỉnh sửa %s" msgstr "Chỉnh sửa %s"
#: judge/views/organization.py:1150 #: judge/views/organization.py:1151
#, python-format #, python-format
msgid "Pending blogs in %s" msgid "Pending blogs in %s"
msgstr "Bài đang đợi duyệt trong %s" msgstr "Bài đang đợi duyệt trong %s"
@ -4738,6 +4745,10 @@ msgstr "Không có máy chấm có thể chấm bài này."
msgid "Submit!" msgid "Submit!"
msgstr "Nộp bài!" msgstr "Nộp bài!"
#: templates/recent-organization.html:30
msgid "Recently visited organizations"
msgstr "Các nhóm thăm gần đây"
#: templates/registration/activate.html:3 #: templates/registration/activate.html:3
#, python-format #, python-format
msgid "%(key)s is an invalid activation key." msgid "%(key)s is an invalid activation key."

View file

@ -1,20 +1,40 @@
{% block two_col_media %}
<style>
.organization-row {
display: block;
padding: 0.5em;
border-bottom: 1px gray solid;
border-top: none;
color: black;
font-weight: bold;
}
.organization-row:hover {
background-color: #f3f3f3;
}
.org-logo {
vertical-align: middle;
height: 2em;
width: 2em;
display: inline-block;
margin-right: 0.5em;
margin-left: 0.5em;
}
.toggle {
cursor: pointer;
}
</style>
{% endblock %}
{% if recent_organizations %} {% if recent_organizations %}
<div class="blog-sidebox sidebox"> <div class="blog-sidebox sidebox">
<h3>{{ _('Recent Organization') }} <i class="fa fa-trophy"></i></h3> <h3>{{ _('Recently visited organizations') }} <i class="fa fa-users"></i></h3>
<div class="sidebox-content" style="padding: 0; border: 0"> <div class="organization-container toggled">
<table class="table feed-table"> {% for organization in recent_organizations %}
<tbody> <a href="{{ url('organization_home', organization.organization.pk, organization.organization.slug) }}" class="sidebox-content organization-row" title="{{organization.organization.about}}">
{% for organization in recent_organizations %} <img class="org-logo" src="{{ organization.organization.logo_override_image or static('icons/icon.png') }}">
<tr> <span>{{ organization.organization }}</span>
<td style="padding: 7px 2px"> </a>
<a href="{{ url('organization_home', organization.organization.pk, organization.organization.slug) }}"> {% endfor %}
<b> {{organization.organization}} </b> </div>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div> </div>
{% endif %} {% endif %}