def _apply_attachments_action(self, attachment_action, xform): if not toggles.MM_CASE_PROPERTIES.enabled(self.case.domain): return # NOTE `attachment_action` is a # `casexml.apps.case.xml.parser.CaseAttachmentAction` and # `attachment_action.attachments` is a dict with values of # `casexml.apps.case.xml.parser.CaseAttachment` current_attachments = self.case.case_attachments for name, att in attachment_action.attachments.items(): if att.is_delete: if name in current_attachments: self.case.track_delete(current_attachments[name]) elif att.attachment_src: form_attachment = xform.get_attachment_meta(att.attachment_src) if form_attachment is None: # Probably an improperly configured form. We need a way to # convey errors like this to domain admins. raise AttachmentNotFound( "%s: %r" % (xform.form_id, att.attachment_src)) if name in current_attachments: existing_attachment = current_attachments[name] existing_attachment.from_form_attachment( form_attachment, att.attachment_src) self.case.track_update(existing_attachment) else: new_attachment = CaseAttachmentSQL.new(att.identifier) new_attachment.from_form_attachment( form_attachment, att.attachment_src) new_attachment.case = self.case self.case.track_create(new_attachment)
def _apply_attachments_action(self, attachment_action, xform): # NOTE `attachment_action` is a # `casexml.apps.case.xml.parser.CaseAttachmentAction` and # `attachment_action.attachments` is a dict with values of # `casexml.apps.case.xml.parser.CaseAttachment` current_attachments = self.case.case_attachments for name, att in attachment_action.attachments.items(): if att.is_delete: if name in current_attachments: self.case.track_delete(current_attachments[name]) else: form_attachment = xform.get_attachment_meta(att.attachment_src) if name in current_attachments: existing_attachment = current_attachments[name] existing_attachment.from_form_attachment( form_attachment, att.attachment_src) self.case.track_update(existing_attachment) else: new_attachment = CaseAttachmentSQL.new(att.identifier) new_attachment.from_form_attachment( form_attachment, att.attachment_src) new_attachment.case = self.case self.case.track_create(new_attachment)
def _migrate_case_attachments(couch_case, sql_case): """Copy over attachment meta """ for name, attachment in couch_case.case_attachments.items(): blob = couch_case.blobs[name] assert name == attachment.identifier or not attachment.identifier or not name, \ (name, attachment.identifier) sql_case.track_create( CaseAttachmentSQL(name=name or attachment.identifier, case=sql_case, content_type=attachment.server_mime, content_length=attachment.content_length, blob_id=blob.id, blob_bucket=couch_case._blobdb_bucket(), properties=attachment.attachment_properties, md5=attachment.server_md5))
def _migrate_case_attachments(couch_case, sql_case): """Copy over attachment meta """ for name, attachment in six.iteritems(couch_case.case_attachments): blob = couch_case.blobs[name] sql_case.track_create( CaseAttachmentSQL(name=name, case=sql_case, identifier=attachment.identifier, attachment_src=attachment.attachment_src, attachment_from=attachment.attachment_from, content_type=attachment.server_mime, content_length=attachment.content_length, blob_id=blob.id, blob_bucket=couch_case._blobdb_bucket(), properties=attachment.attachment_properties, md5=attachment.server_md5))
def _apply_attachments_action(self, attachment_action, xform): current_attachments = self.case.case_attachments for identifier, att in attachment_action.attachments.items(): new_attachment = CaseAttachmentSQL.from_case_update(att) if new_attachment.is_present: form_attachment = xform.get_attachment_meta(att.attachment_src) if identifier in current_attachments: existing_attachment = current_attachments[identifier] existing_attachment.from_form_attachment(form_attachment) self.case.track_update(existing_attachment) else: new_attachment.from_form_attachment(form_attachment) new_attachment.case = self.case self.case.track_create(new_attachment) elif identifier in current_attachments: existing_attachment = current_attachments[identifier] self.case.track_delete(existing_attachment)
if name in current_attachments: self.case.track_delete(current_attachments[name]) elif att.attachment_src: form_attachment = xform.get_attachment_meta(att.attachment_src) if form_attachment is None: # Probably an improperly configured form. We need a way to # convey errors like this to domain admins. raise AttachmentNotFound( "%s: %r" % (xform.form_id, att.attachment_src)) if name in current_attachments: existing_attachment = current_attachments[name] existing_attachment.from_form_attachment( form_attachment, att.attachment_src) self.case.track_update(existing_attachment) else: new_attachment = CaseAttachmentSQL.new(att.identifier) new_attachment.from_form_attachment( form_attachment, att.attachment_src) new_attachment.case = self.case self.case.track_create(new_attachment) def _apply_close_action(self, case_update): self.case.closed = True self.case.closed_on = case_update.guess_modified_on() self.case.closed_by = case_update.user_id def _reset_case_state(self): """ Clear known case properties, and all dynamic properties """ self.case.case_json = {}