def handle(self, *args, **options): if len(args) == 1: id = args[0] else: raise CommandError("Usage: %s\n%s" % (self.args, self.help)) reprocess_form_cases(XFormError.get(id))
def handle(self, *args, **options): if len(args) == 1: id = args[0] else: raise CommandError('Usage: %s\n%s' % (self.args, self.help)) reprocess_form_cases(XFormError.get(id))
def post_xform_to_couch(instance, attachments={}): """ Post an xform to couchdb, based on the settings.XFORMS_POST_URL. Returns the newly created document from couchdb, or raises an exception if anything goes wrong. attachments is a dictionary of the request.FILES that are not the xform. Key is the parameter name, and the value is the django MemoryFile object stream. """ def _has_errors(response, errors): return errors or "error" in response # check settings for authentication credentials try: response, errors = post_from_settings(instance) if not _has_errors(response, errors): doc_id = response try: xform = XFormInstance.get(doc_id) #put attachments onto the saved xform instance for key, val in attachments.items(): res = xform.put_attachment(val, name=key, content_type=val.content_type, content_length=val.size) # fire signals # We don't trap any exceptions here. This is by design. # If something fails (e.g. case processing), we quarantine the # form into an error location. xform_saved.send(sender="couchforms", xform=xform) return xform except Exception, e: logging.error("Problem with form %s" % doc_id) logging.exception(e) # "rollback" by changing the doc_type to XFormError try: bad = XFormError.get(doc_id) bad.problem = "%s" % e bad.save() return bad except ResourceNotFound: pass # no biggie, the failure must have been in getting it back raise else: