From d32f65e29e735ba1e2010bf7f508af70fbc253f5 Mon Sep 17 00:00:00 2001 From: Daniel Roberts Date: Fri, 4 Apr 2014 16:57:48 -0400 Subject: [PATCH 1/2] use jsonobject-couchdbkit --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 686b7b7..9dc83e6 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ author_email='dev@dimagi.com', url='http://www.dimagi.com/', install_requires=[ - "couchdbkit", + "jsonobject-couchdbkit", "couchexport", "dimagi-utils>=1.0.11", "django", From 1ea3482f64298d6e4b35d1095a702575213c9aff Mon Sep 17 00:00:00 2001 From: Daniel Roberts Date: Fri, 4 Apr 2014 16:58:23 -0400 Subject: [PATCH 2/2] make all form properties explicit --- couchforms/models.py | 24 +++++++++++++++---- couchforms/tests/data/cloudant-template.json | 13 ++++++++-- couchforms/tests/data/decimalmeta.json | 13 ++++++++-- couchforms/tests/data/duplicate.json | 13 ++++++++-- couchforms/tests/data/edit.json | 13 ++++++++-- couchforms/tests/data/meta.json | 13 ++++++++-- couchforms/tests/data/meta_bad_username.json | 13 ++++++++-- .../tests/data/meta_dict_appversion.json | 13 ++++++++-- couchforms/tests/data/namespaces.json | 13 ++++++++-- couchforms/tests/data/unicode.json | 13 ++++++++-- couchforms/util.py | 22 ++++++++--------- 11 files changed, 129 insertions(+), 34 deletions(-) diff --git a/couchforms/models.py b/couchforms/models.py index 852fa4e..824f6c5 100644 --- a/couchforms/models.py +++ b/couchforms/models.py @@ -1,7 +1,11 @@ from __future__ import absolute_import -import datetime, hashlib, logging, time +import datetime +import hashlib +import logging +import time from copy import copy +from jsonobject.base import DefaultProperty from lxml import etree from xml.etree import ElementTree @@ -16,7 +20,6 @@ from dimagi.utils.couch.safe_index import safe_index from dimagi.utils.couch.database import get_safe_read_kwargs, SafeSaveDocument from dimagi.utils.mixins import UnicodeMixIn -from dimagi.utils.couch.database import get_db, iter_docs from couchforms.signals import xform_archived, xform_unarchived from couchforms.const import ATTACHMENT_NAME @@ -92,11 +95,24 @@ class XFormOperation(DocumentSchema): class XFormInstance(SafeSaveDocument, UnicodeMixIn, ComputedDocumentMixin, CouchDocLockableMixIn): """An XForms instance.""" + domain = StringProperty() + app_id = StringProperty() xmlns = StringProperty() + form = DictProperty() received_on = DateTimeProperty() - partial_submission = BooleanProperty(default=False) # Used to tag forms that were forcefully submitted without a touchforms session completing normally + # Used to tag forms that were forcefully submitted + # without a touchforms session completing normally + partial_submission = BooleanProperty(default=False) history = SchemaListProperty(XFormOperation) - form = DictProperty() + auth_context = DictProperty() + submit_ip = StringProperty() + path = StringProperty() + openrosa_headers = DictProperty() + last_sync_token = StringProperty() + # almost always a datetime, but if it's not parseable it'll be a string + date_header = DefaultProperty() + build_id = StringProperty() + export_tag = DefaultProperty(name='#export_tag') @classmethod def get(cls, docid, rev=None, db=None, dynamic_properties=True): diff --git a/couchforms/tests/data/cloudant-template.json b/couchforms/tests/data/cloudant-template.json index a50ac32..4d0bf69 100644 --- a/couchforms/tests/data/cloudant-template.json +++ b/couchforms/tests/data/cloudant-template.json @@ -1,5 +1,4 @@ { - "#export_tag": "xmlns", "_attachments": { "form.xml": { "content_type": "text/xml", @@ -102,5 +101,15 @@ "initial_processing_complete": false, "partial_submission": false, "received_on": "2013-09-21T03:52:24Z", - "xmlns": "http://openrosa.org/formdesigner/266AD1A0-9EAE-483E-B4B2-4E85D6CA8D4B" + "xmlns": "http://openrosa.org/formdesigner/266AD1A0-9EAE-483E-B4B2-4E85D6CA8D4B", + "#export_tag": null, + "app_id": null, + "auth_context": {}, + "build_id": null, + "date_header": null, + "domain": null, + "last_sync_token": null, + "openrosa_headers": {}, + "path": null, + "submit_ip": null } diff --git a/couchforms/tests/data/decimalmeta.json b/couchforms/tests/data/decimalmeta.json index b36f337..ff0bc21 100644 --- a/couchforms/tests/data/decimalmeta.json +++ b/couchforms/tests/data/decimalmeta.json @@ -1,5 +1,4 @@ { - "#export_tag": "xmlns", "_attachments": { "form.xml": { "content_type": "text/xml", @@ -66,5 +65,15 @@ "initial_processing_complete": false, "partial_submission": false, "received_on": "2013-09-21T04:06:18Z", - "xmlns": "http://openrosa.org/app/general" + "xmlns": "http://openrosa.org/app/general", + "#export_tag": null, + "app_id": null, + "auth_context": {}, + "build_id": null, + "date_header": null, + "domain": null, + "last_sync_token": null, + "openrosa_headers": {}, + "path": null, + "submit_ip": null } diff --git a/couchforms/tests/data/duplicate.json b/couchforms/tests/data/duplicate.json index ffc927d..2cca04e 100644 --- a/couchforms/tests/data/duplicate.json +++ b/couchforms/tests/data/duplicate.json @@ -1,5 +1,4 @@ { - "#export_tag": "xmlns", "_attachments": { "form.xml": { "content_type": "text/xml", @@ -66,5 +65,15 @@ "initial_processing_complete": false, "partial_submission": false, "received_on": "2013-09-21T04:13:14Z", - "xmlns": "http://openrosa.org/app/general" + "xmlns": "http://openrosa.org/app/general", + "#export_tag": null, + "app_id": null, + "auth_context": {}, + "build_id": null, + "date_header": null, + "domain": null, + "last_sync_token": null, + "openrosa_headers": {}, + "path": null, + "submit_ip": null } diff --git a/couchforms/tests/data/edit.json b/couchforms/tests/data/edit.json index aac08fb..9b66552 100644 --- a/couchforms/tests/data/edit.json +++ b/couchforms/tests/data/edit.json @@ -1,5 +1,4 @@ { - "#export_tag": "xmlns", "_attachments": { "form.xml": { "content_type": "text/xml", @@ -66,5 +65,15 @@ "initial_processing_complete": false, "partial_submission": false, "received_on": "2013-09-21T04:14:10Z", - "xmlns": "http://openrosa.org/app/general" + "xmlns": "http://openrosa.org/app/general", + "#export_tag": null, + "app_id": null, + "auth_context": {}, + "build_id": null, + "date_header": null, + "domain": null, + "last_sync_token": null, + "openrosa_headers": {}, + "path": null, + "submit_ip": null } diff --git a/couchforms/tests/data/meta.json b/couchforms/tests/data/meta.json index 2a39c01..003ae9b 100644 --- a/couchforms/tests/data/meta.json +++ b/couchforms/tests/data/meta.json @@ -1,5 +1,4 @@ { - "#export_tag": "xmlns", "_attachments": { "form.xml": { "content_type": "text/xml", @@ -66,5 +65,15 @@ "initial_processing_complete": false, "partial_submission": false, "received_on": "2013-09-21T04:14:50Z", - "xmlns": "http://openrosa.org/app/general" + "xmlns": "http://openrosa.org/app/general", + "#export_tag": null, + "app_id": null, + "auth_context": {}, + "build_id": null, + "date_header": null, + "domain": null, + "last_sync_token": null, + "openrosa_headers": {}, + "path": null, + "submit_ip": null } diff --git a/couchforms/tests/data/meta_bad_username.json b/couchforms/tests/data/meta_bad_username.json index 3dc8e5c..e115921 100644 --- a/couchforms/tests/data/meta_bad_username.json +++ b/couchforms/tests/data/meta_bad_username.json @@ -1,5 +1,4 @@ { - "#export_tag": "xmlns", "_attachments": { "form.xml": { "content_type": "text/xml", @@ -56,5 +55,15 @@ "initial_processing_complete": false, "partial_submission": false, "received_on": "2013-09-21T04:16:59Z", - "xmlns": "http://openrosa.org/formdesigner/badmetauser" + "xmlns": "http://openrosa.org/formdesigner/badmetauser", + "#export_tag": null, + "app_id": null, + "auth_context": {}, + "build_id": null, + "date_header": null, + "domain": null, + "last_sync_token": null, + "openrosa_headers": {}, + "path": null, + "submit_ip": null } diff --git a/couchforms/tests/data/meta_dict_appversion.json b/couchforms/tests/data/meta_dict_appversion.json index 9722354..db0d655 100644 --- a/couchforms/tests/data/meta_dict_appversion.json +++ b/couchforms/tests/data/meta_dict_appversion.json @@ -1,5 +1,4 @@ { - "#export_tag": "xmlns", "_attachments": { "form.xml": { "content_type": "text/xml", @@ -56,5 +55,15 @@ "initial_processing_complete": false, "partial_submission": false, "received_on": "2013-09-21T04:18:17Z", - "xmlns": "http://openrosa.org/formdesigner/badmetauser" + "xmlns": "http://openrosa.org/formdesigner/badmetauser", + "#export_tag": null, + "app_id": null, + "auth_context": {}, + "build_id": null, + "date_header": null, + "domain": null, + "last_sync_token": null, + "openrosa_headers": {}, + "path": null, + "submit_ip": null } diff --git a/couchforms/tests/data/namespaces.json b/couchforms/tests/data/namespaces.json index 8e49218..7e15535 100644 --- a/couchforms/tests/data/namespaces.json +++ b/couchforms/tests/data/namespaces.json @@ -1,5 +1,4 @@ { - "#export_tag": "xmlns", "_attachments": { "form.xml": { "content_type": "text/xml", @@ -43,5 +42,15 @@ "initial_processing_complete": false, "partial_submission": false, "received_on": "2013-09-21T04:19:11Z", - "xmlns": "http://commcarehq.org/test/ns" + "xmlns": "http://commcarehq.org/test/ns", + "#export_tag": null, + "app_id": null, + "auth_context": {}, + "build_id": null, + "date_header": null, + "domain": null, + "last_sync_token": null, + "openrosa_headers": {}, + "path": null, + "submit_ip": null } diff --git a/couchforms/tests/data/unicode.json b/couchforms/tests/data/unicode.json index 7140bd1..1354316 100644 --- a/couchforms/tests/data/unicode.json +++ b/couchforms/tests/data/unicode.json @@ -1,5 +1,4 @@ { - "#export_tag": "xmlns", "_attachments": { "form.xml": { "content_type": "text/xml", @@ -23,5 +22,15 @@ "initial_processing_complete": false, "partial_submission": false, "received_on": "2014-01-06T21:30:43Z", - "xmlns": "http://openrosa.org/app/unicode" + "xmlns": "http://openrosa.org/app/unicode", + "#export_tag": null, + "app_id": null, + "auth_context": {}, + "build_id": null, + "date_header": null, + "domain": null, + "last_sync_token": null, + "openrosa_headers": {}, + "path": null, + "submit_ip": null } diff --git a/couchforms/util.py b/couchforms/util.py index c2b4caf..e53a323 100644 --- a/couchforms/util.py +++ b/couchforms/util.py @@ -127,7 +127,6 @@ def create_xform_from_xml(xml_string, _id=None, process=None): form=json_form, xmlns=json_form.get('@xmlns'), received_on=datetime.datetime.utcnow(), - **{'#export_tag': 'xmlns'} ) if _id: kwargs['_id'] = _id @@ -383,24 +382,23 @@ def __init__(self, instance=None, attachments=None, auth_context=None, def _attach_shared_props(self, doc): # attaches shared properties of the request to the document. # used on forms and errors - doc['auth_context'] = self.auth_context.to_json() - doc['submit_ip'] = self.submit_ip - doc['path'] = self.path + doc.auth_context = self.auth_context.to_json() + doc.submit_ip = self.submit_ip + doc.path = self.path - doc['openrosa_headers'] = self.openrosa_headers - - doc['last_sync_token'] = self.last_sync_token + doc.openrosa_headers = self.openrosa_headers + doc.last_sync_token = self.last_sync_token if self.received_on: doc.received_on = self.received_on if self.date_header: - doc['date_header'] = self.date_header + doc.date_header = self.date_header - doc['domain'] = self.domain - doc['app_id'] = self.app_id - doc['build_id'] = self.build_id - doc['#export_tag'] = ["domain", "xmlns"] + doc.domain = self.domain + doc.app_id = self.app_id + doc.build_id = self.build_id + doc.export_tag = ["domain", "xmlns"] return doc