1
|
|
|
# coding: utf-8 |
2
|
|
|
|
3
|
1 |
|
import zope.interface |
4
|
|
|
|
5
|
1 |
|
from schematics.models import Model |
6
|
1 |
|
from schematics.types import BooleanType |
7
|
|
|
|
8
|
1 |
|
from .interfaces import INISerializable, DefaultProvider |
9
|
1 |
|
from .helpers import field_from_ini, field_to_ini |
10
|
|
|
|
11
|
|
|
|
12
|
1 |
View Code Duplication |
@zope.interface.implementer(INISerializable) |
|
|
|
|
13
|
1 |
|
@zope.interface.implementer(DefaultProvider) |
14
|
1 |
|
class Morse(Model): |
15
|
1 |
|
allow_morse_as_text = BooleanType( |
16
|
|
|
default=True, |
17
|
|
|
required=True, |
18
|
|
|
) |
19
|
1 |
|
show_morse_as_text = BooleanType( |
20
|
|
|
default=False, |
21
|
|
|
required=True, |
22
|
|
|
) |
23
|
1 |
|
block_morse_chat = BooleanType( |
24
|
|
|
default=False, |
25
|
|
|
required=True, |
26
|
|
|
) |
27
|
|
|
|
28
|
1 |
|
@classmethod |
29
|
|
|
def from_ini(cls, ini): |
30
|
|
|
return cls({ |
31
|
|
|
'allow_morse_as_text': field_from_ini( |
32
|
|
|
cls.allow_morse_as_text, ini, |
33
|
|
|
'NET', 'allowMorseAsText', |
34
|
|
|
), |
35
|
|
|
'show_morse_as_text': field_from_ini( |
36
|
|
|
cls.show_morse_as_text, ini, |
37
|
|
|
'game', 'ShowMorseAsText', |
38
|
|
|
), |
39
|
|
|
'block_morse_chat': field_from_ini( |
40
|
|
|
cls.block_morse_chat, ini, |
41
|
|
|
'game', 'BlockMorseChat', |
42
|
|
|
), |
43
|
|
|
}) |
44
|
|
|
|
45
|
1 |
|
def to_ini(self, ini): |
46
|
|
|
field_to_ini(self.allow_morse_as_text, ini, 'NET', 'allowMorseAsText') |
47
|
|
|
field_to_ini(self.show_morse_as_text, ini, 'game', 'ShowMorseAsText') |
48
|
|
|
field_to_ini(self.block_morse_chat, ini, 'game', 'BlockMorseChat') |
49
|
|
|
|
50
|
|
|
@classmethod |
51
|
|
|
def default(cls): |
52
|
|
|
return cls({ |
53
|
|
|
field_name: field.default |
54
|
|
|
for field_name, field in cls.fields.items() |
55
|
|
|
}) |
56
|
|
|
|