Skip to content

Commit

Permalink
make all form properties explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyroberts committed Apr 4, 2014
1 parent 9e41593 commit 0e0e260
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 34 deletions.
24 changes: 20 additions & 4 deletions couchforms/models.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 11 additions & 2 deletions couchforms/tests/data/cloudant-template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"#export_tag": "xmlns",
"_attachments": {
"form.xml": {
"content_type": "text/xml",
Expand Down Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions couchforms/tests/data/decimalmeta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"#export_tag": "xmlns",
"_attachments": {
"form.xml": {
"content_type": "text/xml",
Expand Down Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions couchforms/tests/data/duplicate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"#export_tag": "xmlns",
"_attachments": {
"form.xml": {
"content_type": "text/xml",
Expand Down Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions couchforms/tests/data/edit.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"#export_tag": "xmlns",
"_attachments": {
"form.xml": {
"content_type": "text/xml",
Expand Down Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions couchforms/tests/data/meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"#export_tag": "xmlns",
"_attachments": {
"form.xml": {
"content_type": "text/xml",
Expand Down Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions couchforms/tests/data/meta_bad_username.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"#export_tag": "xmlns",
"_attachments": {
"form.xml": {
"content_type": "text/xml",
Expand Down Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions couchforms/tests/data/meta_dict_appversion.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"#export_tag": "xmlns",
"_attachments": {
"form.xml": {
"content_type": "text/xml",
Expand Down Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions couchforms/tests/data/namespaces.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"#export_tag": "xmlns",
"_attachments": {
"form.xml": {
"content_type": "text/xml",
Expand Down Expand Up @@ -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
}
13 changes: 11 additions & 2 deletions couchforms/tests/data/unicode.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"#export_tag": "xmlns",
"_attachments": {
"form.xml": {
"content_type": "text/xml",
Expand All @@ -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
}
22 changes: 10 additions & 12 deletions couchforms/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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
Expand Down Expand Up @@ -359,24 +358,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

Expand Down

0 comments on commit 0e0e260

Please sign in to comment.