From 53d807ef17364e017dde21cc5dacf284d3ce0a9e Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Mon, 24 Oct 2016 16:49:20 +0200 Subject: [PATCH] empty forms command (#13669) --- wcs/ctl/empty_forms.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 wcs/ctl/empty_forms.py diff --git a/wcs/ctl/empty_forms.py b/wcs/ctl/empty_forms.py new file mode 100644 index 0000000..1689b29 --- /dev/null +++ b/wcs/ctl/empty_forms.py @@ -0,0 +1,51 @@ +# w.c.s. - web application for online forms +# Copyright (C) 2005-2010 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . + +import os + +from qommon.ctl import Command, make_option + + +class EmptyForms(Command): + name = 'empty_forms' + + def __init__(self): + Command.__init__(self, [ + make_option('--all', action='store_true', + dest='all', default=False), + ]) + + def execute(self, base_options, sub_options, args): + import publisher + from wcs.formdef import FormDef + + publisher.WcsPublisher.configure(self.config) + pub = publisher.WcsPublisher.create_publisher( + register_cron=False, register_tld_names=False) + app_dir = pub.app_dir + + if sub_options.all: + hostnames = publisher.WcsPublisher.get_tenants() + else: + hostnames = args + for hostname in hostnames: + pub.app_dir = os.path.join(app_dir, hostname) + + for formdef in FormDef.select(): + formdata = formdef.data_class() + formdata.wipe() + +EmptyForms.register() -- 2.10.1