ScreenshotFilter   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
wmc 0
1
# coding: utf8
2
3
"""
4
This software is licensed under the Apache 2 license, quoted below.
5
6
Copyright 2015 Crystalnix Limited
7
8
Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
use this file except in compliance with the License. You may obtain a copy of
10
the License at
11
12
    http://www.apache.org/licenses/LICENSE-2.0
13
14
Unless required by applicable law or agreed to in writing, software
15
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
License for the specific language governing permissions and limitations under
18
the License.
19
"""
20
21
from django.contrib import admin
22
23
from crash.admin import TextInputFilter, BooleanFilter
24
25
from feedback.models import Feedback, FeedbackDescription
26
from feedback.forms import FeedbackForm
27
28
29
class ScreenshotFilter(BooleanFilter):
30
    title = 'Screenshot'
31
    parameter_name = 'screenshot'
32
33
34
class BlackboxFilter(BooleanFilter):
35
    title = 'Blackbox'
36
    parameter_name = 'blackbox'
37
38
39
class SystemLogsFilter(BooleanFilter):
40
    title = 'System Logs'
41
    parameter_name = 'system_logs'
42
43
44
class AttachedFileFilter(BooleanFilter):
45
    title = 'Attached File'
46
    parameter_name = 'attached_file'
47
48
49
def short_url(obj):
50
    limit = 60
51
    res = obj.page_url
52
    return res if len(res) < limit else res[:limit] + '...'
53
short_url.short_description = 'Page URL'
54
55
@admin.register(Feedback)
56
class FeedbackAdmin(admin.ModelAdmin):
57
    list_display = ('id', 'description', 'email', short_url, 'created_at', 'ip',)
58
    list_display_links = ('id', 'description')
59
    list_filter = (('id', TextInputFilter,), ScreenshotFilter, BlackboxFilter, SystemLogsFilter, AttachedFileFilter, 'created_at',)
60
    form = FeedbackForm
61
    readonly_fields = ('created_at',)
62
63
    def get_queryset(self, request):
64
        qs = super(FeedbackAdmin, self).get_queryset(request)
65
        return qs.filter(description__startswith='BlackBox')
66
67
68
@admin.register(FeedbackDescription)
69
class FeedbackDescriptionAdmin(admin.ModelAdmin):
70
    list_display = ('id', 'description', 'email', short_url, 'created_at', 'ip',)
71
    list_display_links = ('id', 'description')
72
    list_filter = (('id', TextInputFilter,), ScreenshotFilter, BlackboxFilter, SystemLogsFilter, AttachedFileFilter, 'created_at')
73
    form = FeedbackForm
74
    readonly_fields = ('created_at',)
75
76
    def get_queryset(self, request):
77
        qs = super(FeedbackDescriptionAdmin, self).get_queryset(request)
78
        return qs.exclude(description__startswith='BlackBox')
79