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)
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 = {}