This commit is contained in:
cuom1999 2023-07-06 22:39:16 +07:00
parent 1595063463
commit 1ca0d51f67
7 changed files with 41 additions and 41 deletions

View file

@ -156,7 +156,7 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
def get(self, request, *args, **kwargs):
target_comment = None
if "comment-id" in request.GET:
if "comment-id" in request.GET:
comment_id = int(request.GET["comment-id"])
try:
comment_obj = Comment.objects.get(id=comment_id)
@ -179,9 +179,7 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
queryset.select_related("author__user")
.filter(hidden=False)
.defer("author__about")
.annotate(
revisions=Count("versions", distinct=True)
)
.annotate(revisions=Count("versions", distinct=True))
)
else:
queryset = self.object.comments
@ -211,7 +209,7 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
queryset = self._get_queryset(target_comment)
comment_count = self.object.comments.filter(parent=None, hidden=False).count()
context["target_comment"] = -1
if (target_comment != None):
if target_comment != None:
context["target_comment"] = target_comment.id
if self.request.user.is_authenticated:

View file

@ -68,7 +68,7 @@ class Course(models.Model):
return False
@classmethod
def is_accessible_by(cls,course, profile):
def is_accessible_by(cls, course, profile):
userqueryset = CourseRole.objects.filter(course=course, user=profile)
if userqueryset.exists():
return True
@ -76,29 +76,29 @@ class Course(models.Model):
return False
@classmethod
def get_students(cls,course):
def get_students(cls, course):
return CourseRole.objects.filter(course=course, role="ST").values("user")
@classmethod
def get_assistants(cls,course):
def get_assistants(cls, course):
return CourseRole.objects.filter(course=course, role="AS").values("user")
@classmethod
def get_teachers(cls,course):
def get_teachers(cls, course):
return CourseRole.objects.filter(course=course, role="TE").values("user")
@classmethod
def add_student(cls,course, profiles):
def add_student(cls, course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role="ST")
@classmethod
def add_teachers(cls,course, profiles):
def add_teachers(cls, course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role="TE")
@classmethod
def add_assistants(cls,course, profiles):
def add_assistants(cls, course, profiles):
for profile in profiles:
CourseRole.make_role(course=course, user=profile, role="AS")

View file

@ -154,14 +154,12 @@ def get_comments(request, limit=10):
.annotate(
count_replies=Count("replies", distinct=True),
revisions=Count("versions", distinct=True),
)[offset:offset+limit]
)[offset : offset + limit]
)
if request.user.is_authenticated:
profile = request.profile
queryset = queryset.annotate(
my_vote=FilteredRelation(
"votes", condition=Q(votes__voter_id=profile.id)
),
my_vote=FilteredRelation("votes", condition=Q(votes__voter_id=profile.id)),
).annotate(vote_score=Coalesce(F("my_vote__score"), Value(0)))
new_offset = offset + min(len(queryset), limit)
@ -172,15 +170,15 @@ def get_comments(request, limit=10):
"request": request,
"comment_root_id": comment_root_id,
"comment_list": queryset,
"vote_hide_threshold" : settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD,
"vote_hide_threshold": settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD,
"perms": PermWrapper(request.user),
"offset": new_offset,
"limit": limit,
"comment_count": comment_count,
"comment_parent_none": parent_none,
"target_comment": target_comment,
"comment_more": comment_count - new_offset
}
"comment_more": comment_count - new_offset,
},
)
return HttpResponse(comment_html)

View file

@ -15,17 +15,20 @@ __all__ = [
course_directory_file = ""
class CourseListMixin(object):
def get_queryset(self):
return Course.objects.filter(is_open = "true").values()
return Course.objects.filter(is_open="true").values()
class CourseList(ListView):
model = Course
template_name = "course/list.html"
queryset = Course.objects.filter(is_public=True).filter(is_open=True)
def get_context_data(self, **kwargs):
context = super(CourseList,self).get_context_data(**kwargs)
available , enrolling = [] , []
context = super(CourseList, self).get_context_data(**kwargs)
available, enrolling = [], []
for course in Course.objects.filter(is_public=True).filter(is_open=True):
if Course.is_accessible_by(course, self.request.profile):
enrolling.append(course)
@ -34,4 +37,3 @@ class CourseList(ListView):
context["available"] = available
context["enrolling"] = enrolling
return context

View file

@ -351,7 +351,9 @@ class SubmissionsListBase(DiggPaginatorMixin, TitleMixin, ListView):
def _get_entire_queryset(self):
organization = self.organization or self.request.organization
if organization:
queryset = Submission.objects.filter(contest_object__organizations=organization)
queryset = Submission.objects.filter(
contest_object__organizations=organization
)
else:
queryset = Submission.objects.all()
use_straight_join(queryset)