Code Duplication    Length = 17-18 lines in 2 locations

web/opensubmit/admin/submission.py 2 locations

@@ 67-84 (lines=18) @@
64
            return qs.filter(state__in=[Submission.GRADED])
65
        elif self.value() == 'closed':
66
            return Submission.qs_notified(qs)
67
        else:
68
            return qs
69
70
71
class SubmissionAssignmentFilter(SimpleListFilter):
72
73
    ''' This custom filter allows to filter the submissions according to their
74
        assignment. Only submissions from courses were the user is tutor are
75
        considered.
76
    '''
77
    title = _('Assignment')
78
    parameter_name = 'assignmentfilter'
79
80
    def lookups(self, request, model_admin):
81
        tutor_assignments = Assignment.objects.filter(course__in=list(
82
            request.user.profile.tutor_courses())).order_by('title')
83
        return ((ass.pk, ass.title) for ass in tutor_assignments)
84
85
    def queryset(self, request, qs):
86
        if self.value():
87
            return qs.filter(assignment__exact=self.value())
@@ 87-103 (lines=17) @@
84
85
    def queryset(self, request, qs):
86
        if self.value():
87
            return qs.filter(assignment__exact=self.value())
88
        else:
89
            return qs.filter(assignment__course__in=list(request.user.profile.tutor_courses()))
90
91
92
class SubmissionCourseFilter(SimpleListFilter):
93
94
    ''' This custom filter allows to filter the submissions according to
95
        the course they belong to. Additionally, only submission that the
96
        user is a tutor for are returned in any of the filter settings.
97
    '''
98
    title = _('Course')
99
    parameter_name = 'coursefilter'
100
101
    def lookups(self, request, model_admin):
102
        return ((c.pk, c.title) for c in list(request.user.profile.tutor_courses()))
103
104
    def queryset(self, request, qs):
105
        if self.value():
106
            return qs.filter(assignment__course__exact=self.value())