Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
765 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from django.contrib import admin | ||
from django.contrib import messages | ||
from django.contrib.contenttypes.models import ContentType | ||
from .models import Run, RunLog, Identifier, Range, Record | ||
from django.urls import reverse | ||
from django.http import HttpResponseRedirect | ||
|
||
|
||
class FixedTabularInline(admin.TabularInline): | ||
can_delete = False | ||
extra = 0 | ||
|
||
def has_add_permission(self, request, obj): | ||
return False | ||
|
||
|
||
class RangeInline(FixedTabularInline): | ||
model = Range | ||
readonly_fields = [ | ||
'type', | ||
'header_col', | ||
'start_col', | ||
'end_col', | ||
'header_row', | ||
'start_row', | ||
'end_row', | ||
'count' | ||
] | ||
|
||
|
||
class RecordInline(FixedTabularInline): | ||
model = Record | ||
fields = readonly_fields = [ | ||
'row', | ||
'success', | ||
'content_type', | ||
'content_object', | ||
'fail_reason' | ||
] | ||
|
||
|
||
class RunLogInline(FixedTabularInline): | ||
model = RunLog | ||
readonly_fields = ['event', 'date'] | ||
|
||
|
||
@admin.register(Run) | ||
class RunAdmin(admin.ModelAdmin): | ||
list_display = [ | ||
'__str__', 'serializer_label', 'record_count', 'last_update' | ||
] | ||
inlines = [RangeInline, RecordInline, RunLogInline] | ||
|
||
|
||
@admin.register(Identifier) | ||
class IdentifierAdmin(admin.ModelAdmin): | ||
list_display = ['__str__', 'type', 'resolved'] | ||
|
||
|
||
def start_data_wizard(modeladmin, request, queryset): | ||
if queryset.count() != 1: | ||
modeladmin.message_user( | ||
request, | ||
'Select a single row to start data wizard.', | ||
level=messages.ERROR, | ||
) | ||
return | ||
instance = queryset.first() | ||
if isinstance(instance, Run): | ||
run = instance | ||
else: | ||
ct = ContentType.objects.get_for_model(queryset.model) | ||
run = Run.objects.create( | ||
user=request.user, | ||
content_type=ct, | ||
object_id=instance.pk, | ||
) | ||
return HttpResponseRedirect( | ||
reverse('data_wizard:run-serializers', kwargs={'pk': run.pk}) | ||
) | ||
|
||
|
||
start_data_wizard.short_description = "Import via data wizard" | ||
|
||
admin.site.add_action(start_data_wizard, 'data_wizard') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.