Completed
Push — master ( 74046a...4c11f7 )
by Oleksandr
01:30
created

Countries

Complexity

Total Complexity 0

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 0
c 5
b 0
f 1
dl 0
loc 16
ccs 16
cts 16
cp 1
1
# coding: utf-8
2
3 1
import six
4
5 1
from candv import (
6
    Constants, Values, VerboseConstant, VerboseValueConstant,
7
    with_constant_class,
8
)
9
10 1
from .utils import translations
11
12
13 1
_ = translations.ugettext_lazy
14
15
16 1
class Belligerent(VerboseValueConstant):
17
    pass
18
19
20 1
class Belligerents(with_constant_class(Belligerent), Values):
21 1
    none = Belligerent(0, _("none"))
22 1
    red = Belligerent(1, _("red"))
23 1
    blue = Belligerent(2, _("blue"))
24 1
    green = Belligerent(3, _("green"))
25 1
    gold = Belligerent(4, _("gold"))
26 1
    purple = Belligerent(5, _("purple"))
27 1
    aqua = Belligerent(6, _("aqua"))
28 1
    maroon = Belligerent(7, _("maroon"))
29 1
    navy = Belligerent(8, _("navy"))
30 1
    emerald = Belligerent(9, _("emerald"))
31 1
    olive = Belligerent(10, _("olive"))
32 1
    magenta = Belligerent(11, _("magenta"))
33 1
    teal = Belligerent(12, _("teal"))
34 1
    orange = Belligerent(13, _("orange"))
35 1
    turquoise = Belligerent(14, _("turquoise"))
36 1
    brown = Belligerent(15, _("brown"))
37 1
    salad = Belligerent(16, _("salad"))
38
39
40 1
class Country(VerboseConstant):
41
    pass
42
43
44 1
class Countries(with_constant_class(Country), Constants):
45 1
    au = Country(verbose_name=_("Australia"))
46 1
    fi = Country(verbose_name=_("Finland"))
47 1
    fr = Country(verbose_name=_("France"))
48 1
    de = Country(verbose_name=_("Germany"))
49 1
    hu = Country(verbose_name=_("Hungary"))
50 1
    jp = Country(verbose_name=_("Japan"))
51 1
    it = Country(verbose_name=_("Italy"))
52 1
    nl = Country(verbose_name=_("Netherlands"))
53 1
    nz = Country(verbose_name=_("New Zealand"))
54 1
    pl = Country(verbose_name=_("Poland"))
55 1
    ro = Country(verbose_name=_("Romania"))
56 1
    sk = Country(verbose_name=_("Slovakia"))
57 1
    su = Country(verbose_name=_("Soviet Union"))
58 1
    uk = Country(verbose_name=_("United Kingdom"))
59 1
    us = Country(verbose_name=_("United States"))
60
61
62 1
class AirForce(VerboseValueConstant):
63
64 1
    def __init__(self, country, default_flight_prefix, value,
65
                 verbose_name=None, help_text=None):
66 1
        super(AirForce, self).__init__(value,
67
                                       verbose_name=verbose_name,
68
                                       help_text=help_text)
69 1
        self.country = country
70
71 1
        if default_flight_prefix is not None:
72 1
            self.default_flight_prefix = str(default_flight_prefix)
73
        else:
74 1
            self.default_flight_prefix = None
75
76 1
    def merge_into_group(self, group):
77 1
        super(AirForce, self).merge_into_group(group)
78 1
        group.country = self.country
79 1
        group.default_flight_prefix = self.default_flight_prefix
80
81 1
    def to_primitive(self, context=None):
82 1
        primitive = super(AirForce, self).to_primitive(context)
83 1
        country = self.country and self.country.to_primitive(context)
84 1
        primitive.update({
85
            'country': country,
86
            'default_flight_prefix': self.default_flight_prefix,
87
        })
88 1
        return primitive
89
90
91 1
class AirForces(with_constant_class(AirForce), Values):
92 1
    ala = AirForce(
93
        country=Countries.fr,
94
        default_flight_prefix='fr01',
95
        value='fr',
96
        verbose_name=_("ALA"),
97
        help_text=_("Army of the Air"),
98
    )
99 1
    faf = AirForce(
100
        country=Countries.fi,
101
        default_flight_prefix='f01',
102
        value='fi',
103
        verbose_name=_("FAF"),
104
        help_text=_("Finnish Air Force"),
105
    )
106 1
    far = AirForce(
107
        country=Countries.ro,
108
        default_flight_prefix='ro01',
109
        value='ro',
110
        verbose_name=_("FAR"),
111
        help_text=_("Romanian Air Force"),
112
    )
113 1
    haf = AirForce(
114
        country=Countries.hu,
115
        default_flight_prefix='h01',
116
        value='hu',
117
        verbose_name=_("HAF"),
118
        help_text=_("Hungarian Air Force"),
119
    )
