Skip to content

Commit

Permalink
[api] Altera código de exportação do campo "indexado_em". #343
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusandrade committed Mar 10, 2017
1 parent 19b614b commit bc5739b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions bireme/api/bibliographic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def build_filters(self, filters=None):
filter_db = filters['indexed_database']
filter_db_id = Database.objects.get(acronym=filter_db)
orm_filters['indexed_database__exact'] = filter_db_id

return orm_filters

def prepend_urls(self):
Expand Down Expand Up @@ -135,6 +135,13 @@ def full_dehydrate(self, bundle, for_list=False):
def add_fields_to_bundle(self, bundle, obj, import_field_list=[]):
for field in obj._meta.get_fields():
field_value = getattr(obj, field.name, {})

# check if field has multiples values (ex. ManyToManyField)
if hasattr(field_value, 'all'):
# if field is empty skip to next field
if not field_value.all().exists():
continue

if field_value:
# if import_field_list is present check if field is the list
if import_field_list:
Expand Down Expand Up @@ -179,7 +186,7 @@ def dehydrate(self, bundle):
bundle.data['descriptors_secondary'] = descriptors_secundary
bundle.data['thematic_areas'] = [{'text': thematic.thematic_area.name} for thematic in thematic_areas]
bundle.data['alternate_ids'] = [alt.alternate_id for alt in alternate_ids]
bundle.data['database'] = [database.acronym for database in bundle.obj.indexed_database.all()]
bundle.data['indexed_database'] = [database.acronym for database in bundle.obj.indexed_database.all()]

electronic_address = []
for attach in attachments:
Expand Down Expand Up @@ -225,7 +232,7 @@ def dehydrate(self, bundle):

if local_databases:
# add local databases to database field (v04)
bundle.data['database'].extend(local_databases)
bundle.data['database'] = local_databases

return bundle

Expand Down
2 changes: 1 addition & 1 deletion bireme/biblioref/field_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'reproduction_note': '533', 'original_version_note': '534', 'institution_as_subject': '610',
'local_descriptors': '653', 'clinical_trial_registry_name': '700', 'doi_number': '724',
'source_control': '98', 'export_control_1': '776', 'export_control_2': '778', 'alternate_ids': '779',
'created_time': '91', 'created_by': '92', 'updated_time': '93', 'system_version': '899',
'created_time': '91', 'created_by': '92', 'updated_time': '93', 'system_version': '899', 'indexed_database': '904',
}


Expand Down

0 comments on commit bc5739b

Please sign in to comment.