CrashLimitStorageSize   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 6
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
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
import pytz
22
from datetime import datetime
23
24
from django.forms import IntegerField
25
from django.core.validators import MinValueValidator
26
27
from dynamic_preferences.types import IntegerPreference, ChoicePreference
28
from dynamic_preferences.registries import global_preferences_registry
29
from django_select2.forms import Select2Widget
30
31
class PositiveIntegerField(IntegerField):
32
    min_value = 1
33
    default_validators = [MinValueValidator(min_value)]
34
35
    def __init__(self, *args, **kwargs):
36
        defaults = {'min_value': self.min_value}
37
        defaults.update(kwargs)
38
        super(PositiveIntegerField, self).__init__(**defaults)
39
40
41
class PositiveIntegerPreference(IntegerPreference):
42
    field_class = PositiveIntegerField
43
44
@global_preferences_registry.register
45
class CrashLimitStorageDays(PositiveIntegerPreference):
46
    section = 'Crash'
47
    verbose_name = 'Maximum storage time (days) for crashes'
48
    name = "limit_storage_days"
49
    default = 360
50
51
52
@global_preferences_registry.register
53
class CrashLimitStorageSize(PositiveIntegerPreference):
54
    section = 'Crash'
55
    verbose_name = "Maximum crash storage utilization (GB)"
56
    name = "limit_size"
57
    default = 100
58
59
60
@global_preferences_registry.register
61
class CrashLimitDuplicateNumber(PositiveIntegerPreference):
62
    section = 'Crash'
63
    verbose_name = 'Maximum number duplicate crashes'
64
    name = "duplicate_number"
65
    default = 10
66
67
68
@global_preferences_registry.register
69
class OmahaLimitSize(PositiveIntegerPreference):
70
    section = 'Version'
71
    verbose_name = "Alert when Omaha version storage exceeds (GB) "
72
    name = "limit_size"
73
    default = 100
74
75
76
@global_preferences_registry.register
77
class SparkleLimitSize(PositiveIntegerPreference):
78
    section = 'SparkleVersion'
79
    verbose_name = "Alert when Sparkle version storage exceeds (GB) "
80
    name = "limit_size"
81
    default = 100
82
83
84
@global_preferences_registry.register
85
class FeedbackLimitStorageDays(PositiveIntegerPreference):
86
    section = 'Feedback'
87
    verbose_name = 'Maximum storage time (days) for feedbacks'
88
    name = "limit_storage_days"
89
    default = 360
90
91
92
@global_preferences_registry.register
93
class FeedbackLimitSize(PositiveIntegerPreference):
94
    section = 'Feedback'
95
    verbose_name = "Maximum feedback storage utilization (GB)"
96
    name = "limit_size"
97
    default = 100
98
99
100
@global_preferences_registry.register
101
class SymbolsLimitSize(PositiveIntegerPreference):
102
    section = 'Symbols'
103
    verbose_name = "Alert when symbol file storage exceeds (GB) "
104
    name = "limit_size"
105
    default = 100
106
107
@global_preferences_registry.register
108
class TimeZone(ChoicePreference):
109
    choices = [(tz, ' '.join([tz, datetime.now(pytz.timezone(tz)).strftime('%z')]))
110
               for tz in pytz.common_timezones]
111
    widget = Select2Widget
112
    section = 'Timezone'
113
    verbose_name = "Choose your timezone"
114
    name = "timezone"
115
    default = "UTC"
116
117
118
global_preferences = global_preferences_registry
119
global_preferences_manager = global_preferences.manager()
120