|
|
|
|
63
|
'ntypesuperiors': 2, # chances to link with a superior
|
63
|
'ntypesuperiors': 2, # chances to link with a superior
|
64
|
'nofields': 10, # no fields in a fieldgroup
|
64
|
'nofields': 10, # no fields in a fieldgroup
|
65
|
'nfields': 8, # max number of fields per fieldgroups
|
65
|
'nfields': 8, # max number of fields per fieldgroups
|
|
|
66
|
+ 'nr2tfields': 1, # max number of rel2type fields per fieldgroups
|
66
|
'rfields': 5, # max number of attributes relation fields
|
67
|
'rfields': 5, # max number of attributes relation fields
|
67
|
'optfield': 2, # chances to be optionnal
|
68
|
'optfield': 2, # chances to be optionnal
|
68
|
}
|
69
|
}
|
|
|
|
|
107
|
emtype.add_superior(possible[nat][i], nat)
|
108
|
emtype.add_superior(possible[nat][i], nat)
|
108
|
|
109
|
|
109
|
#fields creation
|
110
|
#fields creation
|
110
|
- ft_l = [ ftname for ftname in EmField.fieldtypes_list() if ftname != 'pk' ]
|
|
|
|
|
111
|
+ ft_l = [ ftname for ftname in EmField.fieldtypes_list() if ftname != 'pk' and ftname != 'rel2type']
|
111
|
for emfg in ed_mod.components(EmFieldGroup):
|
112
|
for emfg in ed_mod.components(EmFieldGroup):
|
112
|
if random.randint(0, chances['nofields']) != 0:
|
113
|
if random.randint(0, chances['nofields']) != 0:
|
113
|
for _ in range(random.randint(1, chances['nfields'])):
|
114
|
for _ in range(random.randint(1, chances['nfields'])):
|
|
|
|
|
115
|
fdats = cls._rnd_component_datas()
|
116
|
fdats = cls._rnd_component_datas()
|
116
|
fdats['fieldtype'] = field_type
|
117
|
fdats['fieldtype'] = field_type
|
117
|
fdats['fieldgroup_id'] = emfg.uid
|
118
|
fdats['fieldgroup_id'] = emfg.uid
|
118
|
- if field_type == 'rel2type':
|
|
|
119
|
- emtypes = ed_mod.components(EmType)
|
|
|
120
|
- fdats['rel_to_type_id'] = emtypes[random.randint(0, len(emtypes) - 1)].uid
|
|
|
121
|
if random.randint(0, chances['optfield']) == 0:
|
119
|
if random.randint(0, chances['optfield']) == 0:
|
122
|
fdats['optional'] = True
|
120
|
fdats['optional'] = True
|
123
|
ed_mod.create_component('EmField', fdats)
|
121
|
ed_mod.create_component('EmField', fdats)
|
|
|
122
|
+
|
|
|
123
|
+ #rel2type creation (in case none where created before
|
|
|
124
|
+ for emfg in ed_mod.components(EmFieldGroup):
|
|
|
125
|
+ for _ in range(random.randint(0, chances['nr2tfields'])):
|
|
|
126
|
+ field_type = 'rel2type'
|
|
|
127
|
+ fdats = cls._rnd_component_datas()
|
|
|
128
|
+ fdats['fieldtype'] = field_type
|
|
|
129
|
+ fdats['fieldgroup_id'] = emfg.uid
|
|
|
130
|
+ emtypes = ed_mod.components(EmType)
|
|
|
131
|
+ fdats['rel_to_type_id'] = emtypes[random.randint(0, len(emtypes) - 1)].uid
|
|
|
132
|
+ if random.randint(0, chances['optfield']) == 0:
|
|
|
133
|
+ fdats['optional'] = True
|
|
|
134
|
+ ed_mod.create_component('EmField', fdats)
|
|
|
135
|
+
|
124
|
|
136
|
|
125
|
- #relationnal fiels creation
|
|
|
|
|
137
|
+ #relationnal fields creation
|
126
|
ft_l = [field_type for field_type in EmField.fieldtypes_list() if field_type != 'rel2type' and field_type != 'pk']
|
138
|
ft_l = [field_type for field_type in EmField.fieldtypes_list() if field_type != 'rel2type' and field_type != 'pk']
|
127
|
for emrelf in [f for f in ed_mod.components(EmField) if f.fieldtype == 'rel2type']:
|
139
|
for emrelf in [f for f in ed_mod.components(EmField) if f.fieldtype == 'rel2type']:
|
128
|
for _ in range(0, chances['rfields']):
|
140
|
for _ in range(0, chances['rfields']):
|
129
|
field_type = ft_l[random.randint(0, len(ft_l) - 1)]
|
141
|
field_type = ft_l[random.randint(0, len(ft_l) - 1)]
|
130
|
fdats = cls._rnd_component_datas()
|
142
|
fdats = cls._rnd_component_datas()
|
|
|
143
|
+ fdats['rel_field_id'] = emrelf.uid
|
131
|
fdats['fieldtype'] = field_type
|
144
|
fdats['fieldtype'] = field_type
|
132
|
fdats['fieldgroup_id'] = emrelf.fieldgroup_id
|
145
|
fdats['fieldgroup_id'] = emrelf.fieldgroup_id
|
133
|
if random.randint(0, chances['optfield']) == 0:
|
146
|
if random.randint(0, chances['optfield']) == 0:
|