Skip to content
Snippets Groups Projects
Commit 78643547 authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Fix imports

parent 603d991d
No related branches found
No related tags found
No related merge requests found
......@@ -3,11 +3,16 @@ from enumfields.admin import EnumFieldListFilter
from arkindex.dataimport.models import DataImport, DataFile
class DataFileInline(admin.StackedInline):
model = DataImport.files.through
class DataImportAdmin(admin.ModelAdmin):
list_display = ('id', 'creator', 'corpus', 'state', 'mode')
list_filter = [('state', EnumFieldListFilter), ('mode', EnumFieldListFilter)]
fields = ('id', 'creator', 'corpus', 'state', 'mode', 'payload', 'root_id')
readonly_fields = ('id', 'root_id', )
inlines = [DataFileInline, ]
class DataFileAdmin(admin.ModelAdmin):
......@@ -15,6 +20,7 @@ class DataFileAdmin(admin.ModelAdmin):
list_filter = ('corpus', )
fields = ('id', 'name', 'size', 'hash', 'content_type', 'corpus')
readonly_fields = ('id', 'size', 'hash', )
inlines = [DataFileInline, ]
admin.site.register(DataImport, DataImportAdmin)
......
......@@ -2,9 +2,10 @@ from django.db import models
from django.contrib.postgres.fields import JSONField
from django.template.defaultfilters import slugify
from django.conf import settings
from celery import states
from celery.canvas import Signature
from enumfields import EnumField, Enum
from celery.result import AsyncResult, GroupResult
from enumfields import EnumField, Enum
from arkindex.project.models import IndexableModel
import uuid
import os
......@@ -39,6 +40,9 @@ class DataImport(IndexableModel):
root_id = models.UUIDField(null=True, blank=True)
task_count = models.PositiveSmallIntegerField(null=True, blank=True)
class Meta:
ordering = ['corpus', '-created']
@property
def celery_root(self):
return AsyncResult(str(self.root_id)) if self.root_id else None
......@@ -48,10 +52,18 @@ class DataImport(IndexableModel):
"""
Get a list of all tasks associated with the import
"""
return filter(
return list(filter(
lambda task: not isinstance(task, GroupResult),
reversed(self.celery_root.build_graph(True).topsort())
) if self.celery_root else None
)) if self.celery_root else None
@property
def result(self):
"""
Get the last task's result
"""
if self.tasks and self.tasks[-1].state == states.SUCCESS:
return self.tasks[-1].result
def build_workflow(self):
# Only Images import is supported
......@@ -114,6 +126,7 @@ class DataFile(models.Model):
class Meta:
unique_together = (('corpus', 'hash'), )
ordering = ['corpus', 'name']
@property
def staging_path(self):
......
......@@ -127,6 +127,7 @@ class DataImportSerializer(DataImportLightSerializer):
'files',
'tasks',
'task_count',
'result',
)
......
......@@ -6,7 +6,7 @@ from django.conf import settings
from arkindex.project.celery import ReportingTask
from arkindex.documents.models import Element, ElementType
from arkindex.documents.importer import import_page
from arkindex.images.models import ImageServer
from arkindex.images.models import ImageServer, ImageStatus
from arkindex.dataimport.models import DataImport, DataImportState
from PIL import Image
from shutil import copyfile
......@@ -81,7 +81,8 @@ def import_images(self, valid_files, dataimport, server_id=settings.LOCAL_IMAGES
path=urllib.parse.urljoin(dataimport.folder_name + '/', newfilename),
defaults={
'width': width,
'height': height
'height': height,
'status': ImageStatus.Checked,
}
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment