| Total Lines | 14 |
| 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 | # Course admin interface |
||
| 18 | View Code Duplication | class CourseAdmin(django.contrib.admin.ModelAdmin): |
|
|
|
|||
| 19 | list_display = ['__str__', 'active', 'owner', assignments, actions] |
||
| 20 | filter_horizontal = ['tutors'] |
||
| 21 | |||
| 22 | class Media: |
||
| 23 | css = {'all': ('css/teacher.css',)} |
||
| 24 | |||
| 25 | def get_queryset(self, request): |
||
| 26 | ''' Restrict the listed courses for the current user.''' |
||
| 27 | qs = super(CourseAdmin, self).get_queryset(request) |
||
| 28 | if request.user.is_superuser: |
||
| 29 | return qs |
||
| 30 | else: |
||
| 31 | return qs.filter(Q(tutors__pk=request.user.pk) | Q(owner=request.user)).distinct() |
||
| 32 |