Skip to content

Commit

Permalink
working now with shared set of cols
Browse files Browse the repository at this point in the history
  • Loading branch information
quadrismegistus committed Jan 17, 2024
1 parent e38652f commit 66bd9c6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
37 changes: 32 additions & 5 deletions mep/people/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Profession,
Relationship,
RelationshipType,
ViafSignalHandler
)
from import_export.admin import (
ImportExportModelAdmin,
Expand All @@ -34,6 +35,30 @@
from import_export.fields import Field
from parasolr.django.signals import IndexableSignalHandler

PERSON_IMPORT_EXPORT_COLUMNS = (
'id',
'name',
'birth_year',
'death_year',
'gender',
'nationalities',
'notes',
'start_year',
'end_year',
'mep_id',
'sort_name',
'viaf_id',
'is_organization',
'verified',
'title',
'profession',
'relations',
'public_notes',
'locations',
'slug',
'updated_at',
)


class InfoURLInline(CollapsibleTabularInline):
model = InfoURL
Expand Down Expand Up @@ -449,11 +474,13 @@ def before_import(self, dataset, *args, **kwargs):
dataset.headers = [x.lower().replace(' ','_') for x in dataset.headers]

Check warning on line 474 in mep/people/admin.py

View check run for this annotation

Codecov / codecov/patch

mep/people/admin.py#L474

Added line #L474 was not covered by tests
# turn off indexing temporarily
IndexableSignalHandler.disconnect()
ViafSignalHandler.disconnect()

Check warning on line 477 in mep/people/admin.py

View check run for this annotation

Codecov / codecov/patch

mep/people/admin.py#L476-L477

Added lines #L476 - L477 were not covered by tests

def after_import(self, *args, **kwargs):
super().after_import(*args, **kwargs)

Check warning on line 480 in mep/people/admin.py

View check run for this annotation

Codecov / codecov/patch

mep/people/admin.py#L480

Added line #L480 was not covered by tests
# reconnect indexing signal handler
IndexableSignalHandler.connect()
ViafSignalHandler.connect()

Check warning on line 483 in mep/people/admin.py

View check run for this annotation

Codecov / codecov/patch

mep/people/admin.py#L482-L483

Added lines #L482 - L483 were not covered by tests

def before_import_row(self, row, **kwargs):
# gender to one char
Expand All @@ -465,26 +492,26 @@ def fmt_gender(x):
name = Field(column_name='name', attribute='name')
gender = Field(column_name='gender', attribute='gender')
nationalities = Field(
column_name='nationality',
column_name='nationalities',
attribute='nationalities',
widget=ManyToManyWidget(Country, field='name', separator=';')
)

class Meta:
model = Person
fields = ('name','gender','nationalities')
import_id_fields = ('name',)
import_id_fields = ('slug',)
export_order = PERSON_IMPORT_EXPORT_COLUMNS
skip_unchanged = True
report_skipped = True


class PersonAdminWithImport(PersonAdmin, ImportExportModelAdmin):
class PersonAdminImportExport(PersonAdmin, ImportExportModelAdmin):
resource_class = PersonResource
change_list_template = "templates/admin/people/person/change_list.html"


# enable default admin to see imported data
admin.site.register(Person, PersonAdminWithImport)
admin.site.register(Person, PersonAdminImportExport)
admin.site.register(Country, CountryAdmin)
admin.site.register(Location, LocationAdmin)
admin.site.register(Profession, NamedNotableAdmin)
Expand Down
13 changes: 12 additions & 1 deletion mep/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@

logger = logging.getLogger(__name__)

VIAF_SIGNAL_ACTIVE=True
class ViafSignalHandler:
def disconnect():
global VIAF_SIGNAL_ACTIVE
VIAF_SIGNAL_ACTIVE = False

Check warning on line 33 in mep/people/models.py

View check run for this annotation

Codecov / codecov/patch

mep/people/models.py#L33

Added line #L33 was not covered by tests
def connect():
global VIAF_SIGNAL_ACTIVE
VIAF_SIGNAL_ACTIVE = True

Check warning on line 36 in mep/people/models.py

View check run for this annotation

Codecov / codecov/patch

mep/people/models.py#L36

Added line #L36 was not covered by tests
def is_connected():
return VIAF_SIGNAL_ACTIVE


class Country(Named):
"""Countries, for documenting nationalities of a :class:`Person`
Expand Down Expand Up @@ -533,7 +544,7 @@ def save(self, *args, **kwargs):
"""Adds birth and death dates if they aren't already set
and there's a viaf id for the record"""

if self.viaf_id and not self.birth_year and not self.death_year:
if ViafSignalHandler.is_connected() and self.viaf_id and not self.birth_year and not self.death_year:
self.set_birth_death_years()

# if slug has changed, save the old one as a past slug
Expand Down

0 comments on commit 66bd9c6

Please sign in to comment.