def deduplicate_xform(cls, xform): # follow standard dupe handling, which simply saves a copy of the form # but a new doc_id, and a doc_type of XFormDuplicate xform.doc_type = XFormDuplicate.__name__ dupe = XFormDuplicate.wrap(xform.to_json()) dupe.problem = "Form is a duplicate of another! (%s)" % xform._id return cls.assign_new_id(dupe)
def swap_doc_types(self, log_file, bad_xform_id, duplicate_xform_id, domain, dry_run): bad_xform = XFormInstance.get(bad_xform_id) # confirm that the doc hasn't already been fixed: bad_xform_problem = None try: bad_xform_problem = bad_xform.problem or "" except AttributeError: pass if bad_xform_problem: if re.match(PROBLEM_TEMPLATE_START, bad_xform_problem): self.log_already_fixed(log_file, bad_xform_id, domain) return duplicate_xform = XFormInstance.get(duplicate_xform_id) now = datetime.now().isoformat() # Convert the XFormInstance to an XFormDuplicate bad_xform.doc_type = XFormDuplicate.__name__ bad_xform.problem = BAD_FORM_PROBLEM_TEMPLATE.format(duplicate_xform_id, now) bad_xform = XFormDuplicate.wrap(bad_xform.to_json()) # Convert the XFormDuplicate to an XFormInstance duplicate_xform.problem = FIXED_FORM_PROBLEM_TEMPLATE.format( id_=bad_xform_id, datetime_=now ) duplicate_xform.doc_type = XFormInstance.__name__ duplicate_xform = XFormInstance.wrap(duplicate_xform.to_json()) self.log_swap(log_file, bad_xform_id, domain, duplicate_xform_id, dry_run) if not dry_run: duplicate_xform.save() bad_xform.save()
def swap_doc_types(self, log_file, bad_xform_id, duplicate_xform_id, domain, dry_run): bad_xform = XFormInstance.get(bad_xform_id) # confirm that the doc hasn't already been fixed: bad_xform_problem = None try: bad_xform_problem = bad_xform.problem or "" except AttributeError: pass if bad_xform_problem: if re.match(PROBLEM_TEMPLATE_START, bad_xform_problem): self.log_already_fixed(log_file, bad_xform_id, domain) return duplicate_xform = XFormInstance.get(duplicate_xform_id) now = datetime.now().isoformat() # Convert the XFormInstance to an XFormDuplicate bad_xform.doc_type = XFormDuplicate.__name__ bad_xform.problem = BAD_FORM_PROBLEM_TEMPLATE.format(duplicate_xform_id, now) bad_xform = XFormDuplicate.wrap(bad_xform.to_json()) # Convert the XFormDuplicate to an XFormInstance duplicate_xform.problem = FIXED_FORM_PROBLEM_TEMPLATE.format( id_=bad_xform_id, datetime_=now ) duplicate_xform.doc_type = XFormInstance.__name__ duplicate_xform = XFormInstance.wrap(duplicate_xform.to_json()) self.log_swap(log_file, bad_xform_id, domain, duplicate_xform_id, dry_run) if not dry_run: duplicate_xform.save() bad_xform.save()
def deduplicate_xform(cls, xform): # follow standard dupe handling, which simply saves a copy of the form # but a new doc_id, and a doc_type of XFormDuplicate xform.doc_type = XFormDuplicate.__name__ dupe = XFormDuplicate.wrap(xform.to_json()) assert not xform.persistent_blobs, "some blobs would be lost" if xform._deferred_blobs: dupe._deferred_blobs = xform._deferred_blobs.copy() dupe.problem = "Form is a duplicate of another! (%s)" % xform._id return cls.assign_new_id(dupe)
def deduplicate_xform(cls, xform): # follow standard dupe handling, which simply saves a copy of the form # but a new doc_id, and a doc_type of XFormDuplicate xform.doc_type = XFormDuplicate.__name__ dupe = XFormDuplicate.wrap(xform.to_json()) assert not xform.persistent_blobs, "some blobs would be lost" if xform._deferred_blobs: dupe._deferred_blobs = xform._deferred_blobs.copy() dupe.problem = "Form is a duplicate of another! (%s)" % xform._id return cls.assign_new_id(dupe)