SubmissionFileAdmin   A
last analyzed

Size/Duplication

Total Lines 13
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A get_queryset() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
from django.contrib.admin import ModelAdmin, StackedInline
2
from django.db.models import Q
3
from opensubmit.models import Submission
4
5
def submissions(submfile):
6
    while submfile.replaced_by is not None:
7
        submfile = submfile.replaced_by
8
    subms = submfile.submissions.all()
9
    return ','.join([str(sub) for sub in subms])
10
11
12
def not_withdrawn(submfile):
13
    return submfile.replaced_by is None
14
not_withdrawn.boolean = True
15
16 View Code Duplication
class SubmissionFileAdmin(ModelAdmin):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
17
    list_display = ['__str__', 'fetched', submissions, not_withdrawn]
18
19
    class Media:
20
        css = {'all': ('css/teacher.css',)}
21
22
    def get_queryset(self, request):
23
        ''' Restrict the listed submission files for the current user.'''
24
        qs = super(SubmissionFileAdmin, self).get_queryset(request)
25
        if request.user.is_superuser:
26
            return qs
27
        else:
28
            return qs.filter(Q(submissions__assignment__course__tutors__pk=request.user.pk) | Q(submissions__assignment__course__owner=request.user)).distinct()
29