def handle(self, *args, **options): print os.path.abspath(os.path.curdir) verbosity = int(options.get('verbosity', 1)) if len(args) != 2: raise CommandError('Usage is submit_form %s' % self.args) file = args[0] url = args[1] method = options.get('method', 'curl') use_chunked = options.get('use_chunked', False) is_odk = options.get('is_odk', False) if file == None or url == None: raise CommandError('Usage is submit_form %s' % self.args) if not os.path.exists(file): raise CommandError("File does not exist") if method == 'curl': use_curl = True elif method == 'python': use_curl = False print post_data(None, url, path=file, use_curl=use_curl, use_chunked=use_chunked, is_odk=is_odk)
def handle(self, *args, **options): if len(args) < 2: raise CommandError('Usage is submit_form %s' % self.args) file = args[0] url = args[1] rest = args[2:] method = options.get('method', 'curl') use_chunked = options.get('use_chunked', False) is_odk = options.get('is_odk', False) if file == None or url == None: raise CommandError('Usage is submit_form %s' % self.args) if not os.path.exists(file): raise CommandError("File does not exist") attachments = [] for attach_path in rest: if not os.path.exists(attach_path): raise CommandError("Error, additional file path does not exist: %s" % attach_path) else: attachments.append((attach_path.replace('.', '_'), attach_path)) if method == 'curl': use_curl = True elif method == 'python': use_curl = False print post_data(None, url, path=file, use_curl=use_curl, use_chunked=use_chunked, is_odk=is_odk, attachments=attachments)
def handle(self, *args, **options): if len(args) < 2: raise CommandError("Usage is submit_form %s" % self.args) file = args[0] url = args[1] rest = args[2:] method = options.get("method", "curl") use_chunked = options.get("use_chunked", False) is_odk = options.get("is_odk", False) if file is None or url is None: raise CommandError("Usage is submit_form %s" % self.args) if not os.path.exists(file): raise CommandError("File does not exist") attachments = [] for attach_path in rest: if not os.path.exists(attach_path): raise CommandError("Error, additional file path does not exist: %s" % attach_path) else: attachments.append((attach_path.replace(".", "_"), attach_path)) if method == "curl": use_curl = True elif method == "python": use_curl = False print post_data( None, url, path=file, use_curl=use_curl, use_chunked=use_chunked, is_odk=is_odk, attachments=attachments )
def handle(self, *args, **options): print "Options:" print options self.username = options['username'] self.password = options['password'] self.url_base = options['url'] self.case_id = options['case'] if self.case_id is None: print "\n\tNo case id, read the damn instructions" self.user_doc = CommCareUser.get_by_username(self.username) if not self.get_credentials(): print "\n\tLogin failed, exiting" sys.exit() print "\nStarting attachment upload" print "here are the files" print options['files'] case_doc = CommCareCase.get(self.case_id) domain = case_doc.domain submit_id = uuid.uuid4().hex def attach_block(key, filename): return '<n0:%s src="%s" from="local"/>' % (key, os.path.split(filename)[-1]) attachments = [attach_block(k, v) for k, v in options['files'].items()] format_dict = { "time_start": (datetime.utcnow() - timedelta(seconds=5)).strftime('%Y-%m-%dT%H:%M:%SZ'), "time_end": datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'), "date_modified": datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'), "user_id": self.user_doc.get_id, "username": self.username, "doc_id": submit_id, "case_id": self.case_id, "attachments": ''.join(attachments) } url = self.url_base + "/a/%s/receiver" % domain attachment_tuples = [(k, v) for k, v in options['files'].items()] final_xml = XFORM_TEMPLATE % format_dict print post_data(final_xml, url, path=None, use_curl=True, use_chunked=True, is_odk=True, attachments=attachment_tuples)
def post_from_settings(instance, extras={}): url = settings.XFORMS_POST_URL if not extras else "%s?%s" % \ (settings.XFORMS_POST_URL, "&".join(["%s=%s" % (k, v) for k, v in extras.items()])) if settings.COUCH_USERNAME: return post_authenticated_data(instance, url, settings.COUCH_USERNAME, settings.COUCH_PASSWORD) else: return post_data(instance, url)
def handle(self, *args, **options): print os.path.abspath(os.path.curdir) if len(args) != 2: raise CommandError('Usage is submit_form %s' % self.args) file = args[0] url = args[1] method = options.get('method', 'curl') use_chunked = options.get('use_chunked', False) is_odk = options.get('is_odk', False) if file == None or url == None: raise CommandError('Usage is submit_form %s' % self.args) if not os.path.exists(file): raise CommandError("File does not exist") if method == 'curl': use_curl = True elif method == 'python': use_curl = False print post_data(None, url, path=file, use_curl=use_curl, use_chunked=use_chunked, is_odk=is_odk)
def _replace_ids_and_post(xml_data, case_id_override=None, referral_id_override=None): # from our test forms, replace the UIDs so we don't get id conflicts uid, case_id, ref_id = (uuid.uuid4().hex for i in range(3)) if case_id_override: case_id = case_id_override if referral_id_override: ref_id = referral_id_override xml_data = xml_data.replace("REPLACE_UID", uid) xml_data = xml_data.replace("REPLACE_CASEID", case_id) xml_data = xml_data.replace("REPLACE_REFID", ref_id) doc_id, _ = post_data(xml_data, settings.XFORMS_POST_URL ) return (doc_id, uid, case_id, ref_id)
def handle(self, *args, **options): if len(args) < 2: raise CommandError('Usage is submit_form %s' % self.args) file = args[0] url = args[1] rest = args[2:] method = options.get('method', 'curl') use_chunked = options.get('use_chunked', False) is_odk = options.get('is_odk', False) if file is None or url is None: raise CommandError('Usage is submit_form %s' % self.args) if not os.path.exists(file): raise CommandError("File does not exist") attachments = [] for attach_path in rest: if not os.path.exists(attach_path): raise CommandError( "Error, additional file path does not exist: %s" % attach_path) else: attachments.append((attach_path.replace('.', '_'), attach_path)) if method == 'curl': use_curl = True elif method == 'python': use_curl = False print post_data(None, url, path=file, use_curl=use_curl, use_chunked=use_chunked, is_odk=is_odk, attachments=attachments)
def handle(self, filename, url, files, **options): use_curl = options['method'] == 'curl' use_chunked = options['use_chunked'] is_odk = options['is_odk'] attachments = [] for attach_path in files: if not os.path.exists(attach_path): raise CommandError( "Error, additional file path does not exist: %s" % attach_path) else: attachments.append((attach_path.replace('.', '_'), attach_path)) print( post_data(None, url, path=file, use_curl=use_curl, use_chunked=use_chunked, is_odk=is_odk, attachments=attachments))