def get__source(self, obj): hidden_fields = ['restrictions'] try: doc = obj.get_doc() masked_fields = self.get_masked_fields(obj) d = doc.to_dict() try: d['ip_objid'] = get_cached_objid(d['ip']) except KeyError: pass if doc._index == 'document': try: d['attachment'].pop('content', None) except KeyError: pass for field in d.keys(): if field in masked_fields: d[field] = '' if field in hidden_fields: d.pop(field) return d except elasticsearch.NotFoundError: return None
def run(self, filename="", events=None): if not filename: ip = InformationPackage.objects.get(pk=self.ip) filename = os.path.join(ip.object_path, ip.get_events_file_path()) generator = XMLGenerator(filepath=filename) template = get_event_element_spec() if not events: events = EventIP.objects.filter( linkingObjectIdentifierValue=self.ip) id_types = {} for id_type in ['event', 'linking_agent', 'linking_object']: entity = '%s_identifier_type' % id_type id_types[id_type] = Parameter.objects.cached( 'entity', entity, 'value') target = generator.find_element('premis') for event in events.iterator(): objid = get_cached_objid(event.linkingObjectIdentifierValue) data = { "eventIdentifierType": id_types['event'], "eventIdentifierValue": str(event.eventIdentifierValue), "eventType": str(event.eventType.code) if event.eventType.code is not None and event.eventType.code != '' else str( event.eventType.eventType), "eventDateTime": str(event.eventDateTime), "eventDetail": event.eventType.eventDetail, "eventOutcome": str(event.eventOutcome), "eventOutcomeDetailNote": event.eventOutcomeDetailNote, "linkingAgentIdentifierType": id_types['linking_agent'], "linkingAgentIdentifierValue": event.linkingAgentIdentifierValue, "linkingAgentRole": event.linkingAgentRole, "linkingObjectIdentifierType": id_types['linking_object'], "linkingObjectIdentifierValue": objid, } generator.insert_from_specification(target, template, data) generator.write(filename)
def __call__(self, *args, **kwargs): options = kwargs.pop('_options', {}) self.chunk = options.get('chunk', False) self.args = options.get('args', []) self.responsible = options.get('responsible') self.ip = options.get('ip') if self.ip is not None: self.ip_objid = get_cached_objid(str(self.ip)) self.step = options.get('step') self.step_pos = options.get('step_pos') self.hidden = options.get('hidden', False) or self.hidden self.undo_type = options.get('undo', False) self.result_params = options.get('result_params', {}) or {} self.task_id = options.get('task_id') or self.request.id self.eager = options.get('eager') or self.request.is_eager if self.chunk: res = [] events = [] if not connection.features.autocommits_when_autocommit_is_off: transaction.set_autocommit(False) try: for a in args: a_options = a.pop('_options') self.eager = True self.task_id = a_options['task_id'] self.args = a_options['args'] self.progress = 0 hidden = a_options.get('hidden', False) or self.hidden time_started = timezone.now() try: retval = self._run(*self.args, **a) except: ProcessTask.objects.filter(pk=self.task_id).update( hidden=hidden, time_started=time_started, progress=self.progress) einfo = ExceptionInfo() if self.event_type: self.create_event(self.task_id, celery_states.FAILURE, args, a, None, einfo) raise else: self.success(retval, self.task_id, None, kwargs) ProcessTask.objects.filter(pk=self.task_id).update( result=retval, status=celery_states.SUCCESS, hidden=hidden, time_started=time_started, time_done=timezone.now(), progress=100) res.append(retval) if self.event_type: self.create_event(self.task_id, celery_states.SUCCESS, self.args, a, retval, None) except: raise else: return res finally: if not connection.features.autocommits_when_autocommit_is_off: transaction.commit() transaction.set_autocommit(True) for k, v in six.iteritems(self.result_params): kwargs[k] = get_result(v, self.eager) if self.track: ProcessTask.objects.filter(pk=self.task_id).update( hidden=self.hidden, status=celery_states.STARTED, time_started=timezone.now()) return self._run(*args, **kwargs)
def event_outcome_success(self, path, prev=None): path, = self.parse_params(path) return "Updated path of %s to %s" % (get_cached_objid(str(self.ip)), path)
def event_outcome_success(self, status, prev=None): status, = self.parse_params(status) return u"Updated status of {} to {}".format(get_cached_objid(str(self.ip)), status)
def event_outcome_success(self): return "Submitted %s" % get_cached_objid(self.ip)
def get_information_package(id): return {'object_identifier_value': get_cached_objid(id)}