Total Lines | 13 |
Duplicated Lines | 100 % |
Changes | 0 |
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 |
||
16 | View Code Duplication | class SubmissionFileAdmin(ModelAdmin): |
|
|
|||
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 |