112 _generate_schema_pot(w, vreg, schema, libconfig=libconfig, cube=cube) |
112 _generate_schema_pot(w, vreg, schema, libconfig=libconfig, cube=cube) |
113 |
113 |
114 |
114 |
115 def _generate_schema_pot(w, vreg, schema, libconfig=None, cube=None): |
115 def _generate_schema_pot(w, vreg, schema, libconfig=None, cube=None): |
116 from cubicweb.common.i18n import add_msg |
116 from cubicweb.common.i18n import add_msg |
|
117 from cubicweb.web import uicfg |
117 w('# schema pot file, generated on %s\n' % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) |
118 w('# schema pot file, generated on %s\n' % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) |
118 w('# \n') |
119 w('# \n') |
119 w('# singular and plural forms for each entity type\n') |
120 w('# singular and plural forms for each entity type\n') |
120 w('\n') |
121 w('\n') |
|
122 vregdone = set() |
121 if libconfig is not None: |
123 if libconfig is not None: |
|
124 from cubicweb.cwvreg import CubicWebVRegistry, clear_rtag_objects |
122 libschema = libconfig.load_schema(remove_unused_rtypes=False) |
125 libschema = libconfig.load_schema(remove_unused_rtypes=False) |
123 entities = [e for e in schema.entities() if not e in libschema] |
126 rinlined = deepcopy(uicfg.autoform_is_inlined) |
|
127 appearsin_addmenu = deepcopy(uicfg.actionbox_appearsin_addmenu) |
|
128 clear_rtag_objects() |
|
129 cleanup_sys_modules(libconfig) |
|
130 print 'hoppp', libconfig.cubes() |
|
131 libvreg = CubicWebVRegistry(libconfig) |
|
132 libvreg.set_schema(libschema) # trigger objects registration |
|
133 librinlined = uicfg.autoform_is_inlined |
|
134 libappearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
|
135 # prefill vregdone set |
|
136 list(_iter_vreg_objids(libvreg, vregdone)) |
124 else: |
137 else: |
125 entities = schema.entities() |
138 libschema = {} |
126 rinlined = uicfg.autoform_is_inlined |
139 rinlined = uicfg.autoform_is_inlined |
|
140 appearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
127 done = set() |
141 done = set() |
128 for eschema in sorted(entities): |
142 for eschema in sorted(schema.entities()): |
129 etype = eschema.type |
143 etype = eschema.type |
130 add_msg(w, etype) |
144 if etype not in libschema: |
131 add_msg(w, '%s_plural' % etype) |
145 add_msg(w, etype) |
132 if not eschema.is_final(): |
146 add_msg(w, '%s_plural' % etype) |
133 add_msg(w, 'This %s' % etype) |
147 if not eschema.is_final(): |
134 add_msg(w, 'New %s' % etype) |
148 add_msg(w, 'This %s' % etype) |
135 for rschema, targetschemas, role in eschema.relation_definitions(True): |
149 add_msg(w, 'New %s' % etype) |
136 targetschemas = [tschema for tschema in targetschemas |
150 if eschema.description and not eschema.description in done: |
137 if rinlined.etype_get(eschema, rschema, role, tschema)] |
151 done.add(eschema.description) |
138 for tschema in targetschemas: |
152 add_msg(w, eschema.description) |
|
153 if eschema.is_final(): |
|
154 continue |
|
155 for rschema, targetschemas, role in eschema.relation_definitions(True): |
|
156 for tschema in targetschemas: |
|
157 if rinlined.etype_get(eschema, rschema, role, tschema) and \ |
|
158 (libconfig is None or not |
|
159 librinlined.etype_get(eschema, rschema, role, tschema)): |
139 add_msg(w, 'add a %s' % tschema, |
160 add_msg(w, 'add a %s' % tschema, |
140 'inlined:%s.%s.%s' % (etype, rschema, role)) |
161 'inlined:%s.%s.%s' % (etype, rschema, role)) |
141 add_msg(w, 'remove this %s' % tschema, |
162 add_msg(w, 'remove this %s' % tschema, |
142 'inlined:%s:%s:%s' % (etype, rschema, role)) |
163 'inlined:%s:%s:%s' % (etype, rschema, role)) |
143 if eschema.description and not eschema.description in done: |
164 if appearsin_addmenu.etype_get(eschema, rschema, role, tschema) and \ |
144 done.add(eschema.description) |
165 (libconfig is None or not |
145 add_msg(w, eschema.description) |
166 libappearsin_addmenu.etype_get(eschema, rschema, role, tschema)): |
|
167 if role == 'subject': |
|
168 label = 'add %s %s %s %s' % (eschema, rschema, |
|
169 tschema, role) |
|
170 label2 = "creating %s (%s %%(linkto)s %s %s)" % ( |
|
171 tschema, eschema, rschema, tschema) |
|
172 else: |
|
173 label = 'add %s %s %s %s' % (tschema, rschema, |
|
174 eschema, role) |
|
175 label2 = "creating %s (%s %s %s %%(linkto)s)" % ( |
|
176 tschema, tschema, rschema, eschema) |
|
177 add_msg(w, label) |
|
178 add_msg(w, label2) |
146 w('# subject and object forms for each relation type\n') |
179 w('# subject and object forms for each relation type\n') |
147 w('# (no object form for final relation types)\n') |
180 w('# (no object form for final or symetric relation types)\n') |
148 w('\n') |
181 w('\n') |
149 if libconfig is not None: |
182 for rschema in sorted(schema.relations()): |
150 relations = [r for r in schema.relations() if not r in libschema] |
|
151 else: |
|
152 relations = schema.relations() |
|
153 for rschema in sorted(set(relations)): |
|
154 rtype = rschema.type |
183 rtype = rschema.type |
155 # bw compat, necessary until all translation of relation are done properly... |
184 if rtype not in libschema: |
156 add_msg(w, rtype) |
185 # bw compat, necessary until all translation of relation are done properly... |
|
186 add_msg(w, rtype) |
|
187 if rschema.description and rschema.description not in done: |
|
188 done.add(rschema.description) |
|
189 add_msg(w, rschema.description) |
|
190 done.add(rtype) |
|
191 librschema = None |
|
192 else: |
|
193 librschema = libschema.rschema(rtype) |
157 # add context information only for non-metadata rtypes |
194 # add context information only for non-metadata rtypes |
158 if rschema not in META_RTYPES: |
195 if rschema not in META_RTYPES: |
|
196 libsubjects = librschema and librschema.subjects() or () |
159 for subjschema in rschema.subjects(): |
197 for subjschema in rschema.subjects(): |
160 add_msg(w, rtype, subjschema.type) |
198 if not subjschema in libsubjects: |
161 done.add(rtype) |
199 add_msg(w, rtype, subjschema.type) |
162 if not (schema.rschema(rtype).is_final() or rschema.symetric): |
200 if not (schema.rschema(rtype).is_final() or rschema.symetric): |
163 for objschema in rschema.objects(): |
201 if rschema not in META_RTYPES: |
164 add_msg(w, '%s_object' % rtype, objschema.type) |
202 libobjects = librschema and librschema.objects() or () |
165 # bw compat, necessary until all translation of relation are done properly... |
203 for objschema in rschema.objects(): |
166 add_msg(w, '%s_object' % rtype) |
204 if not objschema in libobjects: |
167 if rschema.description and rschema.description not in done: |
205 add_msg(w, '%s_object' % rtype, objschema.type) |
168 done.add(rschema.description) |
206 if rtype not in libschema: |
169 add_msg(w, rschema.description) |
207 # bw compat, necessary until all translation of relation are done properly... |
170 w('# add related box generated message\n') |
208 add_msg(w, '%s_object' % rtype) |
171 w('\n') |
209 for objid in _iter_vreg_objids(vreg, vregdone): |
172 appearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
|
173 for eschema in schema.entities(): |
|
174 if eschema.is_final(): |
|
175 continue |
|
176 for role, rschemas in (('subject', eschema.subject_relations()), |
|
177 ('object', eschema.object_relations())): |
|
178 for rschema in rschemas: |
|
179 if rschema.is_final(): |
|
180 continue |
|
181 if libconfig is not None: |
|
182 librschema = libschema.get(rschema) |
|
183 for teschema in rschema.targets(eschema, role): |
|
184 if libconfig is not None and librschema is not None: |
|
185 if role == 'subject': |
|
186 subjtype, objtype = eschema, teschema |
|
187 else: |
|
188 subjtype, objtype = teschema, eschema |
|
189 if librschema.has_rdef(subjtype, objtype): |
|
190 continue |
|
191 if appearsin_addmenu.etype_get(eschema, rschema, role, |
|
192 teschema): |
|
193 if role == 'subject': |
|
194 label = 'add %s %s %s %s' % (eschema, rschema, |
|
195 teschema, role) |
|
196 label2 = "creating %s (%s %%(linkto)s %s %s)" % ( |
|
197 teschema, eschema, rschema, teschema) |
|
198 else: |
|
199 label = 'add %s %s %s %s' % (teschema, rschema, |
|
200 eschema, role) |
|
201 label2 = "creating %s (%s %s %s %%(linkto)s)" % ( |
|
202 teschema, teschema, rschema, eschema) |
|
203 add_msg(w, label) |
|
204 add_msg(w, label2) |
|
205 #cube = (cube and 'cubes.%s.' % cube or 'cubicweb.') |
|
206 done = set() |
|
207 if libconfig is not None: |
|
208 from cubicweb.cwvreg import CubicWebVRegistry |
|
209 libvreg = CubicWebVRegistry(libconfig) |
|
210 libvreg.set_schema(libschema) # trigger objects registration |
|
211 # prefill done set |
|
212 list(_iter_vreg_objids(libvreg, done)) |
|
213 for objid in _iter_vreg_objids(vreg, done): |
|
214 add_msg(w, '%s_description' % objid) |
210 add_msg(w, '%s_description' % objid) |
215 add_msg(w, objid) |
211 add_msg(w, objid) |
216 |
212 |
217 def _iter_vreg_objids(vreg, done, prefix=None): |
213 def _iter_vreg_objids(vreg, done, prefix=None): |
218 for reg, objdict in vreg.items(): |
214 for reg, objdict in vreg.items(): |