120 1
    luftwaffe = AirForce(
121
        country=Countries.de,
122
        default_flight_prefix='g01',
123
        value='de',
124
        verbose_name=_("Luftwaffe"),
125
        help_text=_("German Air Force"),
126
    )
127 1
    ija = AirForce(
128
        country=Countries.jp,
129
        default_flight_prefix='ja01',
130
        value='ja',
131
        verbose_name=_("IJA"),
132
        help_text=_("Imperial Japanese Army"),
133
    )
134 1
    ijn = AirForce(
135
        country=Countries.jp,
136
        default_flight_prefix='IN_NN',
137
        value='in',
138
        verbose_name=_("IJN"),
139
        help_text=_("Imperial Japanese Navy"),
140
    )
141 1
    paf = AirForce(
142
        country=Countries.pl,
143
        default_flight_prefix='pl01',
144
        value='pl',
145
        verbose_name=_("PAF"),
146
        help_text=_("Polish Air Force"),
147
    )
148 1
    rai = AirForce(
149
        country=Countries.it,
150
        default_flight_prefix='i01',
151
        value='it',
152
        verbose_name=_("RAI"),
153
        help_text=_("Regia Aeronautica Italiana"),
154
    )
155 1
    raaf = AirForce(
156
        country=Countries.au,
157
        default_flight_prefix='RA_NN',
158
        value='ra',
159
        verbose_name=_("RAAF"),
160
        help_text=_("Royal Australian Air Force"),
161
    )
162 1
    raf = AirForce(
163
        country=Countries.uk,
164
        default_flight_prefix='gb01',
165
        value='gb',
166
        verbose_name=_("RAF"),
167
        help_text=_("Royal Air Force"),
168
    )
169 1
    rn = AirForce(
170
        country=Countries.uk,
171
        default_flight_prefix='RN_NN',
172
        value='rn',
173
        verbose_name=_("RN"),
174
        help_text=_("Royal Navy"),
175
    )
176 1
    rnlaf = AirForce(
177
        country=Countries.nl,
178
        default_flight_prefix='DU_NN',
179
        value='du',
180
        verbose_name=_("RNLAF"),
181
        help_text=_("Royal Netherlands Air Force"),
182
    )
183 1
    rnzaf = AirForce(
184
        country=Countries.nz,
185
        default_flight_prefix='RZ_NN',
186
        value='rz',
187
        verbose_name=_("RNZAF"),
188
        help_text=_("Royal New Zealand Air Force"),
189
    )
190 1
    saf = AirForce(
191
        country=Countries.sk,
192
        default_flight_prefix='sk01',
193
        value='sk',
194
        verbose_name=_("SAF"),
195
        help_text=_("Slovak Air Force"),
196
    )
197 1
    usaaf = AirForce(
198
        country=Countries.us,
199
        default_flight_prefix='usa01',
200
        value='us',
201
        verbose_name=_("USAAF"),
202
        help_text=_("United States Army Air Forces"),
203
    )
204 1
    usmc = AirForce(
205
        country=Countries.us,
206
        default_flight_prefix='UM_NN',
207
        value='um',
208
        verbose_name=_("USMC"),
209
        help_text=_("United States Marine Corps"),
210
    )
211 1
    usn = AirForce(
212
        country=Countries.us,
213
        default_flight_prefix='UN_NN',
214
        value='un',
215
        verbose_name=_("USN"),
216
        help_text=_("United States Navy"),
217
    )
218 1
    vvs_rkka = AirForce(
219
        country=Countries.su,
220
        default_flight_prefix='r01',
221
        value='ru',
222
        verbose_name=_("VVS RKKA"),
223
        help_text=_("Workers-Peasants Red Army Air Forces"),
224
    )
225 1
    none = AirForce(
226
        country=None,
227
        default_flight_prefix=None,
228
        value='nn',
229
        verbose_name=_("None"),
230
        help_text=_("No Air Force"),
231
    )
232
233 1
    @classmethod
234
    def get_flight_prefixes(cls):
235 1
        result = map(lambda x: x.default_flight_prefix, cls.iterconstants())
236 1
        if six.PY3:
237
            result = list(result)
238 1
        return result
239
240 1
    @classmethod
241
    def get_by_flight_prefix(cls, prefix):
242 1
        for constant in cls.iterconstants():
243 1
            if constant.default_flight_prefix == prefix:
244 1
                return constant
245 1
        raise ValueError(
246
            "Air force with prefix '{0}' is not present in '{1}'"
247
            .format(prefix, cls.__name__)
248
        )
249
250 1
    @classmethod
251
    def filter_by_country(cls, country):
252
        return filter(lambda x: x.country == country, cls.constants())
253