Repository: Cloud-CV/EvalAI

Issue:
Add feature for filtering the submissions
## Current Scenario

If there are a large number of submissions in a challenge and a challenge host wants to view all the submissions for a participant team then they have to scroll through all the submissions.

## Expected

The challenge host should be able to filter the submissions by participant team name in `View All Submissions` Tab.

## Deliverables
- [ ] Add the required API's.
- [ ] Add the required frontend UI.

Please feel free to discuss the approach before start coding.


Discussion:
@RishabhJain2018 Can I work on this issue?
Can I take this, as I am done with my previous issue?
@anuj-rathore You can take #2142 issue.
Wait, wait. I'm here to help :)

Since @Sanji515 you commented first, you can take this one. @anuj-rathore Please take the issue #2142 or you can wait I'm opening some more issues.
@RishabhJain2018 Could you please take a look at the proposal I've sent ?
Yeah, I've it in my todo's. I'll get to it soon.
@RishabhJain2018 For frontend should I add another `dropdown` similar to `phase list` populated with the list of the participating team for filtering?
Hmm..I am thinking of having a `Filter Submissions` button near the `Download` button under `View All Submissions` Tab which will appear when the host will select a phase. Upon clicking that button a modal comes up saying
`Filter submissions by using participant team` with a list of participant teams having input as a checkbox and of course scrollable, out of which the host selects one or multiple participant teams` and the submissions by those team will appear in the results.

@deshraj Thoughts on this?
After having an offline discussion with @RishabhJain2018, we have converged on trying to get a search based filtering implemented instead of filtering through a modal. This will be a much simpler approach and provides a better user experience. 

So basically the flow will be something like this:

1. Select phase to see all submissions
2. Enter submission id or team name in a search box to filter the submissions
3. Show filtered submissions

See the following demo to get a sense of what we are looking for: http://plnkr.co/edit/XklvXtc1AZpndjLvXrh8?p=preview
So we are going to give two option for filtering one with `submission ID` and another with `team name` and the user can select among these two options, by which method he wants to search like in the `demo` dropdown is given for `Designation, name and company name`.
am I right? @RishabhJain2018 @deshraj 
yeah
@RishabhJain2018 @deshraj Please have a look to screencast.

![recording 4](https://user-images.githubusercontent.com/32524438/53214800-01740e00-3674-11e9-86c4-a9aa80ea98a6.gif)

@Sanji515 Could I ask which tool did you use to make this amazing gif? Many thanks!
@Helinia **Screencast-O-Matic** :) 
oh, I forgot this doesn't give you a gif, you will need to convert from video to Gif.
> @RishabhJain2018 @deshraj Please have a look to screencast.
> 
> ![recording 4](https://user-images.githubusercontent.com/32524438/53214800-01740e00-3674-11e9-86c4-a9aa80ea98a6.gif)

@RishabhJain2018 @deshraj Please look into it.
@Sanji515 this looks good in general. We might have more comments when we try it on our local machine. There might be some UI alignment we would want to do. Can you please open a PR for this? 
@deshraj @RishabhJain2018 sure!

Resolving patch:
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -56,6 +56,7 @@
     is_user_a_host_of_challenge,
     get_challenge_host_team_model,
 )
+from jobs.filters import SubmissionFilter
 from jobs.models import Submission
 from jobs.serializers import (
     SubmissionSerializer,
@@ -1188,7 +1189,8 @@ def get_all_submissions_of_challenge(
         submissions = Submission.objects.filter(
             challenge_phase=challenge_phase
         ).order_by("-submitted_at")
-        paginator, result_page = paginated_queryset(submissions, request)
+        filtered_submissions = SubmissionFilter(request.GET, queryset=submissions)
+        paginator, result_page = paginated_queryset(filtered_submissions.qs, request)
         serializer = ChallengeSubmissionManagementSerializer(
             result_page, many=True, context={"request": request}
         )
diff --git a/apps/jobs/filters.py b/apps/jobs/filters.py
new file mode 100644
--- /dev/null
+++ b/apps/jobs/filters.py
@@ -0,0 +1,8 @@
+import django_filters
+from .models import Submission
+
+
+class SubmissionFilter(django_filters.FilterSet):
+    class Meta:
+        model = Submission
+        fields = ["participant_team__team_name"]
diff --git a/settings/common.py b/settings/common.py
--- a/settings/common.py
+++ b/settings/common.py
@@ -70,6 +70,7 @@
     "rest_framework_docs",
     "rest_framework_expiring_authtoken",
     "drf_yasg",
+    "django_filters"
 ]
 
 INSTALLED_APPS = DEFAULT_APPS + OUR_APPS + THIRD_PARTY_APPS


Test patch: