Browse Source

Modified the random em generator for a better rel2type generation

Yann Weber 9 years ago
parent
commit
bb80f3e001
1 changed files with 18 additions and 5 deletions
  1. 18
    5
      EditorialModel/randomem.py

+ 18
- 5
EditorialModel/randomem.py View File

@@ -63,6 +63,7 @@ class RandomEm(object):
63 63
             'ntypesuperiors': 2,    # chances to link with a superior
64 64
             'nofields': 10,         # no fields in a fieldgroup
65 65
             'nfields': 8,           # max number of fields per fieldgroups
66
+            'nr2tfields': 1,        # max number of rel2type fields per fieldgroups
66 67
             'rfields': 5,           # max number of attributes relation fields
67 68
             'optfield': 2,          # chances to be optionnal
68 69
         }
@@ -107,7 +108,7 @@ class RandomEm(object):
107 108
                         emtype.add_superior(possible[nat][i], nat)
108 109
 
109 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 112
         for emfg in ed_mod.components(EmFieldGroup):
112 113
             if random.randint(0, chances['nofields']) != 0:
113 114
                 for _ in range(random.randint(1, chances['nfields'])):
@@ -115,19 +116,31 @@ class RandomEm(object):
115 116
                     fdats = cls._rnd_component_datas()
116 117
                     fdats['fieldtype'] = field_type
117 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 119
                     if random.randint(0, chances['optfield']) == 0:
122 120
                         fdats['optional'] = True
123 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 138
         ft_l = [field_type for field_type in EmField.fieldtypes_list() if field_type != 'rel2type' and field_type  != 'pk']
127 139
         for emrelf in [f for f in ed_mod.components(EmField) if f.fieldtype == 'rel2type']:
128 140
             for _ in range(0, chances['rfields']):
129 141
                 field_type = ft_l[random.randint(0, len(ft_l) - 1)]
130 142
                 fdats = cls._rnd_component_datas()
143
+                fdats['rel_field_id'] = emrelf.uid
131 144
                 fdats['fieldtype'] = field_type
132 145
                 fdats['fieldgroup_id'] = emrelf.fieldgroup_id
133 146
                 if random.randint(0, chances['optfield']) == 0:

Loading…
Cancel
Save