misc: change trigger_jumps into a django command (#18730)
This commit is contained in:
parent
d9dd94d2ff
commit
c33a029ae3
|
@ -14,7 +14,7 @@ from wcs.qommon.management.commands.collectstatic import Command as CmdCollectSt
|
|||
from wcs.qommon.management.commands.migrate import Command as CmdMigrate
|
||||
from wcs.ctl.process_bounce import CmdProcessBounce
|
||||
from wcs.ctl.wipe_data import CmdWipeData
|
||||
from wcs.ctl.trigger_jumps import select_and_jump_formdata
|
||||
from wcs.ctl.management.commands.trigger_jumps import select_and_jump_formdata
|
||||
from wcs.ctl.delete_tenant import CmdDeleteTenant
|
||||
from wcs.sql import get_connection_and_cursor, cleanup_connection
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# w.c.s. - web application for online forms
|
||||
# Copyright (C) 2005-2013 Entr'ouvert
|
||||
# Copyright (C) 2005-2017 Entr'ouvert
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -14,20 +14,20 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import os
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from quixote import get_publisher
|
||||
|
||||
from qommon.ctl import Command, make_option
|
||||
from qommon.publisher import get_publisher_class
|
||||
|
||||
from wcs.formdef import FormDef
|
||||
from wcs.workflows import Workflow
|
||||
from wcs.wf.jump import JumpWorkflowStatusItem, jump_and_perform as wcs_jump_and_perform
|
||||
|
||||
|
||||
class CmdTriggerJumps(Command):
|
||||
class Command(BaseCommand):
|
||||
'''Triggers all "jump trigger" for a formdef, given host publisher context
|
||||
|
||||
source.json file format:
|
||||
|
@ -40,57 +40,42 @@ class CmdTriggerJumps(Command):
|
|||
]
|
||||
'''
|
||||
|
||||
name = 'trigger-jumps'
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('-d', '--domain', metavar='DOMAIN', required=True)
|
||||
parser.add_argument('--trigger', metavar='TRIGGER', required=True)
|
||||
parser.add_argument('--workflow-id', metavar='WORKFLOW_ID')
|
||||
parser.add_argument('--formdef-id', metavar='FORMDEF_ID')
|
||||
parser.add_argument('--all-formdata', action='store_true')
|
||||
parser.add_argument('filenames', metavar='FILENAME', nargs='+')
|
||||
|
||||
def __init__(self):
|
||||
Command.__init__(self, [
|
||||
make_option('--trigger', metavar='TRIGGER', action='store',
|
||||
dest='trigger', help='(mandatory) trigger name'),
|
||||
make_option('--vhost', metavar='VHOST', action='store',
|
||||
dest='vhost'),
|
||||
make_option('--workflow-id', metavar='WORKFLOW_ID', action='store',
|
||||
dest='workflow_id'),
|
||||
make_option('--formdef-id', metavar='FORMDEF_ID', action='store',
|
||||
dest='formdef_id'),
|
||||
make_option('--all-formdata', metavar='ALL_FORMDATA',
|
||||
action='store_true', dest='all_formdata'),
|
||||
])
|
||||
def init_tenant_publisher(self, domain):
|
||||
publisher_class = get_publisher_class()
|
||||
publisher = publisher_class.create_publisher()
|
||||
if not domain in publisher.get_tenants():
|
||||
raise CommandError('unknown tenant')
|
||||
publisher.app_dir = os.path.join(publisher.app_dir, domain)
|
||||
return publisher
|
||||
|
||||
def execute(self, base_options, sub_options, args):
|
||||
def handle(self, filenames, domain, trigger, workflow_id, formdef_id,
|
||||
all_formdata, **options):
|
||||
|
||||
if not sub_options.all_formdata and not args:
|
||||
exit('missing input json file(s) (or --all-formdata flag)')
|
||||
if not sub_options.vhost:
|
||||
exit('you must specify --vhost')
|
||||
if not sub_options.trigger:
|
||||
exit('you must specify --trigger')
|
||||
if sub_options.formdef_id and sub_options.workflow_id:
|
||||
exit('specify --workflow-id or --formdef-id')
|
||||
self.init_tenant_publisher(domain)
|
||||
|
||||
import publisher
|
||||
self.config.remove_option('main', 'error_log')
|
||||
publisher.WcsPublisher.configure(self.config)
|
||||
publisher = publisher.WcsPublisher.create_publisher(
|
||||
register_tld_names=False)
|
||||
publisher.app_dir = os.path.join(publisher.app_dir, sub_options.vhost)
|
||||
publisher.set_config()
|
||||
|
||||
trigger = sub_options.trigger
|
||||
if not sub_options.all_formdata:
|
||||
rows = list(get_rows(args))
|
||||
if not all_formdata:
|
||||
rows = list(get_rows(filenames))
|
||||
else:
|
||||
rows = '__all__'
|
||||
|
||||
if sub_options.formdef_id:
|
||||
formdef = FormDef.get(id=sub_options.formdef_id, ignore_errors=True)
|
||||
if formdef_id:
|
||||
formdef = FormDef.get(id=formdef_id, ignore_errors=True)
|
||||
if not formdef:
|
||||
exit('formdef-id does not exist')
|
||||
raise CommandError('formdef-id does not exist')
|
||||
select_and_jump_formdata(formdef, trigger, rows)
|
||||
else:
|
||||
if sub_options.workflow_id:
|
||||
workflow = Workflow.get(id=sub_options.workflow_id, ignore_errors=True)
|
||||
if workflow_id:
|
||||
workflow = Workflow.get(id=workflow_id, ignore_errors=True)
|
||||
if not workflow:
|
||||
exit('workflow does not exist')
|
||||
raise CommandError('workflow does not exist')
|
||||
workflows = [workflow]
|
||||
else:
|
||||
workflows = Workflow.select()
|
||||
|
@ -101,12 +86,6 @@ class CmdTriggerJumps(Command):
|
|||
select_and_jump_formdata(formdef, trigger, rows, status_ids)
|
||||
|
||||
|
||||
CmdTriggerJumps.register()
|
||||
|
||||
def exit(message):
|
||||
print >> sys.stderr, message
|
||||
sys.exit(1)
|
||||
|
||||
def get_rows(args):
|
||||
for arg in args:
|
||||
for row in json.load(file(arg)):
|
|
@ -130,6 +130,7 @@ INSTALLED_APPS = (
|
|||
#'django.contrib.messages',
|
||||
#'django.contrib.admin',
|
||||
'gadjo',
|
||||
'wcs.ctl',
|
||||
'wcs.qommon',
|
||||
'django.contrib.staticfiles',
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue