14 |
14 |
# You should have received a copy of the GNU General Public License
|
15 |
15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
16 |
16 |
|
17 |
|
from __future__ import print_function
|
18 |
|
|
19 |
17 |
import json
|
20 |
18 |
|
21 |
19 |
from django.core.management.base import CommandError
|
... | ... | |
51 |
49 |
parser.add_argument('filenames', metavar='FILENAME', nargs='+')
|
52 |
50 |
|
53 |
51 |
def handle(self, filenames, domain, trigger, workflow_id, formdef_id,
|
54 |
|
all_formdata, **options):
|
|
52 |
all_formdata, verbosity, **options):
|
55 |
53 |
|
56 |
54 |
self.init_tenant_publisher(domain)
|
57 |
55 |
|
... | ... | |
64 |
62 |
formdef = FormDef.get(id=formdef_id, ignore_errors=True)
|
65 |
63 |
if not formdef:
|
66 |
64 |
raise CommandError('formdef-id does not exist')
|
67 |
|
select_and_jump_formdata(formdef, trigger, rows)
|
|
65 |
select_and_jump_formdata(formdef, trigger, rows, verbosity=verbosity)
|
68 |
66 |
else:
|
69 |
67 |
if workflow_id:
|
70 |
68 |
workflow = Workflow.get(id=workflow_id, ignore_errors=True)
|
... | ... | |
77 |
75 |
status_ids = list(get_status_ids_accepting_trigger(workflow, trigger))
|
78 |
76 |
if status_ids:
|
79 |
77 |
for formdef in [f for f in FormDef.select() if f.workflow_id == workflow.id]:
|
80 |
|
select_and_jump_formdata(formdef, trigger, rows, status_ids)
|
|
78 |
select_and_jump_formdata(formdef, trigger, rows,
|
|
79 |
status_ids=status_ids, verbosity=verbosity)
|
81 |
80 |
|
82 |
81 |
|
83 |
82 |
def get_rows(args):
|
... | ... | |
116 |
115 |
return True
|
117 |
116 |
|
118 |
117 |
|
119 |
|
def jump_and_perform(formdata, action, workflow_data=None):
|
|
118 |
def jump_and_perform(formdata, action, workflow_data=None, verbosity=1):
|
120 |
119 |
get_publisher().substitutions.reset()
|
121 |
120 |
get_publisher().substitutions.feed(get_publisher())
|
122 |
121 |
get_publisher().substitutions.feed(formdata.formdef)
|
123 |
122 |
get_publisher().substitutions.feed(formdata)
|
124 |
|
print('formdata %s jumps to status %s' % (formdata, action.status))
|
|
123 |
if verbosity > 1:
|
|
124 |
print('formdata %s jumps to status %s' % (formdata, action.status))
|
125 |
125 |
wcs_jump_and_perform(formdata, action, workflow_data=workflow_data)
|
126 |
126 |
|
127 |
127 |
|
128 |
|
def select_and_jump_formdata(formdef, trigger, rows, status_ids=None):
|
|
128 |
def select_and_jump_formdata(formdef, trigger, rows, status_ids=None, verbosity=1):
|
129 |
129 |
for formdata, action_item in get_formdata_accepting_trigger(formdef, trigger, status_ids):
|
130 |
130 |
if rows == '__all__':
|
131 |
|
jump_and_perform(formdata, action=action_item)
|
|
131 |
jump_and_perform(formdata, action=action_item, verbosity=verbosity)
|
132 |
132 |
else:
|
133 |
133 |
substitution_variables = formdata.get_substitution_variables()
|
134 |
134 |
for row in rows:
|
135 |
135 |
if match_row(substitution_variables, row):
|
136 |
|
jump_and_perform(formdata, action_item, row.get('data'))
|
|
136 |
jump_and_perform(formdata, action=action_item,
|
|
137 |
workflow_data=row.get('data'), verbosity=verbosity)
|
137 |
138 |
break # next formdata
|
138 |
|
-
|