|
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 import forms |
|
22
|
|
|
from django.core.files.uploadedfile import UploadedFile |
|
23
|
|
|
from django.forms import widgets |
|
24
|
|
|
from django_ace import AceWidget |
|
25
|
|
|
|
|
26
|
|
|
from feedback.models import Feedback |
|
27
|
|
|
|
|
28
|
|
|
class FeedbackForm(forms.ModelForm): |
|
29
|
|
|
class Meta: |
|
30
|
|
|
model = Feedback |
|
31
|
|
|
exclude = [] |
|
32
|
|
|
widgets = { |
|
33
|
|
|
'feedback_data': AceWidget(mode='json', theme='monokai', width='600px', height='300px'), |
|
34
|
|
|
'screenshot_size': widgets.TextInput(attrs=dict(disabled='disabled')), |
|
35
|
|
|
'system_logs_size': widgets.TextInput(attrs=dict(disabled='disabled')), |
|
36
|
|
|
'blackbox_size': widgets.TextInput(attrs=dict(disabled='disabled')), |
|
37
|
|
|
'attached_file_size': widgets.TextInput(attrs=dict(disabled='disabled')), |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
def clean_screenshot_size(self): |
|
41
|
|
|
return self._clean_file_size('screenshot') |
|
42
|
|
|
|
|
43
|
|
|
def clean_blackbox_size(self): |
|
44
|
|
|
return self._clean_file_size('blackbox') |
|
45
|
|
|
|
|
46
|
|
|
def clean_system_logs_size(self): |
|
47
|
|
|
return self._clean_file_size('system_logs') |
|
48
|
|
|
|
|
49
|
|
|
def clean_attached_file_size(self): |
|
50
|
|
|
return self._clean_file_size('attached_file') |
|
51
|
|
|
|
|
52
|
|
|
def _clean_file_size(self, file_field): |
|
53
|
|
|
if file_field not in self.cleaned_data: |
|
54
|
|
|
return 0 |
|
55
|
|
|
_file = self.cleaned_data[file_field] |
|
56
|
|
|
if isinstance(_file, UploadedFile): |
|
57
|
|
|
return _file.size |
|
58
|
|
|
return self.initial.get("%s_size" % file_field, 0) |
|
59
|
|
|
|