forked from dimagi/commcare-hq
/
specs.py
30 lines (23 loc) · 946 Bytes
/
specs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from collections import namedtuple
from dimagi.ext.jsonobject import StringProperty
from datetime import datetime
def TypeProperty(value):
"""
Shortcut for making a required property and restricting it to a single specified
value. This adds additional validation that the objects are being wrapped as expected
according to the type.
"""
return StringProperty(required=True, choices=[value])
class FactoryContext(namedtuple('FactoryContext', ('named_expressions', 'named_filters'))):
@staticmethod
def empty():
return FactoryContext({}, {})
class EvaluationContext(object):
"""
An evaluation context. Necessary for repeats to pass both the row of the repeat as well
as the root document and the iteration number.
"""
def __init__(self, root_doc, iteration=0):
self.root_doc = root_doc
self.iteration = iteration
self.inserted_timestamp = datetime.utcnow()