def related_budget(self, related_budget_all, serializer, prefix="organisation_total_budget"): if related_budget_all: self.add_field(prefix + '_period_start', []) self.add_field(prefix + '_period_end', []) self.add_field(prefix + '_value', []) self.add_field(prefix + '_value_currency', []) self.add_field(prefix + '_value_date', []) self.add_field(prefix, []) for related_budget in related_budget_all: self.add_value_list(prefix + '_period_start', value_string(related_budget.period_start)) self.add_value_list(prefix + '_period_end', value_string(related_budget.period_end)) self.add_value_list(prefix + '_value', decimal_string(related_budget.value)) self.add_value_list(prefix + '_value_currency', related_budget.currency_id) self.add_value_list(prefix + '_value_date', value_string(related_budget.value_date)) self.add_value_list( prefix, JSONRenderer().render( serializer(related_budget).data).decode())
def indicator_period(self, indicator): period_all = indicator.resultindicatorperiod_set.all() if period_all: if 'result_indicator_period_period_start_iso_date' not in self.indexing: # NOQA: E501 self.add_field( 'result_indicator_period_period_start_iso_date', [] ) self.add_field( 'result_indicator_period_period_end_iso_date', [] ) for period in period_all: self.add_value_list( 'result_indicator_period_period_start_iso_date', value_string(period.period_start) ) self.add_value_list( 'result_indicator_period_period_end_iso_date', value_string(period.period_end) ) self.indicator_period_related( period.targets.all() ) self.indicator_period_related( period.actuals.all() )
def dataset(self): dataset = self.record self.add_field('id', dataset.id) self.add_field('name', dataset.name) self.add_field('title', dataset.title) self.add_field('filetype', dataset.filetype) self.add_field('date_created', value_string(dataset.date_created).split(' ')[0]) self.add_field('date_updated', value_string(dataset.date_updated).split(' ')[0]) self.add_field('iati_version', dataset.iati_version) self.add_field('source_url', dataset.source_url) self.dataset_publisher()
def organisation(self): organisation = self.record self.add_field('id', organisation.id) self.add_field('organisation_identifier', organisation.organisation_identifier) self.add_field('organisation_type', organisation.type_id) self.add_field('organisation_reported_in_iati', bool_string(organisation.reported_in_iati)) self.add_field('organisation_published', bool_string(organisation.published)) self.add_field('organisation_last_updated_datetime', value_string(organisation.last_updated_datetime)) self.add_field('organisation_default_currency_code', organisation.default_currency_id) self.add_field('organisation_default_lang_code', organisation.default_lang_id) self.name() self.related_budget(self.record.total_budgets.all(), serializer=OrganisationTotalBudgetSerializer, prefix="organisation_total_budget") self.related_budget( self.record.recipientorgbudget_set.all(), serializer=OrganisationRecipientOrgBudgetSerializer, prefix="organisation_recipient_org_budget") self.related_budget( self.record.recipient_region_budget.all(), serializer=OrganisationRecipientRegionBudgetSerializer, prefix="organisation_recipient_region_budget") self.related_budget( self.record.recipient_country_budgets.all(), serializer=OrganisationRecipientCountryBudgetSerializer, prefix="organisation_recipient_country_budget") self.document_links()
def document_link(self, document_link_all, prefix='result_document_link'): if document_link_all: if prefix not in self.indexing: self.add_field(prefix, []) self.add_field(prefix + '_url', []) self.add_field(prefix + '_format', []) self.add_field(prefix + '_document_date_iso_date', []) self.add_field(prefix + '_description_narrative', []) self.add_field(prefix + '_category_code', []) self.add_field(prefix + '_language_code', []) for document_link in document_link_all: self.add_value_list( prefix, JSONRenderer().render( DocumentLinkSerializer(document_link).data).decode()) self.add_value_list(prefix + '_url', document_link.url) self.add_value_list(prefix + '_format', document_link.file_format_id) self.add_value_list(prefix + '_document_date_iso_date', value_string(document_link.iso_date)) category_all = document_link.documentlinkcategory_set.all() if category_all: for category in category_all: self.add_value_list(prefix + '_category_code', category.category_id) language_all = document_link.documentlinklanguage_set.all() if language_all: for language in language_all: self.add_value_list(prefix + '_language_code', language.language_id)
def budget(self): budget = self.record self.add_field('id', budget.id) self.add_field('iati_identifier', budget.activity.iati_identifier) self.add_field('budget_type', budget.type_id) self.add_field('budget_status', budget.status_id) self.add_field('budget_period_start_iso_date', value_string(budget.period_start)) self.add_field('budget_period_end_iso_date', value_string(budget.period_end)) self.add_field('budget_value_currency', budget.currency_id) self.add_field('budget_value_date', value_string(budget.value_date)) self.add_field('budget_value', decimal_string(budget.value)) add_reporting_org(self, budget.activity)
def indicator_baseline(self, indicator): baseline_all = indicator.resultindicatorbaseline_set.all() if baseline_all: if 'result_indicator_baseline_year' not in self.indexing: self.add_field('result_indicator_baseline_year', []) self.add_field('result_indicator_baseline_iso_date', []) self.add_field('result_indicator_baseline_value', []) self.add_field('result_indicator_baseline_location_ref', []) self.add_field('result_indicator_baseline_dimension_name', []) self.add_field('result_indicator_baseline_dimension_value', []) self.add_field('result_indicator_baseline_comment_narrative', []) for baseline in baseline_all: self.add_value_list('result_indicator_baseline_year', baseline.year) self.add_value_list('result_indicator_baseline_iso_date', value_string(baseline.iso_date)) self.add_value_list('result_indicator_baseline_value', baseline.value) for location in baseline.location_set.all(): self.add_value_list( 'result_indicator_baseline_location_ref', location.ref) for dimension in \ baseline.resultindicatorbaselinedimension_set.all(): self.add_value_list( 'result_indicator_baseline_dimension_name', dimension.name) self.add_value_list( 'result_indicator_baseline_dimension_value', dimension.value) comment = get_child_attr(baseline, 'resultindicatorbaselinecomment') if comment: for narrative in comment.narratives.all(): self.add_value_list( 'result_indicator_baseline_comment_narrative', narrative.content) self.document_link( baseline.baseline_document_links.all(), prefix='result_indicator_baseline_document_link')
def document_links(self): document_link_all = self.record.organisationdocumentlink_set.all() if document_link_all: self.add_field('organisation_document_link', []) self.add_field('organisation_document_link_url', []) self.add_field('organisation_document_link_format', []) self.add_field('organisation_document_link_document_date', []) for document_link in document_link_all: self.add_value_list('organisation_document_link_url', document_link.url) self.add_value_list('organisation_document_link_format', document_link.file_format_id) self.add_value_list('organisation_document_link_document_date', value_string(document_link.iso_date)) self.add_value_list( 'organisation_document_link', JSONRenderer().render( OrganisationDocumentLinkSerializer( document_link).data).decode())
def add_activity_additional_filter_fields(serializer, activity): serializer.add_field('activity_scope_code', activity.scope_id) serializer.add_field('activity_status_code', activity.activity_status_id) serializer.add_field('collaboration_type_code', activity.collaboration_type_id) serializer.add_field('default_currency', activity.default_currency_id) serializer.add_field('default_finance_type_code', activity.default_finance_type_id) serializer.add_field('default_lang', activity.default_lang_id) serializer.add_field('default_flow_type_code', activity.default_flow_type_id) serializer.add_field('default_tied_status_code', activity.default_tied_status_id) serializer.add_field('hierarchy', value_string(activity.hierarchy)) serializer.add_field('default_humanitarian', bool_string(activity.humanitarian)) serializer.add_field('dataset_iati_version', activity.iati_standard_version_id) # default-aid-type default_aid_type_all = activity.default_aid_types.all() if default_aid_type_all: serializer.add_field('default_aid_type_code', []) serializer.add_field('default_aid_type_vocabulary', []) serializer.add_field('default_aid_type_category_code', []) for default_aid_type in default_aid_type_all: serializer.add_value_list( 'default_aid_type_code', get_child_attr(default_aid_type, 'aid_type.code')) serializer.add_value_list( 'default_aid_type_vocabulary', get_child_attr(default_aid_type, 'aid_type.vocabulary.code')) serializer.add_value_list( 'default_aid_type_category_code', get_child_attr(default_aid_type, 'aid_type.category.code')) # document-link-category-code # we want to get only activity/document-link not other document-links document_link_all = activity.documentlink_set.filter( result_id__isnull=True, result_indicator_id__isnull=True, result_indicator_baseline_id__isnull=True, result_indicator_period_actual_id__isnull=True, result_indicator_period_target_id__isnull=True) if document_link_all: serializer.add_field('document_link_category_code', []) for document_link in document_link_all: for document_link_category in \ document_link.documentlinkcategory_set.all(): serializer.add_value_list('document_link_category_code', document_link_category.category_id) # humanitarian scope humanitarian_scope_all = activity.humanitarianscope_set.all() if humanitarian_scope_all: serializer.add_field('humanitarian_scope_type', []) serializer.add_field('humanitarian_scope_vocabulary', []) for humanitarian_scope in humanitarian_scope_all: serializer.add_value_list('humanitarian_scope_type', humanitarian_scope.type_id) serializer.add_value_list('humanitarian_scope_vocabulary', humanitarian_scope.vocabulary_id) # other-identifier other_identifier_all = activity.otheridentifier_set.all() if other_identifier_all: serializer.add_field('other_identifier_type', []) for other_identifier in other_identifier_all: serializer.add_value_list('other_identifier_type', other_identifier.type_id) # policy-marker policy_marker_all = activity.activitypolicymarker_set.all() if policy_marker_all: serializer.add_field('policy_marker_code', []) for policy_marker in policy_marker_all: serializer.add_value_list('policy_marker_code', policy_marker.code_id) # tag tag_all = activity.activitytag_set.all() if tag_all: serializer.add_field('tag_code', []) serializer.add_field('tag_vocabulary', []) for tag in tag_all: serializer.add_value_list('tag_code', tag.code) serializer.add_value_list('tag_vocabulary', tag.vocabulary_id)