Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2058: IntegrityError when previewing #2060

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jsapp/js/editorMixins/editableForm.es6
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export default assign({
if (this.state.asset) {
surveyJSON = unnullifyTranslations(surveyJSON, this.state.asset.content);
}
let params = {content: surveyJSON};
let params = {source: surveyJSON};

params = koboMatrixParser(params);

Expand Down
4 changes: 2 additions & 2 deletions kpi/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,9 @@ def content(self):

def save(self, *args, **kwargs):
if self.asset is not None:
if self.asset_version is None:
self.asset_version = self.asset.latest_version
if self.source is None:
if self.asset_version is None:
self.asset_version = self.asset.latest_version
self.source = self.asset_version.version_content
if self.owner is None:
self.owner = self.asset.owner
Expand Down
19 changes: 19 additions & 0 deletions kpi/tests/test_api_asset_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ def _create_asset_snapshot_from_asset(self):
def test_create_asset_snapshot_from_asset(self):
self._create_asset_snapshot_from_asset()

def test_create_two_asset_snapshots_from_source_and_asset(self):
'''
Make sure it's possible to preview unsaved changes to an asset multiple
times; see https://github.com/kobotoolbox/kpi/issues/2058
'''
self.client.login(username='someuser', password='someuser')
snapshot_list_url = reverse('assetsnapshot-list')
asset = self.create_asset(
'Take my snapshot!', self.form_source, format='json')
asset_url = reverse('asset-detail', args=(asset.uid,))
data = {'source': self.form_source, 'asset': asset_url}
for _ in range(2):
response = self.client.post(snapshot_list_url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED,
msg=response.data)
xml_resp = self.client.get(response.data['xml'])
self.assertTrue(len(xml_resp.content) > 0)
self.client.logout()

def test_asset_owner_can_access_snapshot(self):
creation_response = self._create_asset_snapshot_from_asset()
snapshot_uid = creation_response.data['uid']
Expand Down