Skip to content

Commit 090fbb0

Browse files
committed
DateConstant: blockly xml parse/create
1 parent 4cb17e8 commit 090fbb0

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

business_logic/blockly/parse.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
3-
3+
import datetime
44
from lxml import etree, objectify
55

66
from django.utils.six import StringIO
@@ -213,12 +213,18 @@ def visit_field_text(self, node):
213213
def visit_field_bool(self, node):
214214
return self._visit_field(BooleanConstant, value=node.text.lower() == 'true')
215215

216+
def visit_field_date(self, node):
217+
return self._visit_field(DateConstant, value=datetime.datetime.strptime(node.text, '%Y-%m-%d').date())
218+
216219
def visit_value(self, node):
217220
return self._visit_single_child(node)
218221

219222
def visit_statement(self, node):
220223
return self._visit_single_child(node)
221224

225+
def visit_block_business_logic_date(self, node):
226+
return self._visit_single_child(node)
227+
222228
def visit_block_business_logic_reference(self, node):
223229
data = {
224230
'data': {

tests/blockly/test_create.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ def test_create_reference_constant(self):
114114
self.assertIsNot(tree1, tree2)
115115
self.assertFalse(self.tree_diff(tree1, tree2))
116116

117+
def test_create_date(self):
118+
today = datetime.date.today()
119+
tree1 = variable_assign_value(value=DateConstant(value=today))
120+
dict1 = self.build_dict(tree1)
121+
122+
tree2 = NodeTreeCreator().create(dict1)
123+
124+
self.assertIsInstance(tree2, Node)
125+
self.assertIsNot(tree1, tree2)
126+
self.assertFalse(self.tree_diff(tree1, tree2))
117127

118128
def test_create_function(self):
119129
function_definition = PythonCodeFunctionDefinition.objects.create(title='xxx')

tests/blockly/test_parse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def test_boolean_constant(self):
9393
for value in (True, False):
9494
self._test_constant(BooleanConstant, value)
9595

96+
def test_date_constantant(self):
97+
self._test_constant(DateConstant, datetime.date.today())
98+
9699

97100
class BlocklyXmlParserReferenceConstantTest(BlocklyXmlParserTestCase):
98101
def setUp(self):

0 commit comments

Comments
 (0)