0001-cards-forms-reuse-custom-views-on-import-65682.patch
tests/api/test_export_import.py | ||
---|---|---|
227 | 227 |
formdef.disabled = False |
228 | 228 |
formdef.store() |
229 | 229 | |
230 |
custom_view = pub.custom_view_class() |
|
231 |
custom_view.title = 'shared formdef custom view' |
|
232 |
custom_view.formdef = formdef |
|
233 |
custom_view.columns = {'list': [{'id': '1'}]} |
|
234 |
custom_view.filters = {} |
|
235 |
custom_view.visibility = 'any' |
|
236 |
custom_view.store() |
|
237 | ||
230 | 238 |
category = Category(name='Test') |
231 | 239 |
category.store() |
232 | 240 | |
... | ... | |
258 | 266 |
MailTemplateCategory.wipe() |
259 | 267 |
NamedDataSource.wipe() |
260 | 268 |
DataSourceCategory.wipe() |
269 |
pub.custom_view_class.wipe() |
|
261 | 270 | |
262 | 271 |
resp = get_app(pub).put(sign_uri('/api/export-import/bundle-import/'), bundle) |
263 | 272 |
afterjob_url = resp.json['url'] |
... | ... | |
273 | 282 |
assert NamedDataSource.count() == 1 |
274 | 283 |
assert DataSourceCategory.count() == 1 |
275 | 284 |
assert FormDef.select()[0].fields[0].type == 'block:test' |
285 |
assert pub.custom_view_class().count() == 1 |
|
276 | 286 | |
277 | 287 |
# run new import to check it doesn't duplicate objects |
278 | 288 |
resp = get_app(pub).put(sign_uri('/api/export-import/bundle-import/'), bundle) |
... | ... | |
288 | 298 |
assert MailTemplateCategory.count() == 1 |
289 | 299 |
assert NamedDataSource.count() == 1 |
290 | 300 |
assert DataSourceCategory.count() == 1 |
301 |
assert pub.custom_view_class().count() == 1 |
|
291 | 302 | |
292 | 303 |
# change immutable attribute and check it's not reset |
293 | 304 |
formdef = FormDef.select()[0] |
wcs/formdef.py | ||
---|---|---|
564 | 564 | |
565 | 565 |
def store_related_custom_views(self): |
566 | 566 |
for view in getattr(self, '_custom_views', []): |
567 |
if not view.id: |
|
568 |
existing_views = get_publisher().custom_view_class.select( |
|
569 |
[ |
|
570 |
Equal('formdef_type', self.xml_root_node), |
|
571 |
Equal('formdef_id', str(self.id)), |
|
572 |
Equal('visibility', view.visibility), |
|
573 |
Equal('slug', view.slug), |
|
574 |
] |
|
575 |
) |
|
576 |
if existing_views: |
|
577 |
view.id = existing_views[0].id |
|
567 | 578 |
view.formdef = self |
568 | 579 |
view.store() |
569 | 580 | |
570 |
- |