Add friend submissions
This commit is contained in:
parent
3eda48f3ea
commit
fc852d1bc7
8 changed files with 70 additions and 34 deletions
|
@ -369,6 +369,10 @@ urlpatterns = [
|
||||||
r"^submissions/user/(?P<user>\w+)/",
|
r"^submissions/user/(?P<user>\w+)/",
|
||||||
paged_list_view(submission.AllUserSubmissions, "all_user_submissions"),
|
paged_list_view(submission.AllUserSubmissions, "all_user_submissions"),
|
||||||
),
|
),
|
||||||
|
url(
|
||||||
|
r"^submissions/friends/",
|
||||||
|
paged_list_view(submission.AllFriendSubmissions, "all_friend_submissions"),
|
||||||
|
),
|
||||||
url(
|
url(
|
||||||
r"^src/(?P<submission>\d+)/raw$",
|
r"^src/(?P<submission>\d+)/raw$",
|
||||||
submission.SubmissionSourceRaw.as_view(),
|
submission.SubmissionSourceRaw.as_view(),
|
||||||
|
@ -487,7 +491,7 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
url(r"^contests/", paged_list_view(contests.ContestList, "contest_list")),
|
url(r"^contests/", paged_list_view(contests.ContestList, "contest_list")),
|
||||||
url(r"^course/", paged_list_view(course.CourseList, "course_list" )),
|
url(r"^course/", paged_list_view(course.CourseList, "course_list")),
|
||||||
url(
|
url(
|
||||||
r"^contests/(?P<year>\d+)/(?P<month>\d+)/$",
|
r"^contests/(?P<year>\d+)/(?P<month>\d+)/$",
|
||||||
contests.ContestCalendar.as_view(),
|
contests.ContestCalendar.as_view(),
|
||||||
|
|
|
@ -333,14 +333,12 @@ class Profile(models.Model):
|
||||||
def css_class(self):
|
def css_class(self):
|
||||||
return self.get_user_css_class(self.display_rank, self.rating)
|
return self.get_user_css_class(self.display_rank, self.rating)
|
||||||
|
|
||||||
def get_friends(self): # list of usernames, including you
|
def get_friends(self): # list of ids, including you
|
||||||
friend_obj = self.following_users.all()
|
friend_obj = self.following_users.prefetch_related("users")
|
||||||
ret = set()
|
ret = []
|
||||||
|
|
||||||
if friend_obj:
|
if friend_obj:
|
||||||
ret = set(friend.username for friend in friend_obj[0].users.all())
|
ret = [friend.id for friend in friend_obj[0].users.all()]
|
||||||
|
ret.append(self.id)
|
||||||
ret.add(self.username)
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def can_edit_organization(self, org):
|
def can_edit_organization(self, org):
|
||||||
|
@ -395,7 +393,9 @@ class OrganizationRequest(models.Model):
|
||||||
class Friend(models.Model):
|
class Friend(models.Model):
|
||||||
users = models.ManyToManyField(Profile)
|
users = models.ManyToManyField(Profile)
|
||||||
current_user = models.ForeignKey(
|
current_user = models.ForeignKey(
|
||||||
Profile, related_name="following_users", on_delete=CASCADE
|
Profile,
|
||||||
|
related_name="following_users",
|
||||||
|
on_delete=CASCADE,
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -161,7 +161,9 @@ class ContestList(
|
||||||
i
|
i
|
||||||
for i in self.org_query
|
for i in self.org_query
|
||||||
if i
|
if i
|
||||||
in self.request.profile.organizations.values_list("id", flat=True)
|
in self.request.profile.organizations.values_list(
|
||||||
|
"id", flat=True
|
||||||
|
)
|
||||||
]
|
]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
@ -1024,8 +1026,8 @@ def contest_ranking_ajax(request, contest, participation=None):
|
||||||
|
|
||||||
queryset = contest.users.filter(virtual__gte=0)
|
queryset = contest.users.filter(virtual__gte=0)
|
||||||
if request.GET.get("friend") == "true" and request.profile:
|
if request.GET.get("friend") == "true" and request.profile:
|
||||||
friends = list(request.profile.get_friends())
|
friends = request.profile.get_friends()
|
||||||
queryset = queryset.filter(user__user__username__in=friends)
|
queryset = queryset.filter(user_id__in=friends)
|
||||||
if request.GET.get("virtual") != "true":
|
if request.GET.get("virtual") != "true":
|
||||||
queryset = queryset.filter(virtual=0)
|
queryset = queryset.filter(virtual=0)
|
||||||
|
|
||||||
|
|
|
@ -439,6 +439,9 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView):
|
||||||
def get_my_submissions_page(self):
|
def get_my_submissions_page(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_friend_submissions_page(self):
|
||||||
|
return None
|
||||||
|
|
||||||
def get_all_submissions_page(self):
|
def get_all_submissions_page(self):
|
||||||
return reverse("all_submissions")
|
return reverse("all_submissions")
|
||||||
|
|
||||||
|
@ -503,6 +506,7 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView):
|
||||||
)
|
)
|
||||||
context["first_page_href"] = (self.first_page_href or ".") + suffix
|
context["first_page_href"] = (self.first_page_href or ".") + suffix
|
||||||
context["my_submissions_link"] = self.get_my_submissions_page()
|
context["my_submissions_link"] = self.get_my_submissions_page()
|
||||||
|
context["friend_submissions_link"] = self.get_friend_submissions_page()
|
||||||
context["all_submissions_link"] = self.get_all_submissions_page()
|
context["all_submissions_link"] = self.get_all_submissions_page()
|
||||||
context["page_type"] = self.page_type
|
context["page_type"] = self.page_type
|
||||||
|
|
||||||
|
@ -558,7 +562,21 @@ class ConditionalUserTabMixin(object):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class AllUserSubmissions(ConditionalUserTabMixin, UserMixin, SubmissionsListBase):
|
class GeneralSubmissions(SubmissionsListBase):
|
||||||
|
def get_my_submissions_page(self):
|
||||||
|
if self.request.user.is_authenticated:
|
||||||
|
return reverse(
|
||||||
|
"all_user_submissions", kwargs={"user": self.request.user.username}
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_friend_submissions_page(self):
|
||||||
|
if self.request.user.is_authenticated:
|
||||||
|
return reverse("all_friend_submissions")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class AllUserSubmissions(ConditionalUserTabMixin, UserMixin, GeneralSubmissions):
|
||||||
def _get_queryset(self):
|
def _get_queryset(self):
|
||||||
return (
|
return (
|
||||||
super(AllUserSubmissions, self)
|
super(AllUserSubmissions, self)
|
||||||
|
@ -573,19 +591,13 @@ class AllUserSubmissions(ConditionalUserTabMixin, UserMixin, SubmissionsListBase
|
||||||
|
|
||||||
def get_content_title(self):
|
def get_content_title(self):
|
||||||
if self.request.user.is_authenticated and self.request.profile == self.profile:
|
if self.request.user.is_authenticated and self.request.profile == self.profile:
|
||||||
return format_html("All my submissions")
|
return format_html(_("All my submissions"))
|
||||||
return format_html(
|
return format_html(
|
||||||
'All submissions by <a href="{1}">{0}</a>',
|
_('All submissions by <a href="{1}">{0}</a>'),
|
||||||
self.username,
|
self.username,
|
||||||
reverse("user_page", args=[self.username]),
|
reverse("user_page", args=[self.username]),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_my_submissions_page(self):
|
|
||||||
if self.request.user.is_authenticated:
|
|
||||||
return reverse(
|
|
||||||
"all_user_submissions", kwargs={"user": self.request.user.username}
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(AllUserSubmissions, self).get_context_data(**kwargs)
|
context = super(AllUserSubmissions, self).get_context_data(**kwargs)
|
||||||
context["dynamic_update"] = context["page_obj"].number == 1
|
context["dynamic_update"] = context["page_obj"].number == 1
|
||||||
|
@ -594,6 +606,25 @@ class AllUserSubmissions(ConditionalUserTabMixin, UserMixin, SubmissionsListBase
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class AllFriendSubmissions(LoginRequiredMixin, GeneralSubmissions):
|
||||||
|
def _get_queryset(self):
|
||||||
|
friends = self.request.profile.get_friends()
|
||||||
|
return (
|
||||||
|
super(AllFriendSubmissions, self)
|
||||||
|
._get_queryset()
|
||||||
|
.filter(user_id__in=friends)
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_title(self):
|
||||||
|
return _("All friend submissions")
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(AllFriendSubmissions, self).get_context_data(**kwargs)
|
||||||
|
context["dynamic_update"] = False
|
||||||
|
context["page_type"] = "friend_tab"
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
class ProblemSubmissionsBase(SubmissionsListBase):
|
class ProblemSubmissionsBase(SubmissionsListBase):
|
||||||
show_problem = False
|
show_problem = False
|
||||||
dynamic_update = True
|
dynamic_update = True
|
||||||
|
@ -772,15 +803,9 @@ def single_submission_query(request):
|
||||||
return single_submission(request, int(request.GET["id"]), bool(show_problem))
|
return single_submission(request, int(request.GET["id"]), bool(show_problem))
|
||||||
|
|
||||||
|
|
||||||
class AllSubmissions(SubmissionsListBase):
|
class AllSubmissions(GeneralSubmissions):
|
||||||
stats_update_interval = 3600
|
stats_update_interval = 3600
|
||||||
|
|
||||||
def get_my_submissions_page(self):
|
|
||||||
if self.request.user.is_authenticated:
|
|
||||||
return reverse(
|
|
||||||
"all_user_submissions", kwargs={"user": self.request.user.username}
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(AllSubmissions, self).get_context_data(**kwargs)
|
context = super(AllSubmissions, self).get_context_data(**kwargs)
|
||||||
context["dynamic_update"] = (
|
context["dynamic_update"] = (
|
||||||
|
|
|
@ -449,8 +449,8 @@ class UserList(QueryStringSortMixin, DiggPaginatorMixin, TitleMixin, ListView):
|
||||||
filter_friend = False
|
filter_friend = False
|
||||||
|
|
||||||
def filter_friend_queryset(self, queryset):
|
def filter_friend_queryset(self, queryset):
|
||||||
friends = list(self.request.profile.get_friends())
|
friends = self.request.profile.get_friends()
|
||||||
ret = queryset.filter(user__username__in=friends)
|
ret = queryset.filter(id__in=friends)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
|
@ -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: 2023-02-09 10:57+0700\n"
|
"POT-Creation-Date: 2023-02-13 09:44+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"
|
||||||
|
@ -3261,7 +3261,7 @@ msgstr "Bài nộp của %(user)s cho bài %(problem)s"
|
||||||
msgid "All submissions"
|
msgid "All submissions"
|
||||||
msgstr "Tất cả bài nộp"
|
msgstr "Tất cả bài nộp"
|
||||||
|
|
||||||
#: judge/views/submission.py:571
|
#: judge/views/submission.py:571 judge/views/submission.py:576
|
||||||
msgid "All my submissions"
|
msgid "All my submissions"
|
||||||
msgstr "Tất cả bài nộp của tôi"
|
msgstr "Tất cả bài nộp của tôi"
|
||||||
|
|
||||||
|
@ -3270,6 +3270,10 @@ msgstr "Tất cả bài nộp của tôi"
|
||||||
msgid "All submissions by %s"
|
msgid "All submissions by %s"
|
||||||
msgstr "Tất cả bài nộp của %s"
|
msgstr "Tất cả bài nộp của %s"
|
||||||
|
|
||||||
|
#: judge/views/submission.py:578
|
||||||
|
msgid "All submissions by <a href=\"{1}\">{0}</a>"
|
||||||
|
msgstr "Tất cả bài nộp của <a href=\"{1}\">{0}</a>"
|
||||||
|
|
||||||
#: judge/views/submission.py:617
|
#: judge/views/submission.py:617
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "All submissions for %s"
|
msgid "All submissions for %s"
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
{% extends "user/base-users-table.html" %}
|
{% extends "user/base-users-table.html" %}
|
||||||
|
|
||||||
{% set friends = request.profile.get_friends() if request.user.is_authenticated else {} %}
|
|
||||||
|
|
||||||
{% block after_rank_head %}
|
{% block after_rank_head %}
|
||||||
{% if has_rating %}
|
{% if has_rating %}
|
||||||
<th class="rating-column">{{ _('Rating') }}</th>
|
<th class="rating-column">{{ _('Rating') }}</th>
|
||||||
|
|
|
@ -388,6 +388,9 @@
|
||||||
{% if page_type == 'user_submissions_tab' %}
|
{% if page_type == 'user_submissions_tab' %}
|
||||||
{{ make_tab_item('user_submissions_tab', 'fa fa-user', None, _("%(user)s", user=tab_username)) }}
|
{{ make_tab_item('user_submissions_tab', 'fa fa-user', None, _("%(user)s", user=tab_username)) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if friend_submissions_link %}
|
||||||
|
{{ make_tab_item('friend_tab', 'fa fa-user', friend_submissions_link, _('Friends')) }}
|
||||||
|
{% endif %}
|
||||||
{% if perms.judge.change_submission %}
|
{% if perms.judge.change_submission %}
|
||||||
{{ make_tab_item('admin', 'fa fa-edit', url('admin:judge_submission_changelist'), _('Admin')) }}
|
{{ make_tab_item('admin', 'fa fa-edit', url('admin:judge_submission_changelist'), _('Admin')) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue