Skip to content

Commit

Permalink
Merge pull request #106 from dimagi/explicit-form-properties
Browse files Browse the repository at this point in the history
Explicit form properties
  • Loading branch information
czue committed Apr 17, 2014
2 parents 6ddddfb + 1ea3482 commit 4c0443d
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 35 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 @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4c0443d

Please sign in to comment.