-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexample.py
More file actions
186 lines (179 loc) · 17.1 KB
/
example.py
File metadata and controls
186 lines (179 loc) · 17.1 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# encoding: utf-8
# This file is so pathetic it doesn't even need a license
from dictdiff import dictdiff, dictmerge
from pprint import pprint
a = {'Content': [
{'Content': ['First', 'Previous', 'Next', 'Last', 'New', 'Edit', 'Confirm', 'Cancel', 'Remove', 'Search', 'Copy', 'Cut', 'Paste'], 'DataProvider': 'dacCurrencies', 'ID': 'tbrCurrencies', 'Style': 'margin-bottom: 10px', 'widgettype': 'toolbar'},
{'DataProvider': 'dacCurrencies', 'DragType': {'draghandle': '.ui-jqgrid-titlebar:first'},
'GridOptions': {'caption': 'Currencies',
'colModel': [{'editable': False, 'hidden': True, 'label': 'Record', 'name': 'crn_id'},
{'editable': True,
'formatoptions': {'newformat': 'd.m.Y H:i:s', 'srcformat': 'd.m.Y H:i:s'},
'formatter': 'date', 'hidden': True, 'label': 'date cr', 'name': 'crn_cdate'},
{'editable': True, 'edittype': 'text', 'hidden': True, 'label': 'user cr', 'name': 'crn_cuser'},
{'editable': True,
'formatoptions': {'newformat': 'd.m.Y H:i:s', 'srcformat': 'd.m.Y H:i:s'},
'formatter': 'date', 'hidden': True, 'label': 'date upd', 'name': 'crn_mdate'},
{'editable': True, 'edittype': 'text', 'hidden': True, 'label': 'user upd', 'name': 'crn_muser'},
{'editable': True, 'edittype': 'text', 'label': 'Currency name', 'name': 'crn_sname'},
{'editable': True, 'edittype': 'text', 'label': 'Name', 'name': 'crn_name'},
{'editable': True, 'edittype': 'text', 'label': 'Original name', 'name': 'crn_oname'},
{'editable': True,
'formatoptions': {'newformat': 'd.m.Y H:i:s', 'srcformat': 'd.m.Y H:i:s'},
'formatter': 'date', 'label': 'Valid date from', 'name': 'crn_valid_from'},
{'editable': True,
'formatoptions': {'newformat': 'd.m.Y H:i:s', 'srcformat': 'd.m.Y H:i:s'},
'formatter': 'date', 'label': 'Valid date to', 'name': 'crn_valid_to'},
{'align': 'right', 'editable': True, 'formatter': 'integer', 'label': 'Unit', 'name': 'crn_unit'},
{'align': 'right', 'editable': True, 'formatter': 'integer', 'label': 'Rnd', 'name': 'crn_rounding'},
{'editable': True, 'edittype': 'text', 'label': 'Alfa code', 'name': 'crn_code_a'},
{'editable': True, 'edittype': 'number', 'label': 'Numeric code', 'name': 'crn_code_n'}],
'rowList': [10, 20, 30],
'rowNum': 10,
'rownumbers': True,
'viewrecords': True},
'ID': 'gridCurrencies',
'Style': 'margin-bottom: 10px',
'widgettype': 'grid'},
{'Children': [{'Hidden': True, 'ID': 'l_crn_id',
'LabelFor': [{'DataField': 'crn_id', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_id', 'Mask': '0000000000000000', 'widgettype': 'input'}],
'Text': 'Record', 'TextWrap': False, 'widgettype': 'label'},
{'Hidden': True, 'ID': 'l_crn_cdate',
'LabelFor': [{'DataField': 'crn_cdate', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_cdate', 'Type': 'Datetime', 'widgettype': 'input'}],
'Text': 'Creation date', 'TextWrap': False, 'widgettype': 'label'},
{'Hidden': True, 'ID': 'l_crn_cuser',
'LabelFor': [{'DataField': 'crn_cuser', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_cuser', 'widgettype': 'input'}],
'Text': 'Creation user', 'TextWrap': False, 'widgettype': 'label'},
{'Hidden': True, 'ID': 'l_crn_mdate',
'LabelFor': [{'DataField': 'crn_mdate', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_mdate', 'Type': 'Datetime', 'widgettype': 'input'}],
'Text': 'Modification date', 'TextWrap': False, 'widgettype': 'label'},
{'Hidden': True, 'ID': 'l_crn_muser',
'LabelFor': [{'DataField': 'crn_muser', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_muser', 'widgettype': 'input'}],
'Text': 'Modification user', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_sname',
'LabelFor': [{'DataField': 'crn_sname', 'DataProvider': 'dacCurrencies', 'ID': 'crn_sname', 'widgettype': 'input'}],
'Text': 'Currency name', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_name',
'LabelFor': [{'DataField': 'crn_name', 'DataProvider': 'dacCurrencies', 'ID': 'crn_name', 'widgettype': 'input'}],
'Text': 'Name', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_oname',
'LabelFor': [{'DataField': 'crn_oname', 'DataProvider': 'dacCurrencies', 'ID': 'crn_oname', 'widgettype': 'input'}],
'Text': 'Original name', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_valid_from',
'LabelFor': [{'DataField': 'crn_valid_from', 'DataProvider': 'dacCurrencies', 'ID': 'crn_valid_from', 'Type': 'Datetime', 'widgettype': 'input'}],
'Text': 'Valid date from', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_valid_to',
'LabelFor': [{'DataField': 'crn_valid_to', 'DataProvider': 'dacCurrencies', 'ID': 'crn_valid_to', 'Type': 'Datetime', 'widgettype': 'input'}],
'Text': 'Valid date to', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_unit',
'LabelFor': [{'DataField': 'crn_unit', 'DataProvider': 'dacCurrencies', 'ID': 'crn_unit', 'Mask': '000000000000', 'Type': 'Number', 'widgettype': 'input'}],
'Text': 'Unit', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_rounding',
'LabelFor': [{'DataField': 'crn_rounding', 'DataProvider': 'dacCurrencies', 'ID': 'crn_rounding', 'Mask': '000000000000', 'Type': 'Number', 'widgettype': 'input'}],
'Text': 'Rounding (decimals)', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_code_a',
'LabelFor': [{'DataField': 'crn_code_a', 'DataProvider': 'dacCurrencies', 'ID': 'crn_code_a', 'widgettype': 'input'}],
'Text': 'Alfa code', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_code_n',
'LabelFor': [{'DataField': 'crn_code_n', 'DataProvider': 'dacCurrencies', 'ID': 'crn_code_n', 'widgettype': 'input'}],
'Text': 'Numeric code', 'TextWrap': False, 'widgettype': 'label'}],
'ID': 'gb1Currencies', 'Style': 'margin-bottom: 10px', 'Title': 'Fields', 'widgettype': 'groupbox'}],
'CssClass': 'anawin-content-nopadding',
'DACs': [{'DataProvider': 'WorkflowSupport.get_task_form_docgeneric(None)', 'ID': 'dacCurrencies', 'MasterID': '', 'PageSize': 20, 'widgettype': 'dac'}],
'ID': 'winCurrencies', 'Name': 'Currencies', 'ShowBorder': False,
'SysButtons': ['Collapse', 'Maximize', 'Close'],
'Title': {'ID': 'w0labelCurrencies', 'LabelFor': [], 'Text': 'Currencies', 'TextWrap': False, 'widgettype': 'label'},
'widgettype': 'window'}
b = {'Content': [
{'Content': ['First', 'Previous', 'Next', 'Last', 'New', 'Edit', 'Confirm', 'Cancel', 'Remove', 'Search', 'Copy', 'Cut', 'Paste'], 'DataProvider': 'dacCurrencies', 'ID': 'tbrCurrencies', 'Style': 'margin-bottom: 10px', 'widgettype': 'toolbar'},
{'DataProvider': 'dacCurrencies', 'DragType': {'draghandle': '.ui-jqgrid-titlebar:first'},
'GridOptions': {'caption': 'Currencies',
'colModel': [{'editable': False, 'hidden': True, 'label': 'Record', 'name': 'crn_id'},
{'editable': True,
'formatoptions': {'newformat': 'd.m.Y H:i:s', 'srcformat': 'd.m.Y H:i:s'},
'formatter': 'date', 'hidden': True, 'label': 'date cr', 'name': 'crn_cdate'},
{'editable': True, 'edittype': 'text', 'hidden': True, 'label': 'user cr', 'name': 'crn_cuser'},
{'editable': True, 'edittype': 'text', 'hidden': True, 'label': 'user upd', 'name': 'crn_muser'},
{'editable': True,
'formatoptions': {'newformat': 'd.m.Y H:i:s', 'srcformat': 'd.m.Y H:i:s'},
'formatter': 'date', 'hidden': True, 'label': 'date upd', 'name': 'crn_mdate'},
{'editable': True, 'edittype': 'text', 'label': 'Currency name', 'name': 'crn_sname'},
{'editable': True, 'edittype': 'text', 'label': 'Name', 'name': 'crn_name'},
{'editable': True, 'edittype': 'text', 'label': 'Original name', 'name': 'crn_oname'},
{'editable': True,
'formatoptions': {'newformat': 'd.m.Y H:i:s', 'srcformat': 'd.m.Y H:i:s'},
'formatter': 'date', 'label': 'Valid date from', 'name': 'crn_valid_from'},
{'editable': True,
'formatoptions': {'newformat': 'd.m.Y H:i:s', 'srcformat': 'd.m.Y H:i:s'},
'formatter': 'date', 'label': 'Valid date to', 'name': 'crn_valid_to'},
{'align': 'right', 'editable': True, 'formatter': 'integer', 'label': 'Unit', 'name': 'crn_unit'},
{'align': 'right', 'editable': True, 'formatter': 'integer', 'label': 'Rnd', 'name': 'crn_rounding'},
{'editable': True, 'edittype': 'text', 'label': 'Alfa code', 'name': 'crn_code_a'},
{'editable': True, 'edittype': 'text', 'label': 'Numeric code', 'name': 'crn_code_n'},
{'editable': True, 'edittype': 'text', 'label': 'Yet another code', 'name': 'crn_code_x'}],
'rowList': [10, 20, 30],
'rowNum': 10,
'rownumbers': True,
'viewrecords': True},
'ID': 'gridCurrencies',
'Style': 'margin-bottom: 10px',
'widgettype': 'grid'},
{'Children': [{'Hidden': True, 'ID': 'l_crn_id',
'LabelFor': [{'DataField': 'crn_id', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_id', 'Mask': '0000000000000000', 'widgettype': 'input'}],
'Text': 'Record', 'TextWrap': False, 'widgettype': 'label'},
{'Hidden': True, 'ID': 'l_crn_cdate',
'LabelFor': [{'DataField': 'crn_cdate', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_cdate', 'Type': 'Datetime', 'widgettype': 'input'}],
'Text': 'Creation date', 'TextWrap': False, 'widgettype': 'label'},
{'Hidden': True, 'ID': 'l_crn_cuser',
'LabelFor': [{'DataField': 'crn_cuser', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_cuser', 'widgettype': 'input'}],
'Text': 'Creation user', 'TextWrap': False, 'widgettype': 'label'},
{'Hidden': True, 'ID': 'l_crn_muser',
'LabelFor': [{'DataField': 'crn_muser', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_muser', 'widgettype': 'input'}],
'Text': 'Modification user', 'TextWrap': False, 'widgettype': 'label'},
{'Hidden': True, 'ID': 'l_crn_mdate',
'LabelFor': [{'DataField': 'crn_mdate', 'DataProvider': 'dacCurrencies', 'Hidden': True, 'ID': 'crn_mdate', 'Type': 'Datetime', 'widgettype': 'input'}],
'Text': 'Modification date', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_sname',
'LabelFor': [{'DataField': 'crn_sname', 'DataProvider': 'dacCurrencies', 'ID': 'crn_sname', 'widgettype': 'input'}],
'Text': 'Currency name', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_name',
'LabelFor': [{'DataField': 'crn_name', 'DataProvider': 'dacCurrencies', 'ID': 'crn_name', 'widgettype': 'input'}],
'Text': 'Name', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_oname',
'LabelFor': [{'DataField': 'crn_oname', 'DataProvider': 'dacCurrencies', 'ID': 'crn_oname', 'widgettype': 'input'}],
'Text': 'Original name', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_valid_from',
'LabelFor': [{'DataField': 'crn_valid_from', 'DataProvider': 'dacCurrencies', 'ID': 'crn_valid_from', 'Type': 'Datetime', 'widgettype': 'input'}],
'Text': 'Valid date from', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_valid_to',
'LabelFor': [{'DataField': 'crn_valid_to', 'DataProvider': 'dacCurrencies', 'ID': 'crn_valid_to', 'Type': 'Datetime', 'widgettype': 'input'}],
'Text': 'Valid date to', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_unit',
'LabelFor': [{'DataField': 'crn_unit', 'DataProvider': 'dacCurrencies', 'ID': 'crn_unit', 'Mask': '000000000000', 'Type': 'Number', 'widgettype': 'input'}],
'Text': 'Unit', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_rounding',
'LabelFor': [{'DataField': 'crn_rounding', 'DataProvider': 'dacCurrencies', 'ID': 'crn_rounding', 'Mask': '000000000000', 'Type': 'Number', 'widgettype': 'input'}],
'Text': 'Rounding (decimals)', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_code_a',
'LabelFor': [{'DataField': 'crn_code_a', 'DataProvider': 'dacCurrencies', 'ID': 'crn_code_a', 'widgettype': 'input'}],
'Text': 'Alfa code', 'TextWrap': False, 'widgettype': 'label'},
{'ID': 'l_crn_code_n',
'LabelFor': [{'DataField': 'crn_code_n', 'DataProvider': 'dacCurrencies', 'ID': 'crn_code_n', 'widgettype': 'input'}],
'Text': 'Numeric code', 'TextWrap': False, 'widgettype': 'label'}],
'ID': 'gb1Currencies', 'Style': 'margin-bottom: 10px', 'Title': 'Fields', 'widgettype': 'groupbox'}],
'CssClass': 'anawin-content-nopadding',
'DACs': [{'DataProvider': 'WorkflowSupport.get_task_form_docgeneric(None)', 'ID': 'dacCurrencies', 'MasterID': '', 'PageSize': 20, 'widgettype': 'dac'}],
'ID': 'winCurrencies', 'Name': 'Currencies', 'ShowBorder': False,
'SysButtons': ['Collapse', 'Maximize', 'Close'],
'Title': {'ID': 'w0labelCurrencies', 'LabelFor': [], 'Text': 'Currencies', 'TextWrap': False, 'widgettype': 'label'},
'widgettype': 'window'}
#Store diff, for a short difference representation (converto to JSON & save to a file for example)
c = dictdiff(a, b, ["ID", "name"])
pprint(c)
#Apply a stored difference to base (a is reproducible, but we 'lost' b somewhere along the way)
d = dictmerge(a, c, ["ID", "name"])
pprint(d)
#Even if we don't have stored diff, we can apply b to a so that we apply any
#prior modifications (b) yet keep the new features introduced in a later version of a
d = dictmerge(a, b)
pprint(d)