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.qommon.management.commands.migrate import Command as CmdMigrate
|
||||||
from wcs.ctl.process_bounce import CmdProcessBounce
|
from wcs.ctl.process_bounce import CmdProcessBounce
|
||||||
from wcs.ctl.wipe_data import CmdWipeData
|
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.ctl.delete_tenant import CmdDeleteTenant
|
||||||
from wcs.sql import get_connection_and_cursor, cleanup_connection
|
from wcs.sql import get_connection_and_cursor, cleanup_connection
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# w.c.s. - web application for online forms
|
# 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
|
# 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
|
# 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
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
from quixote import get_publisher
|
from quixote import get_publisher
|
||||||
|
from qommon.publisher import get_publisher_class
|
||||||
from qommon.ctl import Command, make_option
|
|
||||||
|
|
||||||
from wcs.formdef import FormDef
|
from wcs.formdef import FormDef
|
||||||
from wcs.workflows import Workflow
|
from wcs.workflows import Workflow
|
||||||
from wcs.wf.jump import JumpWorkflowStatusItem, jump_and_perform as wcs_jump_and_perform
|
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
|
'''Triggers all "jump trigger" for a formdef, given host publisher context
|
||||||
|
|
||||||
source.json file format:
|
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):
|
def init_tenant_publisher(self, domain):
|
||||||
Command.__init__(self, [
|
publisher_class = get_publisher_class()
|
||||||
make_option('--trigger', metavar='TRIGGER', action='store',
|
publisher = publisher_class.create_publisher()
|
||||||
dest='trigger', help='(mandatory) trigger name'),
|
if not domain in publisher.get_tenants():
|
||||||
make_option('--vhost', metavar='VHOST', action='store',
|
raise CommandError('unknown tenant')
|
||||||
dest='vhost'),
|
publisher.app_dir = os.path.join(publisher.app_dir, domain)
|
||||||
make_option('--workflow-id', metavar='WORKFLOW_ID', action='store',
|
return publisher
|
||||||
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 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:
|
self.init_tenant_publisher(domain)
|
||||||
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')
|
|
||||||
|
|
||||||
import publisher
|
if not all_formdata:
|
||||||
self.config.remove_option('main', 'error_log')
|
rows = list(get_rows(filenames))
|
||||||
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))
|
|
||||||
else:
|
else:
|
||||||
rows = '__all__'
|
rows = '__all__'
|
||||||
|
|
||||||
if sub_options.formdef_id:
|
if formdef_id:
|
||||||
formdef = FormDef.get(id=sub_options.formdef_id, ignore_errors=True)
|
formdef = FormDef.get(id=formdef_id, ignore_errors=True)
|
||||||
if not formdef:
|
if not formdef:
|
||||||
exit('formdef-id does not exist')
|
raise CommandError('formdef-id does not exist')
|
||||||
select_and_jump_formdata(formdef, trigger, rows)
|
select_and_jump_formdata(formdef, trigger, rows)
|
||||||
else:
|
else:
|
||||||
if sub_options.workflow_id:
|
if workflow_id:
|
||||||
workflow = Workflow.get(id=sub_options.workflow_id, ignore_errors=True)
|
workflow = Workflow.get(id=workflow_id, ignore_errors=True)
|
||||||
if not workflow:
|
if not workflow:
|
||||||
exit('workflow does not exist')
|
raise CommandError('workflow does not exist')
|
||||||
workflows = [workflow]
|
workflows = [workflow]
|
||||||
else:
|
else:
|
||||||
workflows = Workflow.select()
|
workflows = Workflow.select()
|
||||||
|
@ -101,12 +86,6 @@ class CmdTriggerJumps(Command):
|
||||||
select_and_jump_formdata(formdef, trigger, rows, status_ids)
|
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):
|
def get_rows(args):
|
||||||
for arg in args:
|
for arg in args:
|
||||||
for row in json.load(file(arg)):
|
for row in json.load(file(arg)):
|
|
@ -130,6 +130,7 @@ INSTALLED_APPS = (
|
||||||
#'django.contrib.messages',
|
#'django.contrib.messages',
|
||||||
#'django.contrib.admin',
|
#'django.contrib.admin',
|
||||||
'gadjo',
|
'gadjo',
|
||||||
|
'wcs.ctl',
|
||||||
'wcs.qommon',
|
'wcs.qommon',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue