def handle(self, domain, user_id, **options): form_accessor = FormAccessors(domain) form_ids = form_accessor.get_form_ids_for_user(user_id) print("Found %s forms for user" % len(form_ids)) response = input( "Are you sure you want to archive them? (yes to proceed)") if response == 'yes': with open("archived_forms_for_user_%s.txt" % user_id, 'wb') as log: for ids in chunked(with_progress_bar(form_ids), 100): ids = list([f for f in ids if f]) for form in form_accessor.get_forms(ids): log.write(form.form_id + '\n') form.archive()
def handle(self, username, domain, **options): this_form_accessor = FormAccessors(domain=domain) user = CouchUser.get_by_username(username) if not user: logger.info("User {} not found.".format(username)) sys.exit(1) user_id = user._id form_ids = this_form_accessor.get_form_ids_for_user(user_id) input_response = six.moves.input( "Update {} form(s) for user {} in domain {}? (y/n): ".format(len(form_ids), username, domain)) if input_response == "y": for form_data in this_form_accessor.iter_forms(form_ids): form_attachment_xml_new = self.update_form_data(form_data, NEW_USERNAME) this_form_accessor.modify_attachment_xml_and_metadata(form_data, form_attachment_xml_new, NEW_USERNAME) logging.info("Updated {} form(s) for user {} in domain {}".format(len(form_ids), username, domain)) elif input_response == "n": logging.info("No forms updated, exiting.") else: logging.info("Command not recognized. Exiting.")
def handle(self, username, domain, **options): this_form_accessor = FormAccessors(domain=domain) user = CouchUser.get_by_username(username) if not user: logger.info("User {} not found.".format(username)) sys.exit(1) user_id = user._id form_ids = this_form_accessor.get_form_ids_for_user(user_id) input_response = six.moves.input( "Update {} form(s) for user {} in domain {}? (y/n): ".format( len(form_ids), username, domain)) if input_response == "y": for form_data in this_form_accessor.iter_forms(form_ids): form_attachment_xml_new = self.update_form_data( form_data, NEW_USERNAME) this_form_accessor.modify_attachment_xml_and_metadata( form_data, form_attachment_xml_new, NEW_USERNAME) logging.info("Updated {} form(s) for user {} in domain {}".format( len(form_ids), username, domain)) elif input_response == "n": logging.info("No forms updated, exiting.") else: logging.info("Command not recognized. Exiting.")
def _get_forms_to_archive(self): # ordered with latest form's id on top form_accessor = FormAccessors(self.domain) form_ids = form_accessor.get_form_ids_for_user(self.user_id) return [f for f in form_accessor.get_forms(form_ids) if f.is_normal]