Skip to content
Snippets Groups Projects
Commit d4d6d522 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

GH-877: Allow to find newer comments easily

parent ca4132c0
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,9 @@ class BaseActivityQuerySet(models.QuerySet):
def visible_to(self, user):
return self.filter(visibility__in=self.model.visibility_for(user))
def newer(self, activity):
return self.filter(timestamp__gt=activity.timestamp)
class ActivityQuerySet(BaseActivityQuerySet):
def comments(self):
......
......@@ -108,13 +108,22 @@ class RoundLabList(generics.ListAPIView):
pagination_class = StandardResultsSetPagination
class NewerThanFilter(filters.ModelChoiceFilter):
def filter(self, qs, value):
if not value:
return qs
return qs.newer(value)
class CommentFilter(filters.FilterSet):
since = filters.DateTimeFilter(field_name="timestamp", lookup_expr='gte')
before = filters.DateTimeFilter(field_name="timestamp", lookup_expr='lte')
newer = NewerThanFilter(queryset=Activity.comments.all())
class Meta:
model = Activity
fields = ['submission', 'visibility', 'since', 'before']
fields = ['submission', 'visibility', 'since', 'before', 'newer']
class CommentList(generics.ListAPIView):
......@@ -138,7 +147,7 @@ class CommentListCreate(generics.ListCreateAPIView):
permissions.IsAuthenticated, IsApplyStaffUser,
)
filter_backends = (filters.DjangoFilterBackend,)
filter_fields = ('visibility',)
filter_class = CommentFilter
pagination_class = StandardResultsSetPagination
def get_queryset(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment